func EnterModule(ctx context.Context, enterModroot string) {
LoaderState.MainModules = nil // reset MainModules
LoaderState.requirements = nil
- workFilePath = "" // Force module mode
+ LoaderState.workFilePath = "" // Force module mode
modfetch.Reset()
LoaderState.modRoots = []string{enterModroot}
}, nil
}
-// Variable set in InitWorkfile
-var (
- // Set to the path to the go.work file, or "" if workspace mode is disabled.
- workFilePath string
-)
-
type MainModuleSet struct {
// versions are the module.Version values of each of the main modules.
// For each of them, the Path fields are ordinary module paths and the Version
if err := fsys.Init(); err != nil {
base.Fatal(err)
}
- workFilePath = FindGoWork(base.Cwd())
+ LoaderState.workFilePath = FindGoWork(base.Cwd())
}
// FindGoWork returns the name of the go.work file for this command,
// WorkFilePath returns the absolute path of the go.work file, or "" if not in
// workspace mode. WorkFilePath must be called after InitWorkfile.
func WorkFilePath() string {
- return workFilePath
+ return LoaderState.workFilePath
}
// Reset clears all the initialized, cached state about the use of modules,
cfg.ModulesEnabled = s.modulesEnabled
LoaderState.MainModules = s.MainModules
LoaderState.requirements = s.requirements
- workFilePath = s.workFilePath
+ LoaderState.workFilePath = s.workFilePath
// The modfetch package's global state is used to compute
// the go.sum file, so save and restore it along with the
// modload state.
// commitRequirements functions. All other functions that need or
// produce a *Requirements should accept and/or return an explicit
// parameter.
- requirements *Requirements
+ requirements *Requirements
+
+ // Set to the path to the go.work file, or "" if workspace mode is
+ // disabled
workFilePath string
modfetchState modfetch.State
}
base.Fatalf("go: -modfile cannot be used with commands that ignore the current module")
}
LoaderState.modRoots = nil
- } else if workFilePath != "" {
+ } else if LoaderState.workFilePath != "" {
// We're in workspace mode, which implies module mode.
if cfg.ModFile != "" {
base.Fatalf("go: -modfile cannot be used in workspace mode")
if !Enabled() {
return false
}
- return workFilePath != ""
+ return LoaderState.workFilePath != ""
}
// HasModRoot reports whether a main module or main modules are present.
var workFile *modfile.WorkFile
if inWorkspaceMode() {
var err error
- workFile, LoaderState.modRoots, err = LoadWorkFile(workFilePath)
+ workFile, LoaderState.modRoots, err = LoadWorkFile(LoaderState.workFilePath)
if err != nil {
return nil, err
}
sumFile := strings.TrimSuffix(modFilePath(modRoot), ".mod") + ".sum"
modfetch.WorkspaceGoSumFiles = append(modfetch.WorkspaceGoSumFiles, sumFile)
}
- modfetch.GoSumFile = workFilePath + ".sum"
+ modfetch.GoSumFile = LoaderState.workFilePath + ".sum"
} else if len(LoaderState.modRoots) == 0 {
// We're in module mode, but not inside a module.
//
}
}
vendorDir := ""
- if workFilePath != "" {
- vendorDir = filepath.Join(filepath.Dir(workFilePath), "vendor")
+ if LoaderState.workFilePath != "" {
+ vendorDir = filepath.Join(filepath.Dir(LoaderState.workFilePath), "vendor")
} else {
if len(LoaderState.modRoots) != 1 {
panic(fmt.Errorf("outside workspace mode, but have %v modRoots", LoaderState.modRoots))