diff options
author | Bryan C. Mills <bcmills@google.com> | 2021-06-23 23:29:10 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2021-06-24 18:12:53 +0000 |
commit | 600a2a4ffb9a273a3a1635b60120ffc768741aa9 (patch) | |
tree | 27e3fa4ededd9b74817e55e56d27bd226c0d34d4 /src/cmd/go/internal/modload/import.go | |
parent | a9bb38222a06333176cafc5637083e0322277c09 (diff) | |
download | go-600a2a4ffb9a273a3a1635b60120ffc768741aa9.tar.gz go-600a2a4ffb9a273a3a1635b60120ffc768741aa9.zip |
cmd/go: don't try to add replaced versions that won't be selected
In Go 1.12, we added a heuristic to 'go mod tidy' to resolve packages
by adding replaced-but-not-required modules before falling back to
searching for modules from the network. Unfortunately, that heuristic
fails when the replaced version is already lower than the selected
version: adding such a module to the build list doesn't change the
selected version of that module, and so it doesn't make progress
toward resolving the missing package.
Fixes #46659
Change-Id: I75e2387d5290e769f6b0fa1231dcc4605db68597
Reviewed-on: https://go-review.googlesource.com/c/go/+/330432
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>
Diffstat (limited to 'src/cmd/go/internal/modload/import.go')
-rw-r--r-- | src/cmd/go/internal/modload/import.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go index 60bd26fb22..d2bbe5cbe0 100644 --- a/src/cmd/go/internal/modload/import.go +++ b/src/cmd/go/internal/modload/import.go @@ -428,6 +428,15 @@ func queryImport(ctx context.Context, path string, rs *Requirements) (module.Ver mv = module.ZeroPseudoVersion("v0") } } + mg, err := rs.Graph(ctx) + if err != nil { + return module.Version{}, err + } + if cmpVersion(mg.Selected(mp), mv) >= 0 { + // We can't resolve the import by adding mp@mv to the module graph, + // because the selected version of mp is already at least mv. + continue + } mods = append(mods, module.Version{Path: mp, Version: mv}) } |