diff options
author | Bryan C. Mills <bcmills@google.com> | 2021-04-29 10:27:43 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2021-04-30 18:05:30 +0000 |
commit | 8d8abb3b8a80d341ce2d7c6dd3f2a43fd586bed8 (patch) | |
tree | 38934f57b967ac2171901908a2b66e50c80f0d2d | |
parent | 9a81702b974f9d6e5569f069baaad58a0829c63a (diff) | |
download | go-8d8abb3b8a80d341ce2d7c6dd3f2a43fd586bed8.tar.gz go-8d8abb3b8a80d341ce2d7c6dd3f2a43fd586bed8.zip |
cmd/go: verify lazy-loading invariants when loading the vendor list for a lazy module
For #36460
Change-Id: Ib4b1baea35826c3e359456f8dba09a49283e7fee
Reviewed-on: https://go-review.googlesource.com/c/go/+/315069
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
-rw-r--r-- | src/cmd/go/internal/modload/buildlist.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/cmd/go/internal/modload/buildlist.go b/src/cmd/go/internal/modload/buildlist.go index 46aee45bd5..4b83ede541 100644 --- a/src/cmd/go/internal/modload/buildlist.go +++ b/src/cmd/go/internal/modload/buildlist.go @@ -140,12 +140,21 @@ func (rs *Requirements) initVendor(vendorList []module.Version) { // The roots of a lazy module should already include every module in the // vendor list, because the vendored modules are the same as those // maintained as roots by the lazy loading “import invariant”. - if go117LazyTODO { - // Double-check here that that invariant holds. + // + // Just to be sure, we'll double-check that here. + inconsistent := false + for _, m := range vendorList { + if v, ok := rs.rootSelected(m.Path); !ok || v != m.Version { + base.Errorf("go: vendored module %v should be required explicitly in go.mod", m) + inconsistent = true + } + } + if inconsistent { + base.Fatalf("go: %v", errGoModDirty) } - // So we can just treat the rest of the module graph as effectively - // “pruned out”, like a more aggressive version of lazy loading: + // Now we can treat the rest of the module graph as effectively “pruned + // out”, like a more aggressive version of lazy loading: in vendor mode, // the root requirements *are* the complete module graph. mg.g.Require(Target, rs.rootModules) } else { |