return ""
}
goVersion := modload.MainModules.GoVersion()
- if modload.RootMode == modload.NoRoot && p.Module != nil {
+ if modload.LoaderState.RootMode == modload.NoRoot && p.Module != nil {
// This is go install pkg@version or go run pkg@version.
// Use the Go version from the package.
// If there isn't one, then assume Go 1.20,
if !modload.LoaderState.ForceUseModules {
panic("modload.ForceUseModules must be true")
}
- if modload.RootMode != modload.NoRoot {
+ if modload.LoaderState.RootMode != modload.NoRoot {
panic("modload.RootMode must be NoRoot")
}
base.Fatalf("go: 'go mod graph' accepts no arguments")
}
modload.LoaderState.ForceUseModules = true
- modload.RootMode = modload.NeedRoot
+ modload.LoaderState.RootMode = modload.NeedRoot
goVersion := graphGo.String()
if goVersion != "" && gover.Compare(gover.Local(), goVersion) < 0 {
// that are in 'all' but outside of the main module, we must explicitly
// request that their test dependencies be included.
modload.LoaderState.ForceUseModules = true
- modload.RootMode = modload.NeedRoot
+ modload.LoaderState.RootMode = modload.NeedRoot
goVersion := tidyGo.String()
if goVersion != "" && gover.Compare(gover.Local(), goVersion) < 0 {
base.Fatalf("go: 'go mod vendor' accepts no arguments")
}
modload.LoaderState.ForceUseModules = true
- modload.RootMode = modload.NeedRoot
+ modload.LoaderState.RootMode = modload.NeedRoot
loadOpts := modload.PackageOpts{
Tags: imports.AnyTags(),
base.Fatalf("go: verify takes no arguments")
}
modload.LoaderState.ForceUseModules = true
- modload.RootMode = modload.NeedRoot
+ modload.LoaderState.RootMode = modload.NeedRoot
// Only verify up to GOMAXPROCS zips at once.
type token struct{}
func runWhy(ctx context.Context, cmd *base.Command, args []string) {
modload.InitWorkfile()
modload.LoaderState.ForceUseModules = true
- modload.RootMode = modload.NeedRoot
+ modload.LoaderState.RootMode = modload.NeedRoot
modload.ExplicitWriteGoMod = true // don't write go.mod in ListModules
loadOpts := modload.PackageOpts{
testenv.MustHaveExecPath(t, "git")
oldAllowMissingModuleImports := allowMissingModuleImports
- oldRootMode := RootMode
+ oldRootMode := LoaderState.RootMode
defer func() {
allowMissingModuleImports = oldAllowMissingModuleImports
- RootMode = oldRootMode
+ LoaderState.RootMode = oldRootMode
}()
allowMissingModuleImports = true
- RootMode = NoRoot
+ LoaderState.RootMode = NoRoot
ctx := context.Background()
rs := LoadModFile(ctx)
//
// TODO(#40775): See if these can be plumbed as explicit parameters.
var (
- // RootMode determines whether a module root is needed.
- RootMode Root
-
allowMissingModuleImports bool
// ExplicitWriteGoMod prevents LoadPackages, ListModules, and other functions
// It is exported mainly for Go toolchain switching, which must process
// the go.work very early at startup.
func FindGoWork(wd string) string {
- if RootMode == NoRoot {
+ if LoaderState.RootMode == NoRoot {
return ""
}
oldState := State{
initialized: LoaderState.initialized,
ForceUseModules: LoaderState.ForceUseModules,
- rootMode: RootMode,
+ RootMode: LoaderState.RootMode,
modRoots: modRoots,
modulesEnabled: cfg.ModulesEnabled,
mainModules: MainModules,
}
LoaderState.initialized = s.initialized
LoaderState.ForceUseModules = s.ForceUseModules
- RootMode = s.rootMode
+ LoaderState.RootMode = s.RootMode
modRoots = s.modRoots
cfg.ModulesEnabled = s.modulesEnabled
MainModules = s.mainModules
// 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
- mainModules *MainModuleSet
- requirements *Requirements
- workFilePath string
- modfetchState modfetch.State
+
+ // RootMode determines whether a module root is needed.
+ RootMode Root
+ modRoots []string
+ modulesEnabled bool
+ mainModules *MainModuleSet
+ requirements *Requirements
+ workFilePath string
+ modfetchState modfetch.State
}
func NewState() *State { return &State{} }
if modRoots != nil {
// modRoot set before Init was called ("go mod init" does this).
// No need to search for go.mod.
- } else if RootMode == NoRoot {
+ } else if LoaderState.RootMode == NoRoot {
if cfg.ModFile != "" && !base.InGOFLAGS("-modfile") {
base.Fatalf("go: -modfile cannot be used with commands that ignore the current module")
}
if cfg.ModFile != "" {
base.Fatalf("go: cannot find main module, but -modfile was set.\n\t-modfile cannot be used to set the module root directory.")
}
- if RootMode == NeedRoot {
+ if LoaderState.RootMode == NeedRoot {
base.Fatal(ErrNoModRoot)
}
if !mustUseModules {
// It's a bit of a peculiar thing to disallow but quite mysterious
// when it happens. See golang.org/issue/26708.
fmt.Fprintf(os.Stderr, "go: warning: ignoring go.mod in system temp root %v\n", os.TempDir())
- if RootMode == NeedRoot {
+ if LoaderState.RootMode == NeedRoot {
base.Fatal(ErrNoModRoot)
}
if !mustUseModules {
gopath = list[0]
if _, err := fsys.Stat(filepath.Join(gopath, "go.mod")); err == nil {
fmt.Fprintf(os.Stderr, "go: warning: ignoring go.mod in $GOPATH %v\n", gopath)
- if RootMode == NeedRoot {
+ if LoaderState.RootMode == NeedRoot {
base.Fatal(ErrNoModRoot)
}
if !mustUseModules {
// before loading packages, since it affects package locations, e.g.,
// for -race and -msan.
modload.LoaderState.ForceUseModules = true
- modload.RootMode = modload.NoRoot
+ modload.LoaderState.RootMode = modload.NoRoot
modload.AllowMissingModuleImports()
modload.Init()
} else {
// Ignore go.mod and go.work: we don't need them, and we want to be able
// to run the tool even if there's an issue with the module or workspace the
// user happens to be in.
- modload.RootMode = modload.NoRoot
+ modload.LoaderState.RootMode = modload.NoRoot
runFunc := func(b *work.Builder, ctx context.Context, a *work.Action) error {
cmdline := str.StringList(builtTool(a), a.Args)
// Set up modules without an explicit go.mod, to download distribution.
modload.Reset()
modload.LoaderState.ForceUseModules = true
- modload.RootMode = modload.NoRoot
+ modload.LoaderState.RootMode = modload.NoRoot
modload.Init()
// Download and unpack toolchain module into module cache.
// Set up modules without an explicit go.mod, to download go.mod.
modload.LoaderState.ForceUseModules = true
- modload.RootMode = modload.NoRoot
+ modload.LoaderState.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.LoaderState.ForceUseModules = true
- modload.RootMode = modload.NoRoot
+ modload.LoaderState.RootMode = modload.NoRoot
modload.AllowMissingModuleImports()
modload.Init()
BuildInit()