}
func runEditwork(ctx context.Context, cmd *base.Command, args []string) {
+ moduleLoaderState := modload.NewState()
if *editJSON && *editPrint {
base.Fatalf("go: cannot use both -json and -print")
}
if len(args) == 1 {
gowork = args[0]
} else {
- modload.InitWorkfile(modload.LoaderState)
- gowork = modload.WorkFilePath(modload.LoaderState)
+ modload.InitWorkfile(moduleLoaderState)
+ gowork = modload.WorkFilePath(moduleLoaderState)
}
if gowork == "" {
base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using GOWORK environment variable)")
}
func runInit(ctx context.Context, cmd *base.Command, args []string) {
- modload.InitWorkfile(modload.LoaderState)
+ moduleLoaderState := modload.NewState()
+ modload.InitWorkfile(moduleLoaderState)
- modload.LoaderState.ForceUseModules = true
+ moduleLoaderState.ForceUseModules = true
- gowork := modload.WorkFilePath(modload.LoaderState)
+ gowork := modload.WorkFilePath(moduleLoaderState)
if gowork == "" {
gowork = filepath.Join(base.Cwd(), "go.work")
}
wf := new(modfile.WorkFile)
wf.Syntax = new(modfile.FileSyntax)
wf.AddGoStmt(goV)
- workUse(ctx, gowork, wf, args)
+ workUse(moduleLoaderState, ctx, gowork, wf, args)
modload.WriteWorkFile(gowork, wf)
}
}
func runSync(ctx context.Context, cmd *base.Command, args []string) {
- modload.LoaderState.ForceUseModules = true
- modload.InitWorkfile(modload.LoaderState)
- if modload.WorkFilePath(modload.LoaderState) == "" {
+ moduleLoaderState := modload.NewState()
+ moduleLoaderState.ForceUseModules = true
+ modload.InitWorkfile(moduleLoaderState)
+ if modload.WorkFilePath(moduleLoaderState) == "" {
base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using GOWORK environment variable)")
}
- _, err := modload.LoadModGraph(modload.LoaderState, ctx, "")
+ _, err := modload.LoadModGraph(moduleLoaderState, ctx, "")
if err != nil {
- toolchain.SwitchOrFatal(modload.LoaderState, ctx, err)
+ toolchain.SwitchOrFatal(moduleLoaderState, ctx, err)
}
mustSelectFor := map[module.Version][]module.Version{}
- mms := modload.LoaderState.MainModules
+ mms := moduleLoaderState.MainModules
opts := modload.PackageOpts{
Tags: imports.AnyTags(),
}
for _, m := range mms.Versions() {
opts.MainModule = m
- _, pkgs := modload.LoadPackages(modload.LoaderState, ctx, opts, "all")
+ _, pkgs := modload.LoadPackages(moduleLoaderState, ctx, opts, "all")
opts.MainModule = module.Version{} // reset
var (
mustSelectFor[m] = mustSelect
}
- workFilePath := modload.WorkFilePath(modload.LoaderState) // save go.work path because EnterModule clobbers it.
+ workFilePath := modload.WorkFilePath(moduleLoaderState) // save go.work path because EnterModule clobbers it.
var goV string
for _, m := range mms.Versions() {
// Use EnterModule to reset the global state in modload to be in
// single-module mode using the modroot of m.
- modload.EnterModule(modload.LoaderState, ctx, mms.ModRoot(m))
+ modload.EnterModule(moduleLoaderState, ctx, mms.ModRoot(m))
// Edit the build list in the same way that 'go get' would if we
// requested the relevant module versions explicitly.
// so we don't write some go.mods with the "before" toolchain
// and others with the "after" toolchain. If nothing else, that
// discrepancy could show up in auto-recorded toolchain lines.
- changed, err := modload.EditBuildList(modload.LoaderState, ctx, nil, mustSelectFor[m])
+ changed, err := modload.EditBuildList(moduleLoaderState, ctx, nil, mustSelectFor[m])
if err != nil {
continue
}
if changed {
- modload.LoadPackages(modload.LoaderState, ctx, modload.PackageOpts{
+ modload.LoadPackages(moduleLoaderState, ctx, modload.PackageOpts{
Tags: imports.AnyTags(),
Tidy: true,
VendorModulesInGOROOTSrc: true,
SilenceMissingStdImports: true,
SilencePackageErrors: true,
}, "all")
- modload.WriteGoMod(modload.LoaderState, ctx, modload.WriteOpts{})
+ modload.WriteGoMod(moduleLoaderState, ctx, modload.WriteOpts{})
}
- goV = gover.Max(goV, modload.LoaderState.MainModules.GoVersion(modload.LoaderState))
+ goV = gover.Max(goV, moduleLoaderState.MainModules.GoVersion(moduleLoaderState))
}
wf, err := modload.ReadWorkFile(workFilePath)
}
func runUse(ctx context.Context, cmd *base.Command, args []string) {
- modload.LoaderState.ForceUseModules = true
- modload.InitWorkfile(modload.LoaderState)
- gowork := modload.WorkFilePath(modload.LoaderState)
+ moduleLoaderState := modload.NewState()
+ moduleLoaderState.ForceUseModules = true
+ modload.InitWorkfile(moduleLoaderState)
+ gowork := modload.WorkFilePath(moduleLoaderState)
if gowork == "" {
base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using GOWORK environment variable)")
}
if err != nil {
base.Fatal(err)
}
- workUse(ctx, gowork, wf, args)
+ workUse(moduleLoaderState, ctx, gowork, wf, args)
modload.WriteWorkFile(gowork, wf)
}
-func workUse(ctx context.Context, gowork string, wf *modfile.WorkFile, args []string) {
+func workUse(loaderstate *modload.State, ctx context.Context, gowork string, wf *modfile.WorkFile, args []string) {
workDir := filepath.Dir(gowork) // absolute, since gowork itself is absolute
haveDirs := make(map[string][]string) // absolute → original(s)
// all entries for the absolute path should be removed.
keepDirs := make(map[string]string)
- sw := toolchain.NewSwitcher(modload.LoaderState)
+ sw := toolchain.NewSwitcher(loaderstate)
// lookDir updates the entry in keepDirs for the directory dir,
// which is either absolute or relative to the current working directory
}
func runVendor(ctx context.Context, cmd *base.Command, args []string) {
- modload.InitWorkfile(modload.LoaderState)
- if modload.WorkFilePath(modload.LoaderState) == "" {
+ moduleLoaderState := modload.NewState()
+ modload.InitWorkfile(moduleLoaderState)
+ if modload.WorkFilePath(moduleLoaderState) == "" {
base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using GOWORK environment variable)")
}
- modcmd.RunVendor(modload.LoaderState, ctx, vendorE, vendorO, args)
+ modcmd.RunVendor(moduleLoaderState, ctx, vendorE, vendorO, args)
}