diff options
author | Bryan C. Mills <bcmills@google.com> | 2021-04-16 12:17:27 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2021-04-16 19:01:31 +0000 |
commit | 2fc0ebb623e2859094ad3f41e61325df0c2163f8 (patch) | |
tree | 02b4666da6ec01cd4e9d6cac26edfc5cfa031f18 /src/cmd/go/internal/modload/init.go | |
parent | c1e8a9a8c6315f63b7fa0eee8a79589bb02f89fa (diff) | |
download | go-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.go | 12 |
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 } |