// would cause it to be interpreted differently if it were the main module
// (replace, exclude).
func PackagesAndErrorsOutsideModule(ctx context.Context, opts PackageOpts, args []string) ([]*Package, error) {
- if !modload.ForceUseModules {
+ if !modload.LoaderState.ForceUseModules {
panic("modload.ForceUseModules must be true")
}
if modload.RootMode != modload.NoRoot {
modload.InitWorkfile()
// Check whether modules are enabled and whether we're in a module.
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.ExplicitWriteGoMod = true
haveExplicitArgs := len(args) > 0
if len(args) > 0 {
base.Fatalf("go: 'go mod graph' accepts no arguments")
}
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.RootMode = modload.NeedRoot
goVersion := graphGo.String()
modPath = args[0]
}
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.CreateModFile(ctx, modPath) // does all the hard work
}
// those packages. In order to make 'go test' reproducible for the packages
// that are in 'all' but outside of the main module, we must explicitly
// request that their test dependencies be included.
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.RootMode = modload.NeedRoot
goVersion := tidyGo.String()
if len(args) != 0 {
base.Fatalf("go: 'go mod vendor' accepts no arguments")
}
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.RootMode = modload.NeedRoot
loadOpts := modload.PackageOpts{
// NOTE(rsc): Could take a module pattern.
base.Fatalf("go: verify takes no arguments")
}
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.RootMode = modload.NeedRoot
// Only verify up to GOMAXPROCS zips at once.
func runWhy(ctx context.Context, cmd *base.Command, args []string) {
modload.InitWorkfile()
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.RootMode = modload.NeedRoot
modload.ExplicitWriteGoMod = true // don't write go.mod in ListModules
base.Fatalf("go: -insecure flag is no longer supported; use GOINSECURE instead")
}
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
// Do not allow any updating of go.mod until we've applied
// all the requested changes and checked that the result matches
// RootMode determines whether a module root is needed.
RootMode Root
- // ForceUseModules may be set to force modules to be enabled when
- // GO111MODULE=auto or to report an error when GO111MODULE=off.
- ForceUseModules bool
-
allowMissingModuleImports bool
// ExplicitWriteGoMod prevents LoadPackages, ListModules, and other functions
// Reset the state to a clean state.
oldstate := setState(State{})
- ForceUseModules = true
+ LoaderState.ForceUseModules = true
// Load in workspace mode.
InitWorkfile()
func setState(s State) State {
oldState := State{
initialized: LoaderState.initialized,
- forceUseModules: ForceUseModules,
+ ForceUseModules: LoaderState.ForceUseModules,
rootMode: RootMode,
modRoots: modRoots,
modulesEnabled: cfg.ModulesEnabled,
requirements: requirements,
}
LoaderState.initialized = s.initialized
- ForceUseModules = s.forceUseModules
+ LoaderState.ForceUseModules = s.ForceUseModules
RootMode = s.rootMode
modRoots = s.modRoots
cfg.ModulesEnabled = s.modulesEnabled
}
type State struct {
- initialized bool
- forceUseModules bool
+ initialized bool
+
+ // ForceUseModules may be set to force modules to be enabled when
+ // GO111MODULE=auto or to report an error when GO111MODULE=off.
+ ForceUseModules bool
rootMode Root
modRoots []string
modulesEnabled bool
default:
base.Fatalf("go: unknown environment setting GO111MODULE=%s", env)
case "auto":
- mustUseModules = ForceUseModules
+ mustUseModules = LoaderState.ForceUseModules
case "on", "":
mustUseModules = true
case "off":
- if ForceUseModules {
+ if LoaderState.ForceUseModules {
base.Fatalf("go: modules disabled by GO111MODULE=off; see 'go help modules'")
}
mustUseModules = false
// This must be done before modload.Init, but we need to call work.BuildInit
// before loading packages, since it affects package locations, e.g.,
// for -race and -msan.
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.RootMode = modload.NoRoot
modload.AllowMissingModuleImports()
modload.Init()
// Set up modules without an explicit go.mod, to download distribution.
modload.Reset()
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.RootMode = modload.NoRoot
modload.Init()
// command lines if we add new flags in the future.
// Set up modules without an explicit go.mod, to download go.mod.
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.RootMode = modload.NoRoot
modload.Init()
defer modload.Reset()
//
// See golang.org/issue/40276 for details and rationale.
func installOutsideModule(ctx context.Context, args []string) {
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.RootMode = modload.NoRoot
modload.AllowMissingModuleImports()
modload.Init()
func runInit(ctx context.Context, cmd *base.Command, args []string) {
modload.InitWorkfile()
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
gowork := modload.WorkFilePath()
if gowork == "" {
}
func runSync(ctx context.Context, cmd *base.Command, args []string) {
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.InitWorkfile()
if modload.WorkFilePath() == "" {
base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using GOWORK environment variable)")
}
func runUse(ctx context.Context, cmd *base.Command, args []string) {
- modload.ForceUseModules = true
+ modload.LoaderState.ForceUseModules = true
modload.InitWorkfile()
gowork := modload.WorkFilePath()
if gowork == "" {