Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Skip duplicate project roots during glide import
Browse files Browse the repository at this point in the history
  • Loading branch information
carolynvs committed Aug 11, 2017
1 parent 65bfe46 commit a61cc1b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 13 deletions.
47 changes: 34 additions & 13 deletions cmd/dep/glide_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ func (g *glideImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, e
if err != nil {
return nil, nil, err
}

if _, isDup := manifest.Constraints[pc.Ident.ProjectRoot]; isDup {
continue
}

manifest.Constraints[pc.Ident.ProjectRoot] = gps.ProjectProperties{Source: pc.Ident.Source, Constraint: pc.Constraint}
}

Expand All @@ -171,7 +176,15 @@ func (g *glideImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, e
lock = &dep.Lock{}

for _, pkg := range append(g.lock.Imports, g.lock.TestImports...) {
lp := g.buildLockedProject(pkg, manifest)
lp, err := g.buildLockedProject(pkg, manifest)
if err != nil {
return nil, nil, err
}

if projectExistsInLock(lock, lp.Ident().ProjectRoot) {
continue
}

lock.P = append(lock.P, lp)
}
}
Expand All @@ -180,8 +193,17 @@ func (g *glideImporter) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, e
}

func (g *glideImporter) buildProjectConstraint(pkg glidePackage) (pc gps.ProjectConstraint, err error) {
if pkg.Name == "" {
err = errors.New("Invalid glide configuration, package name is required")
pr, err := g.sm.DeduceProjectRoot(pkg.Name)
if err != nil {
return
}

pc.Ident = gps.ProjectIdentifier{
ProjectRoot: pr,
Source: pkg.Repository,
}
pc.Constraint, err = g.sm.InferConstraint(pkg.Reference, pc.Ident)
if err != nil {
return
}

Expand All @@ -194,21 +216,20 @@ func (g *glideImporter) buildProjectConstraint(pkg glidePackage) (pc gps.Project
}
}

pc.Ident = gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot(pkg.Name), Source: pkg.Repository}
pc.Constraint, err = g.sm.InferConstraint(pkg.Reference, pc.Ident)
if err != nil {
return
}

f := fb.NewConstraintFeedback(pc, fb.DepTypeImported)
f.LogFeedback(g.logger)

return
}

func (g *glideImporter) buildLockedProject(pkg glideLockedPackage, manifest *dep.Manifest) gps.LockedProject {
func (g *glideImporter) buildLockedProject(pkg glideLockedPackage, manifest *dep.Manifest) (lp gps.LockedProject, err error) {
pr, err := g.sm.DeduceProjectRoot(pkg.Name)
if err != nil {
return
}

pi := gps.ProjectIdentifier{
ProjectRoot: gps.ProjectRoot(pkg.Name),
ProjectRoot: pr,
Source: pkg.Repository,
}
revision := gps.Revision(pkg.Reference)
Expand All @@ -220,10 +241,10 @@ func (g *glideImporter) buildLockedProject(pkg glideLockedPackage, manifest *dep
g.logger.Println(err.Error())
}

lp := gps.NewLockedProject(pi, version, nil)
lp = gps.NewLockedProject(pi, version, nil)

f := fb.NewLockedProjectFeedback(lp, fb.DepTypeImported)
f.LogFeedback(g.logger)

return lp
return
}
47 changes: 47 additions & 0 deletions cmd/dep/glide_importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,50 @@ func equalSlice(a, b []string) bool {

return true
}

func TestGlideConfig_Convert_ConsolidateRootPackages(t *testing.T) {
h := test.NewHelper(t)
defer h.Cleanup()

ctx := newTestContext(h)
sm, err := ctx.SourceManager()
h.Must(err)
defer sm.Release()

g := newGlideImporter(ctx.Err, true, sm)
g.yaml = glideYaml{
Imports: []glidePackage{
{Name: "github.com/carolynvs/deptest-subpkg/subby"},
{Name: "github.com/carolynvs/deptest-subpkg"},
},
}
g.lock = &glideLock{
Imports: []glideLockedPackage{
{Name: "github.com/carolynvs/deptest-subpkg/subby"},
{Name: "github.com/carolynvs/deptest-subpkg"},
},
}

manifest, lock, err := g.convert(testGlideProjectRoot)
h.Must(err)

gotMLen := len(manifest.Constraints)
if gotMLen != 1 {
t.Fatalf("Expected manifest to contain 1 constraint, got %d", gotMLen)
}

wantRoot := gps.ProjectRoot("github.com/carolynvs/deptest-subpkg")
if _, has := manifest.Constraints[wantRoot]; !has {
t.Fatalf("Expected manifest to contain a constraint for %s, got %v", wantRoot, manifest.Constraints)
}

gotLLen := len(lock.P)
if gotLLen != 1 {
t.Fatalf("Expected lock to contain 1 project, got %d", gotLLen)
}

gotRoot := lock.P[0].Ident().ProjectRoot
if gotRoot != wantRoot {
t.Fatalf("Expected lock to contain a project for %s, got %v", wantRoot, gotRoot)
}
}

0 comments on commit a61cc1b

Please sign in to comment.