Skip to content

Commit 06538fa

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> Trust: Jay Conrod <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 67bf1c9 commit 06538fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2622
-963
lines changed

doc/go1.16.html

+10
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ <h4 id="go-test"><code>go</code> <code>test</code></h4>
110110
See <code>go</code> <code>help</code> <code>environment</code> for details.
111111
</p>
112112

113+
<h4 id="go-get"><code>go</code> <code>get</code></h4>
114+
115+
<p><!-- golang.org/cl/263267 -->
116+
<code>go</code> <code>get</code> <code>example.com/mod@patch</code> now
117+
requires that some version of <code>example.com/mod</code> already be
118+
required by the main module.
119+
(However, <code>go</code> <code>get</code> <code>-u=patch</code> continues
120+
to patch even newly-added dependencies.)
121+
</p>
122+
113123
<h4 id="all-pattern">The <code>all</code> pattern</h4>
114124

115125
<p><!-- golang.org/cl/240623 -->

src/cmd/go/alldocs.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)