mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
c1e8a9a8c6
commit
2fc0ebb623
1 changed files with 11 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue