// but the command line is not.
// TODO(bcmills): modload.EditBuildList should catch this instead,
// and then this can be changed to base.Fatal(err).
- toolchain.SwitchOrFatal(ctx, err)
+ toolchain.SwitchOrFatal(modload.LoaderState, ctx, err)
}
newReqs := reqsFromGoMod(modload.ModFile())
// methods.
mg, err := modload.LoadModGraph(ctx, "")
if err != nil {
- toolchain.SwitchOrFatal(ctx, err)
+ toolchain.SwitchOrFatal(modload.LoaderState, ctx, err)
}
buildList := mg.BuildList()
// are old enough but the go command itself is not new
// enough. See the related comment on the SwitchOrFatal
// in runGet when WriteGoMod returns an error.
- toolchain.SwitchOrFatal(ctx, err)
+ toolchain.SwitchOrFatal(modload.LoaderState, ctx, err)
}
}
changed, err := modload.EditBuildList(modload.LoaderState, ctx, additions, resolved)
if err != nil {
if errors.Is(err, gover.ErrTooNew) {
- toolchain.SwitchOrFatal(ctx, err)
+ toolchain.SwitchOrFatal(modload.LoaderState, ctx, err)
}
constraint, ok := errors.AsType[*modload.ConstraintError](err)
mg, err := modload.LoadModGraph(ctx, "")
if err != nil {
- toolchain.SwitchOrFatal(ctx, err)
+ toolchain.SwitchOrFatal(modload.LoaderState, ctx, err)
}
r.buildList = mg.BuildList()
// It must be called early in startup.
// See https://go.dev/doc/toolchain#select.
func Select() {
+ moduleLoaderState := modload.NewState()
log.SetPrefix("go: ")
defer log.SetPrefix("")
- if !modload.WillBeEnabled() {
+ if !modload.WillBeEnabled(moduleLoaderState) {
return
}
gotoolchain = minToolchain
if mode == "auto" || mode == "path" {
// Read go.mod to find new minimum and suggested toolchain.
- file, goVers, toolchain := modGoToolchain()
+ file, goVers, toolchain := modGoToolchain(moduleLoaderState)
gover.Startup.AutoFile = file
if toolchain == "default" {
// "default" means always use the default toolchain,
}
}
}
- maybeSwitchForGoInstallVersion(minVers)
+ maybeSwitchForGoInstallVersion(moduleLoaderState, minVers)
}
// If we are invoked as a target toolchain, confirm that
}
counterSelectExec.Inc()
- Exec(modload.LoaderState, gotoolchain)
+ Exec(moduleLoaderState, gotoolchain)
}
var counterSelectExec = counter.New("go/toolchain/select-exec")
// modGoToolchain finds the enclosing go.work or go.mod file
// and returns the go version and toolchain lines from the file.
// The toolchain line overrides the version line
-func modGoToolchain() (file, goVers, toolchain string) {
+func modGoToolchain(loaderstate *modload.State) (file, goVers, toolchain string) {
wd := base.UncachedCwd()
- file = modload.FindGoWork(modload.LoaderState, wd)
+ file = modload.FindGoWork(loaderstate, wd)
// $GOWORK can be set to a file that does not yet exist, if we are running 'go work init'.
// Do not try to load the file in that case
if _, err := os.Stat(file); err != nil {
// maybeSwitchForGoInstallVersion reports whether the command line is go install m@v or go run m@v.
// If so, switch to the go version required to build m@v if it's higher than minVers.
-func maybeSwitchForGoInstallVersion(minVers string) {
+func maybeSwitchForGoInstallVersion(loaderstate *modload.State, minVers string) {
// Note: We assume there are no flags between 'go' and 'install' or 'run'.
// During testing there are some debugging flags that are accepted
// in that position, but in production go binaries there are not.
// command lines if we add new flags in the future.
// Set up modules without an explicit go.mod, to download go.mod.
- modload.LoaderState.ForceUseModules = true
- modload.LoaderState.RootMode = modload.NoRoot
- modload.Init(modload.LoaderState)
- defer modload.LoaderState.Reset()
+ loaderstate.ForceUseModules = true
+ loaderstate.RootMode = modload.NoRoot
+ modload.Init(loaderstate)
+ defer loaderstate.Reset()
// See internal/load.PackagesAndErrorsOutsideModule
ctx := context.Background()
allowed = nil
}
noneSelected := func(path string) (version string) { return "none" }
- _, err := modload.QueryPackages(modload.LoaderState, ctx, path, version, noneSelected, allowed)
+ _, err := modload.QueryPackages(loaderstate, ctx, path, version, noneSelected, allowed)
if errors.Is(err, gover.ErrTooNew) {
// Run early switch, same one go install or go run would eventually do,
// if it understood all the command-line flags.
- s := NewSwitcher(modload.LoaderState)
+ s := NewSwitcher(loaderstate)
s.Error(err)
if s.TooNew != nil && gover.Compare(s.TooNew.GoVersion, minVers) > 0 {
- SwitchOrFatal(ctx, err)
+ SwitchOrFatal(loaderstate, ctx, err)
}
}
}