]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/go/internal/modget: resolve paths at the requested versions
authorBryan C. Mills <bcmills@google.com>
Fri, 18 Sep 2020 16:10:58 +0000 (12:10 -0400)
committerBryan C. Mills <bcmills@google.com>
Thu, 5 Nov 2020 17:52:17 +0000 (17:52 +0000)
commit06538fa723fc358462c5d7ae385b5b64ac76827b
tree8d8d5738170ff6cfbf74c8572d2dbb7f10793e51
parent67bf1c9979180da6dba7dd523df7d7917fe04048
cmd/go/internal/modget: resolve paths at the requested versions

Previously, we resolved each argument to 'go get' to a package path or
module path based on what was in the build list at existing versions,
even if the argument specified a different version explicitly. That
resulted in bugs like #37438, in which we variously resolved the wrong
version or guessed the wrong argument type for what is unambiguously a
package argument at the requested version.

We were also using a two-step upgrade/downgrade algorithm, which could
not only upgrade more that is strictly necessary, but could also
unintentionally upgrade *above* the requested versions during the
downgrade step.

This change instead uses an iterative approach, with an explicit
disambiguation step for the (rare) cases where an argument could match
the same package path in multiple modules. We use a hook in the
package loader to halt package loading as soon as an incorrect version
is found — preventing over-resolving — and verify that the result
after applying downgrades successfully obtained the requested versions
of all modules.

Making 'go get' be correct and usable is especially important now that
we are defaulting to read-only mode (#40728), for which we are
recommending 'go get' more heavily.

While I'm in here refactoring, I'm also reworking the API boundary
between the modget and modload packages. Previously, the modget
package edited the build list directly, and the modload package
accepted the edited build list without validation. For lazy loading
(#36460), the modload package will need to maintain additional
metadata about the requirement graph, so it needs tighter control over
the changes to the build list.

As of this change, modget no longer invokes MVS directly, but instead
goes through the modload package. The resulting API gives clearer
reasons in case of updates, which we can use to emit more useful
errors.

Fixes #37438
Updates #36460
Updates #40728

Change-Id: I596f0020f3795870dec258147e6fc26a3292c93a
Reviewed-on: https://go-review.googlesource.com/c/go/+/263267
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
42 files changed:
doc/go1.16.html
src/cmd/go/alldocs.go
src/cmd/go/internal/modget/get.go
src/cmd/go/internal/modget/mvs.go [deleted file]
src/cmd/go/internal/modget/query.go [new file with mode: 0644]
src/cmd/go/internal/modload/buildlist.go
src/cmd/go/internal/modload/import.go
src/cmd/go/internal/modload/load.go
src/cmd/go/internal/modload/mvs.go
src/cmd/go/internal/modload/query.go
src/cmd/go/internal/modload/search.go
src/cmd/go/testdata/script/get_update_all.txt
src/cmd/go/testdata/script/mod_bad_domain.txt
src/cmd/go/testdata/script/mod_dot.txt
src/cmd/go/testdata/script/mod_download.txt
src/cmd/go/testdata/script/mod_get_ambiguous_arg.txt
src/cmd/go/testdata/script/mod_get_ambiguous_import.txt
src/cmd/go/testdata/script/mod_get_ambiguous_pkg.txt
src/cmd/go/testdata/script/mod_get_downgrade.txt
src/cmd/go/testdata/script/mod_get_downgrade_missing.txt
src/cmd/go/testdata/script/mod_get_extra.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_get_issue37438.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_get_main.txt
src/cmd/go/testdata/script/mod_get_moved.txt
src/cmd/go/testdata/script/mod_get_newcycle.txt
src/cmd/go/testdata/script/mod_get_patch.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_get_patchbound.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_get_patchcycle.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_get_patchmod.txt
src/cmd/go/testdata/script/mod_get_patterns.txt
src/cmd/go/testdata/script/mod_get_replaced.txt
src/cmd/go/testdata/script/mod_get_split.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_get_wild.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_invalid_version.txt
src/cmd/go/testdata/script/mod_load_badchain.txt
src/cmd/go/testdata/script/mod_outside.txt
src/cmd/go/testdata/script/mod_query_empty.txt
src/cmd/go/testdata/script/mod_query_exclude.txt
src/cmd/go/testdata/script/mod_retract_pseudo_base.txt
src/cmd/go/testdata/script/mod_sumdb.txt
src/cmd/go/testdata/script/mod_sumdb_file_path.txt
src/cmd/go/testdata/script/mod_upgrade_patch.txt