-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: add a -go flag to 'go mod graph'
For #46366 Change-Id: I8417e6e4dbb8cb56ff7afc16893a01b7bb938217 Reviewed-on: https://go-review.googlesource.com/c/go/+/329529 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
- Loading branch information
Bryan C. Mills
committed
Jun 21, 2021
1 parent
761edf7
commit 1bd5a20
Showing
7 changed files
with
154 additions
and
8 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,101 @@ | ||
# For this module, Go 1.17 prunes out a (transitive and otherwise-irrelevant) | ||
# requirement on a retracted higher version of a dependency. | ||
# However, when Go 1.16 reads the same requirements from the go.mod file, | ||
# it does not prune out that requirement, and selects the retracted version. | ||
# | ||
# The Go 1.16 module graph looks like: | ||
# | ||
# m ---- lazy v0.1.0 ---- requireincompatible v0.1.0 ---- incompatible v2.0.0+incompatible | ||
# | | | ||
# + -------+------------- incompatible v1.0.0 | ||
# | ||
# The Go 1.17 module graph is the same except that the dependencies of | ||
# requireincompatible are pruned out (because the module that requires | ||
# it — lazy v0.1.0 — specifies 'go 1.17', and it is not otherwise relevant to | ||
# the main module). | ||
|
||
cp go.mod go.mod.orig | ||
|
||
go mod graph | ||
cp stdout graph-1.17.txt | ||
stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$' | ||
stdout '^example\.net/lazy@v0\.1\.0 example\.com/retract/incompatible@v1\.0\.0$' | ||
! stdout 'example\.com/retract/incompatible@v2\.0\.0\+incompatible' | ||
|
||
go mod graph -go=1.17 | ||
cmp stdout graph-1.17.txt | ||
|
||
cmp go.mod go.mod.orig | ||
|
||
|
||
# Setting -go=1.16 should report the graph as viewed by Go 1.16, | ||
# but should not edit the go.mod file. | ||
|
||
go mod graph -go=1.16 | ||
cp stdout graph-1.16.txt | ||
stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$' | ||
stdout '^example\.net/lazy@v0\.1\.0 example.com/retract/incompatible@v1\.0\.0$' | ||
stdout '^example.net/requireincompatible@v0.1.0 example.com/retract/incompatible@v2\.0\.0\+incompatible$' | ||
|
||
cmp go.mod go.mod.orig | ||
|
||
|
||
# If we actually update the go.mod file to the requested go version, | ||
# we should get the same selected versions, but the roots of the graph | ||
# may be updated. | ||
# | ||
# TODO(#45551): The roots should not be updated. | ||
|
||
go mod edit -go=1.16 | ||
go mod graph | ||
! stdout '^example\.com/m example\.com/retract/incompatible@v1\.0\.0$' | ||
stdout '^example\.net/lazy@v0.1.0 example.com/retract/incompatible@v1\.0\.0$' | ||
stdout '^example.net/requireincompatible@v0.1.0 example.com/retract/incompatible@v2\.0\.0\+incompatible$' | ||
# TODO(#45551): cmp stdout graph-1.16.txt | ||
|
||
|
||
# Unsupported go versions should be rejected, since we don't know | ||
# what versions they would report. | ||
! go mod graph -go=1.99999999999 | ||
stderr '^invalid value "1\.99999999999" for flag -go: maximum supported Go version is '$goversion'\nusage: go mod graph \[-go=version\]\nRun ''go help mod graph'' for details.$' | ||
|
||
|
||
-- go.mod -- | ||
// Module m indirectly imports a package from | ||
// example.com/retract/incompatible. Its selected version of | ||
// that module is lower under Go 1.17 semantics than under Go 1.16. | ||
module example.com/m | ||
|
||
go 1.17 | ||
|
||
replace ( | ||
example.net/lazy v0.1.0 => ./lazy | ||
example.net/requireincompatible v0.1.0 => ./requireincompatible | ||
) | ||
|
||
require ( | ||
example.com/retract/incompatible v1.0.0 // indirect | ||
example.net/lazy v0.1.0 | ||
) | ||
-- lazy/go.mod -- | ||
// Module lazy requires example.com/retract/incompatible v1.0.0. | ||
// | ||
// When viewed from the outside it also has a transitive dependency | ||
// on v2.0.0+incompatible, but in lazy mode that transitive dependency | ||
// is pruned out. | ||
module example.net/lazy | ||
|
||
go 1.17 | ||
|
||
exclude example.com/retract/incompatible v2.0.0+incompatible | ||
|
||
require ( | ||
example.com/retract/incompatible v1.0.0 | ||
example.net/requireincompatible v0.1.0 | ||
) | ||
-- requireincompatible/go.mod -- | ||
module example.net/requireincompatible | ||
|
||
go 1.15 | ||
|
||
require example.com/retract/incompatible v2.0.0+incompatible |