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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read other dependency mgrs cfg during init
Extract initial root manifest generation into an analyzer which combines evaluating the contents of the GOPATH with importing cfg from other managers.
- Loading branch information
Showing
19 changed files
with
723 additions
and
83 deletions.
There are no files selected for viewing
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) PostSolveShenanigans(m *dep.Manifest, l *dep.Lock) { | ||
for _, a := range a.Analyzers { | ||
a.PostSolveShenanigans(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) PostSolveShenanigans(*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]) | ||
} | ||
} |
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
Oops, something went wrong.