aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/init.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2021-04-16 12:17:27 -0400
committerBryan C. Mills <bcmills@google.com>2021-04-16 19:01:31 +0000
commit2fc0ebb623e2859094ad3f41e61325df0c2163f8 (patch)
tree02b4666da6ec01cd4e9d6cac26edfc5cfa031f18 /src/cmd/go/internal/modload/init.go
parentc1e8a9a8c6315f63b7fa0eee8a79589bb02f89fa (diff)
downloadgo-2fc0ebb623e2859094ad3f41e61325df0c2163f8.tar.gz
go-2fc0ebb623e2859094ad3f41e61325df0c2163f8.zip
cmd/go/internal/modload: when outside a module, set cfg.BuildMod based on allowMissingModuleImports
For #36460 Change-Id: I50c7018a6841bba1a8c6f8f8eca150df1f685526 Reviewed-on: https://go-review.googlesource.com/c/go/+/310789 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/init.go')
-rw-r--r--src/cmd/go/internal/modload/init.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go
index 45852edbd1..35bbcc795e 100644
--- a/src/cmd/go/internal/modload/init.go
+++ b/src/cmd/go/internal/modload/init.go
@@ -617,7 +617,13 @@ func fixVersion(ctx context.Context, fixed *bool) modfile.VersionFixer {
// when there is no module root. Normally, this is forbidden because it's slow
// and there's no way to make the result reproducible, but some commands
// like 'go get' are expected to do this.
+//
+// This function affects the default cfg.BuildMod when outside of a module,
+// so it can only be called prior to Init.
func AllowMissingModuleImports() {
+ if initialized {
+ panic("AllowMissingModuleImports after Init")
+ }
allowMissingModuleImports = true
}
@@ -699,7 +705,11 @@ func setDefaultBuildMod() {
return
}
if modRoot == "" {
- cfg.BuildMod = "readonly"
+ if allowMissingModuleImports {
+ cfg.BuildMod = "mod"
+ } else {
+ cfg.BuildMod = "readonly"
+ }
return
}