From: Bryan C. Mills Date: Fri, 16 Apr 2021 16:17:27 +0000 (-0400) Subject: cmd/go/internal/modload: when outside a module, set cfg.BuildMod based on allowMissin... X-Git-Tag: go1.17beta1~599 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2fc0ebb623;p=gostls13.git 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 Run-TryBot: Bryan C. Mills TryBot-Result: Go Bot Reviewed-by: Jay Conrod --- 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 }