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
Proposal: Allow transitive constraints #1489
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c496efc
gps: apply transitive constraints
carolynvs 00ede10
Test dep ensure with a transitive constraint
carolynvs e075a3f
Test dep init with a transitive constraint
carolynvs 5b8fdcb
Failing test for unused transitive constraint
carolynvs 0b71dd2
NEEDS REVIEW: DO NOT MERGE
carolynvs d93117f
Update exists (pre-PR) tests to pass
carolynvs 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
5 changes: 5 additions & 0 deletions
5
cmd/dep/testdata/harness_tests/ensure/transitive-constraint/README.md
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,5 @@ | ||
# Ensure - Transitive Constraint | ||
|
||
[github.com/carolynvs/deptest-transcons-c](github.com/carolynvs/deptest-transcons-c) | ||
has a bug in the latest release. I am a library and need to define a constraint | ||
so that consumers of my library don't pull in the bad version of C. |
21 changes: 21 additions & 0 deletions
21
cmd/dep/testdata/harness_tests/ensure/transitive-constraint/final/Gopkg.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
cmd/dep/testdata/harness_tests/ensure/transitive-constraint/final/Gopkg.toml
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,7 @@ | ||
[[constraint]] | ||
name = "github.com/carolynvs/deptest-transcons-b" | ||
version = "1.0.0" | ||
|
||
[[constraint]] | ||
name = "github.com/carolynvs/deptest-transcons-c" | ||
version = "<1.0.1" |
7 changes: 7 additions & 0 deletions
7
cmd/dep/testdata/harness_tests/ensure/transitive-constraint/initial/Gopkg.toml
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,7 @@ | ||
[[constraint]] | ||
name = "github.com/carolynvs/deptest-transcons-b" | ||
version = "1.0.0" | ||
|
||
[[constraint]] | ||
name = "github.com/carolynvs/deptest-transcons-c" | ||
version = "<1.0.1" |
15 changes: 15 additions & 0 deletions
15
cmd/dep/testdata/harness_tests/ensure/transitive-constraint/initial/a.go
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,15 @@ | ||
// 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 a | ||
|
||
import ( | ||
"fmt" | ||
"github.com/carolynvs/deptest-transcons-b" | ||
) | ||
|
||
func A() { | ||
fmt.Println("a did a thing") | ||
b.B() | ||
} |
9 changes: 9 additions & 0 deletions
9
cmd/dep/testdata/harness_tests/ensure/transitive-constraint/testcase.json
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,9 @@ | ||
{ | ||
"commands": [ | ||
["ensure"] | ||
], | ||
"vendor-final": [ | ||
"github.com/carolynvs/deptest-transcons-b", | ||
"github.com/carolynvs/deptest-transcons-c" | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
cmd/dep/testdata/harness_tests/init/transitive-constraint/README.md
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,7 @@ | ||
# Init - Transitive Constraint | ||
|
||
[C](github.com/carolynvs/deptest-transcons-c) | ||
has a bug in the latest release. I am an end-user of [A](github.com/carolynvs/deptest-transcons-a) | ||
which transitively depends on C. A has a constraint on C which avoids a bad release of C. | ||
End-users like me should be able to use A, and have `dep init` pick a version of C | ||
that doesn't have the bug, without manually adding overrides. |
27 changes: 27 additions & 0 deletions
27
cmd/dep/testdata/harness_tests/init/transitive-constraint/final/Gopkg.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
cmd/dep/testdata/harness_tests/init/transitive-constraint/final/Gopkg.toml
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,4 @@ | ||
|
||
[[constraint]] | ||
name = "github.com/carolynvs/deptest-transcons-a" | ||
version = "1.0.0" |
15 changes: 15 additions & 0 deletions
15
cmd/dep/testdata/harness_tests/init/transitive-constraint/initial/main.go
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,15 @@ | ||
// 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 ( | ||
"fmt" | ||
"github.com/carolynvs/deptest-transcons-a" | ||
) | ||
|
||
func main () { | ||
fmt.Println("Stand back, I'm gonna do a thing!") | ||
a.A() | ||
} |
10 changes: 10 additions & 0 deletions
10
cmd/dep/testdata/harness_tests/init/transitive-constraint/testcase.json
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,10 @@ | ||
{ | ||
"commands": [ | ||
["init", "--no-examples"] | ||
], | ||
"vendor-final": [ | ||
"github.com/carolynvs/deptest-transcons-a", | ||
"github.com/carolynvs/deptest-transcons-b", | ||
"github.com/carolynvs/deptest-transcons-c" | ||
] | ||
} |
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 |
---|---|---|
|
@@ -177,6 +177,8 @@ type bimodalIdentifier struct { | |
prefv Version | ||
// Indicates that the bmi came from the root project originally | ||
fromRoot bool | ||
// The path to the atom in the graph, e.g. root -> foo -> bar | ||
path []atom | ||
} | ||
|
||
type atom struct { | ||
|
@@ -190,20 +192,8 @@ var nilpa = atom{ | |
} | ||
|
||
type atomWithPackages struct { | ||
a atom | ||
pl []string | ||
} | ||
|
||
// bmi converts an atomWithPackages into a bimodalIdentifier. | ||
// | ||
// This is mostly intended for (read-only) trace use, so the package list slice | ||
// is not copied. It is the callers responsibility to not modify the pl slice, | ||
// lest that backpropagate and cause inconsistencies. | ||
func (awp atomWithPackages) bmi() bimodalIdentifier { | ||
return bimodalIdentifier{ | ||
id: awp.a.id, | ||
pl: awp.pl, | ||
} | ||
a atom | ||
bmi bimodalIdentifier | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haven't fully grokked yet, but the complexity of this area is sufficient that, unless there is copy-avoiding performance argument to the contrary, it is preferable to not reuse types even if they share many fields. instead, types should be created and clearly described for the specific purpose for which they are used. |
||
} | ||
|
||
// completeDep (name hopefully to change) provides the whole picture of a | ||
|
@@ -215,12 +205,14 @@ 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 | ||
// fully-realized atom as the depender (the tail/source of the edge), and a set | ||
// of requirements that any atom to be attached at the head/target must satisfy. | ||
type dependency struct { | ||
depender atom | ||
depender atomWithPackages | ||
dep completeDep | ||
} |
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
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.
OK, so here's where i think the problem is gonna be. This is effectively precaching the path to a given atom from the root - but there's no guarantee that it's the only possible path to the atom. That itself may not necessarily be a problem (i haven't thought it through in at the level of the purest white driven snow algorithm), but it likely will not work well in terms of the way we populate the unselected queue.
Have a look at
selectAtom()
. We only add a bmi to the unselected queue if it induces a new package requirement on the target atom. i believe that'll mean that it's possible for a transitive constraint on P to be ignored if project A that expresses it induces no new packages to be selected within P.That may not be true, but it's not covered by the current set of tests. It also may be the case that this isn't true, but i'm reasoning that it is by relying on cached thoughts around the the restricted purpose of
bimodalIdentifier
. If that's the case, it's evidence for why the reuse of similarly-shaped types for different purposes inside the algorithm is not a great idea - it complicates the already-difficult task of reasoning about the algorithm.