]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: when outside a module, set cfg.BuildMod based on allowMissin...
authorBryan C. Mills <bcmills@google.com>
Fri, 16 Apr 2021 16:17:27 +0000 (12:17 -0400)
committerBryan C. Mills <bcmills@google.com>
Fri, 16 Apr 2021 19:01:31 +0000 (19:01 +0000)
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>
src/cmd/go/internal/modload/init.go

index 45852edbd1480aae3be5a3d49ad6ea450521da3c..35bbcc795e636def3b7c31a28394f3f247d503e2 100644 (file)
@@ -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
        }