]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/go: set cfg.BuildMod to "readonly" by default with no module root
authorJay Conrod <jayconrod@google.com>
Mon, 21 Dec 2020 23:06:35 +0000 (18:06 -0500)
committerJay Conrod <jayconrod@google.com>
Tue, 5 Jan 2021 23:31:36 +0000 (23:31 +0000)
commit3e1e13ce6d1271f49f3d8ee359689145a6995bad
treee5e545f6517ecb15ad231e6dcb9fecb1eb4506a8
parent0b0d004983b5f06d7e8ae2084fc7d6612f1aa869
cmd/go: set cfg.BuildMod to "readonly" by default with no module root

modload.Init now sets the default value for -mod if it wasn't set
explicitly. This happens before go.mod is loaded, so
modload.LoadModFile sets the default value again in order to enable
automatic vendoring.

Previously, cfg.BuildMod wasn't set at all if LoadModFile wasn't
called, as is the case for commands that run outside of a module
root. This problem only affected 'go install pkg@version' since other
commands are either forbidden in module mode or run with -mod=mod
(like 'go get' and 'go mod' subcommands).

This change also suppresses "missing sum" errors when -mod=readonly is
enabled and there is no module root.

Fixes #43278
Related #40278

Change-Id: I6071cc42bc5e24d0d7e84556e5bfd8e368e0019d
Reviewed-on: https://go-review.googlesource.com/c/go/+/279490
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/modload/import.go
src/cmd/go/internal/modload/import_test.go
src/cmd/go/internal/modload/init.go
src/cmd/go/internal/modload/modfile.go
src/cmd/go/testdata/script/mod_install_pkg_version.txt