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

Collect Applicable Constraints #1480

Merged
merged 4 commits into from
Dec 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/dep/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,11 @@ func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) (con
// Iterate through the project constraints to get individual dependency
// project and constraint values.
for pr, pp := range pc {
// Check if the project constraint is imported in the root project
if _, ok := directDeps[string(pr)]; !ok {
continue
}

tempCC := append(
constraintCollection[string(pr)],
projectConstraint{proj.Ident().ProjectRoot, pp.Constraint},
Expand Down
31 changes: 31 additions & 0 deletions cmd/dep/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,44 @@ func TestCollectConstraints(t *testing.T) {
},
wantErr: true,
},
{
name: "collect only applicable constraints",
lock: dep.Lock{
P: []gps.LockedProject{
gps.NewLockedProject(
gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot("github.com/darkowlzz/dep-applicable-constraints")},
gps.NewVersion("v1.0.0"),
[]string{"."},
),
},
},
wantConstraints: constraintsCollection{
"github.com/boltdb/bolt": []projectConstraint{
{"github.com/darkowlzz/dep-applicable-constraints", gps.NewBranch("master")},
},
"github.com/sdboyer/deptest": []projectConstraint{
{"github.com/darkowlzz/dep-applicable-constraints", ver08},
},
},
},
}

h := test.NewHelper(t)
defer h.Cleanup()

h.TempDir("src")
pwd := h.Path(".")
h.TempFile(filepath.Join("src", "dep.go"), `
package dep
import (
_ "github.com/boltdb/bolt"
_ "github.com/sdboyer/deptest"
_ "github.com/sdboyer/dep-test"
_ "github.com/sdboyer/deptestdos"
)
type FooBar int
`)

discardLogger := log.New(ioutil.Discard, "", 0)

ctx := &dep.Ctx{
Expand Down