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

Proposal: Allow transitive constraints #1489

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
Next Next commit
gps: apply transitive constraints
carolynvs authored and carolynvs-msft committed Jan 25, 2018
commit c496efc61a3ef95f851e2ee31d119a9aa2350da0
2 changes: 2 additions & 0 deletions gps/identifier.go
Original file line number Diff line number Diff line change
@@ -215,6 +215,8 @@ type completeDep struct {
workingConstraint
// The specific packages required from the ProjectDep
pl []string
// Flags the constraint as being defined on an indirect/transitive dependency
isTransitive bool
}

// dependency represents an incomplete edge in the depgraph. It has a
20 changes: 20 additions & 0 deletions gps/solve_bimodal_test.go
Original file line number Diff line number Diff line change
@@ -132,6 +132,26 @@ var bimodalFixtures = map[string]bimodalFixture{
"b 1.0.0",
),
},
"transitive constraint": {
ds: []depspec{
dsp(mkDepspec("root 1.0.0", "foo 1.0.0"),
pkg("root", "foo"),
),
dsp(mkDepspec("foo 1.0.0", "bar 1.0.0", "baz =1.0.0"),
pkg("foo", "bar"),
),
dsp(mkDepspec("bar 1.0.0", "baz >=1.0.0"),
pkg("bar", "baz"),
),
dsp(mkDepspec("baz 1.0.1"), pkg("baz")),
dsp(mkDepspec("baz 1.0.0"), pkg("baz")),
},
r: mksolution(
"foo 1.0.0",
"bar 1.0.0",
"baz 1.0.0",
),
},
// Constraints apply only if the project that declares them has a
// reachable import
"constraints activated by import": {
18 changes: 18 additions & 0 deletions gps/solver.go
Original file line number Diff line number Diff line change
@@ -645,6 +645,13 @@ func (s *solver) selectRoot() error {
}

s.sel.pushDep(dependency{depender: awp.a, dep: dep})

if dep.isTransitive {
// Do not add transitive dependencies to the queue immediately,
// instead wait until they are directly used
continue
}

// Add all to unselected queue
heap.Push(s.unsel, bimodalIdentifier{id: dep.Ident, pl: dep.pl, fromRoot: true})
}
@@ -792,6 +799,17 @@ func (s *solver) intersectConstraintsWithImports(deps []workingConstraint, reach
}
}

// Include transitive constraints, flagging them as transitive for special handling later on
for _, wc := range deps {
root := wc.Ident.ProjectRoot
if _, ok := dmap[root]; !ok {
dmap[root] = completeDep{
workingConstraint: wc, // TODO(carolynvs): deal with overrides and package prefix-foo (not sure if that's needed?)
isTransitive: true,
}
}
}

// Dump all the deps from the map into the expected return slice
cdeps := make([]completeDep, 0, len(dmap))
for _, cdep := range dmap {