This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
WIP - Import godep #589
Closed
Closed
WIP - Import godep #589
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4555892
Vendor go-yaml
carolynvs d4e3df4
Make it easier to tell when dep has found its own config
carolynvs 1b526a5
Read glide config files
carolynvs e3dd721
Read other dependency mgrs cfg during init
carolynvs f2b54e1
Test init -skip-tools ignores glide cfg
carolynvs 6941a1c
Remove unused manifest deps
carolynvs 54d535b
Add dep ensure package@version tests
carolynvs 318ce20
Consolidate version/branch validation into deduceConstraint
carolynvs 14188a3
Internally export NewDefaultBranch
carolynvs b4380e3
Categorize glide versions as a branch or version
carolynvs adc74e5
Use the default branch when glide.yaml doesn’t specify
carolynvs b1c99a8
Tidy up new import interfaces
carolynvs c0deda7
Validate glide configuration file during import
carolynvs aa4a4c9
Rename files to snake case
carolynvs 393e718
Add godepFile load, convert and godep importer
darkowlzz d2f3fe2
Add godep importer integration tests
darkowlzz 7398d50
Add license headers
darkowlzz 5c59560
Check json.Unmarshal for error
darkowlzz c637683
Improve godep import tests
darkowlzz f2b9cba
Attempt to fetch version for no comment imports
darkowlzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2016 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/golang/dep" | ||
"github.com/golang/dep/internal/gps" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// compositeAnalyzer overlays configuration from multiple analyzers | ||
type compositeAnalyzer struct { | ||
// Analyzers is the set of analyzers to apply, last one wins any conflicts | ||
Analyzers []rootProjectAnalyzer | ||
} | ||
|
||
func (a compositeAnalyzer) DeriveRootManifestAndLock(path string, n gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) { | ||
var rootM *dep.Manifest | ||
var rootL *dep.Lock | ||
|
||
for _, a := range a.Analyzers { | ||
m, l, err := a.DeriveRootManifestAndLock(path, n) | ||
if err != nil { | ||
return nil, nil, errors.Wrapf(err, "%T.DeriveRootManifestAndLock", a) | ||
} | ||
|
||
if rootM == nil && rootL == nil { | ||
rootM = m | ||
rootL = l | ||
} else { | ||
// Overlay the changes from the analyzer on-top of the previous analyzer's work | ||
if m != nil { | ||
for pkg, prj := range m.Dependencies { | ||
rootM.Dependencies[pkg] = prj | ||
} | ||
for pkg, prj := range m.Ovr { | ||
rootM.Ovr[pkg] = prj | ||
} | ||
for _, pkg := range m.Required { | ||
if !contains(rootM.Required, pkg) { | ||
rootM.Required = append(rootM.Required, pkg) | ||
} | ||
} | ||
for _, pkg := range m.Ignored { | ||
if !contains(rootM.Ignored, pkg) { | ||
rootM.Ignored = append(rootM.Ignored, pkg) | ||
} | ||
} | ||
} | ||
|
||
if l != nil { | ||
for _, lp := range l.P { | ||
for i, existingLP := range rootL.P { | ||
if lp.Ident().ProjectRoot == existingLP.Ident().ProjectRoot { | ||
rootL.P[i] = lp | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return rootM, rootL, nil | ||
} | ||
|
||
func (a compositeAnalyzer) FinalizeManifestAndLock(m *dep.Manifest, l *dep.Lock) { | ||
for _, a := range a.Analyzers { | ||
a.FinalizeManifestAndLock(m, l) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
// Copyright 2016 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/dep" | ||
"github.com/golang/dep/internal/gps" | ||
) | ||
|
||
type testRootProjectAnalyzer struct { | ||
*dep.Manifest | ||
*dep.Lock | ||
} | ||
|
||
func (a testRootProjectAnalyzer) DeriveRootManifestAndLock(path string, n gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error) { | ||
return a.Manifest, a.Lock, nil | ||
} | ||
|
||
func (a testRootProjectAnalyzer) FinalizeManifestAndLock(*dep.Manifest, *dep.Lock) { | ||
// do nothing | ||
} | ||
|
||
func TestCompositeAnalyzer_ManifestDependencies(t *testing.T) { | ||
pkg := gps.ProjectRoot("github.com/sdboyer/deptest") | ||
m1 := &dep.Manifest{ | ||
Dependencies: gps.ProjectConstraints{ | ||
pkg: gps.ProjectProperties{Constraint: gps.NewVersion("^1.0.0")}, | ||
}, | ||
} | ||
m2 := &dep.Manifest{ | ||
Dependencies: gps.ProjectConstraints{ | ||
pkg: gps.ProjectProperties{Constraint: gps.NewVersion("^2.0.0")}, | ||
}, | ||
} | ||
c := compositeAnalyzer{ | ||
Analyzers: []rootProjectAnalyzer{ | ||
testRootProjectAnalyzer{Manifest: m1}, | ||
testRootProjectAnalyzer{Manifest: m2}, | ||
}, | ||
} | ||
|
||
rm, _, err := c.DeriveRootManifestAndLock("", "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if rm == nil { | ||
t.Fatal("Expected the root manifest to not be nil") | ||
} | ||
|
||
dep, has := rm.Dependencies[pkg] | ||
if !has { | ||
t.Fatal("Expected the root manifest to contain the test project") | ||
} | ||
|
||
wantC := "^2.0.0" | ||
gotC := dep.Constraint.String() | ||
if wantC != gotC { | ||
t.Fatalf("Expected the test project to be constrained to '%s', got '%s'", wantC, gotC) | ||
} | ||
} | ||
|
||
func TestCompositeAnalyzer_ManifestOverrides(t *testing.T) { | ||
pkg := gps.ProjectRoot("github.com/sdboyer/deptest") | ||
m1 := &dep.Manifest{ | ||
Ovr: gps.ProjectConstraints{ | ||
pkg: gps.ProjectProperties{Constraint: gps.NewVersion("^1.0.0")}, | ||
}, | ||
} | ||
m2 := &dep.Manifest{ | ||
Ovr: gps.ProjectConstraints{ | ||
pkg: gps.ProjectProperties{Constraint: gps.NewVersion("^2.0.0")}, | ||
}, | ||
} | ||
c := compositeAnalyzer{ | ||
Analyzers: []rootProjectAnalyzer{ | ||
testRootProjectAnalyzer{Manifest: m1}, | ||
testRootProjectAnalyzer{Manifest: m2}, | ||
}, | ||
} | ||
|
||
rm, _, err := c.DeriveRootManifestAndLock("", "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if rm == nil { | ||
t.Fatal("Expected the root manifest to not be nil") | ||
} | ||
|
||
dep, has := rm.Ovr[pkg] | ||
if !has { | ||
t.Fatal("Expected the root manifest to contain the test project override") | ||
} | ||
|
||
wantC := "^2.0.0" | ||
gotC := dep.Constraint.String() | ||
if wantC != gotC { | ||
t.Fatalf("Expected the test project to be overridden to '%s', got '%s'", wantC, gotC) | ||
} | ||
} | ||
|
||
func TestCompositeAnalyzer_ManifestRequired(t *testing.T) { | ||
pkg1 := "github.com/sdboyer/deptest" | ||
pkg2 := "github.com/sdboyer/deptestdos" | ||
m1 := &dep.Manifest{ | ||
Required: []string{pkg1}, | ||
} | ||
m2 := &dep.Manifest{ | ||
Required: []string{pkg2}, | ||
} | ||
c := compositeAnalyzer{ | ||
Analyzers: []rootProjectAnalyzer{ | ||
testRootProjectAnalyzer{Manifest: m1}, | ||
testRootProjectAnalyzer{Manifest: m2}, | ||
}, | ||
} | ||
|
||
rm, _, err := c.DeriveRootManifestAndLock("", "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if rm == nil { | ||
t.Fatal("Expected the root manifest to not be nil") | ||
} | ||
|
||
if len(rm.Required) != 2 { | ||
t.Fatalf("Expected the root manifest to contain 2 required packages, got %d", len(rm.Required)) | ||
} | ||
|
||
if rm.Required[0] != pkg1 { | ||
t.Fatalf("Expected the first required package to be '%s', got '%s'", pkg1, rm.Required[0]) | ||
} | ||
|
||
if rm.Required[1] != pkg2 { | ||
t.Fatalf("Expected the second required package to be '%s', got '%s'", pkg2, rm.Required[1]) | ||
} | ||
} | ||
|
||
func TestCompositeAnalyzer_ManifestIgnored(t *testing.T) { | ||
pkg1 := "github.com/sdboyer/deptest" | ||
pkg2 := "github.com/sdboyer/deptestdos" | ||
m1 := &dep.Manifest{ | ||
Ignored: []string{pkg1}, | ||
} | ||
m2 := &dep.Manifest{ | ||
Ignored: []string{pkg2}, | ||
} | ||
c := compositeAnalyzer{ | ||
Analyzers: []rootProjectAnalyzer{ | ||
testRootProjectAnalyzer{Manifest: m1}, | ||
testRootProjectAnalyzer{Manifest: m2}, | ||
}, | ||
} | ||
|
||
rm, _, err := c.DeriveRootManifestAndLock("", "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if rm == nil { | ||
t.Fatal("Expected the root manifest to not be nil") | ||
} | ||
|
||
if len(rm.Ignored) != 2 { | ||
t.Fatalf("Expected the root manifest to contain 2 ignored packages, got %d", len(rm.Ignored)) | ||
} | ||
|
||
if rm.Ignored[0] != pkg1 { | ||
t.Fatalf("Expected the first ignored package to be '%s', got '%s'", pkg1, rm.Ignored[0]) | ||
} | ||
|
||
if rm.Ignored[1] != pkg2 { | ||
t.Fatalf("Expected the second ignored package to be '%s', got '%s'", pkg2, rm.Ignored[1]) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carolynvs a little problem here. Overlaying of lock isn't happening in some cases.
Let's take the example of integration test init/godep/case1/.
In godep/case1/testcase.json, although
gopath-initial
containsdeptest
, since deptest is a transitive dependency, the default (first analyzer) doesn't adds it to the manifest or lock it generates. And since there's nodeptestdos
ingopath-initial
, the first analyzer generates empty (not nil) manifest and lock structs.Now in the above code, when overlay is attempted for lock with godep analyzer generated manifest and lock,
is skipped because
rootL
is empty from the first analyzer run. And no lock overlay happens.Makes sense?
The final lock in init/godep/case1/ is incorrect at the moment. Commit hash in final lock is different from the one in Godep.json.
UPDATE: I see you have changed the overlay code in #500 and now it's handling this case :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah found that I broke overlay at some point. I have a bunch of fixes/pr feedback I'll push tonight. 😊