fm := template.FuncMap{
"join": strings.Join,
"context": context,
- "module": func(path string) *modinfo.ModulePublic { return modload.ModuleInfo(ctx, path) },
+ "module": func(path string) *modinfo.ModulePublic { return modload.ModuleInfo(modload.LoaderState, ctx, path) },
}
tmpl, err := template.New("main").Funcs(fm).Parse(*listFmt)
if err != nil {
if *listReuse != "" && len(args) == 0 {
base.Fatalf("go: list -m -reuse only has an effect with module@version arguments")
}
- mods, err := modload.ListModules(ctx, args, mode, *listReuse)
+ mods, err := modload.ListModules(modload.LoaderState, ctx, args, mode, *listReuse)
if !*listE {
for _, m := range mods {
if m.Error != nil {
sema.Release(1)
wg.Done()
}
- pmain, ptest, pxtest = load.TestPackagesAndErrors(ctx, done, pkgOpts, p, nil)
+ pmain, ptest, pxtest = load.TestPackagesAndErrors(modload.LoaderState, ctx, done, pkgOpts, p, nil)
} else {
var perr *load.Package
- pmain, ptest, pxtest, perr = load.TestPackagesFor(ctx, pkgOpts, p, nil)
+ pmain, ptest, pxtest, perr = load.TestPackagesFor(modload.LoaderState, ctx, pkgOpts, p, nil)
if perr != nil {
base.Fatalf("go: can't load test package: %s", perr.Error)
}
// TODO: Use pkgsFilter?
for _, p := range pkgs {
if len(p.GoFiles)+len(p.CgoFiles) > 0 {
- a.Deps = append(a.Deps, b.AutoAction(work.ModeInstall, work.ModeInstall, p))
+ a.Deps = append(a.Deps, b.AutoAction(modload.LoaderState, work.ModeInstall, work.ModeInstall, p))
}
}
b.Do(ctx, a)
for _, p := range pkgs {
// Show vendor-expanded paths in listing
- p.TestImports = p.Resolve(p.TestImports)
- p.XTestImports = p.Resolve(p.XTestImports)
+ p.TestImports = p.Resolve(modload.LoaderState, p.TestImports)
+ p.XTestImports = p.Resolve(modload.LoaderState, p.XTestImports)
p.DepOnly = !cmdline[p]
if *listCompiled {
if *listRetracted {
mode |= modload.ListRetracted
}
- rmods, err := modload.ListModules(ctx, args, mode, *listReuse)
+ rmods, err := modload.ListModules(modload.LoaderState, ctx, args, mode, *listReuse)
if err != nil && !*listE {
base.Error(err)
}
// can produce better error messages if it starts with the original paths.
// The initial load of p loads all the non-test imports and rewrites
// the vendored paths, so nothing should ever call p.vendored(p.Imports).
-func (p *Package) Resolve(imports []string) []string {
+func (p *Package) Resolve(loaderstate *modload.State, imports []string) []string {
if len(imports) > 0 && len(p.Imports) > 0 && &imports[0] == &p.Imports[0] {
panic("internal error: p.Resolve(p.Imports) called")
}
seen := make(map[string]bool)
var all []string
for _, path := range imports {
- path = ResolveImportPath(p, path)
+ path = ResolveImportPath(loaderstate, p, path)
if !seen[path] {
seen[path] = true
all = append(all, path)
// First, there is Go 1.5 vendoring (golang.org/s/go15vendor).
// If vendor expansion doesn't trigger, then the path is also subject to
// Go 1.11 module legacy conversion (golang.org/issue/25069).
-func ResolveImportPath(parent *Package, path string) (found string) {
+func ResolveImportPath(loaderstate *modload.State, parent *Package, path string) (found string) {
var parentPath, parentDir, parentRoot string
parentIsStd := false
if parent != nil {
parentRoot = parent.Root
parentIsStd = parent.Standard
}
- return resolveImportPath(modload.LoaderState, path, parentPath, parentDir, parentRoot, parentIsStd)
+ return resolveImportPath(loaderstate, path, parentPath, parentDir, parentRoot, parentIsStd)
}
func resolveImportPath(loaderstate *modload.State, path, parentPath, parentDir, parentRoot string, parentIsStd bool) (found string) {
// the package containing an error if the test packages or
// their dependencies have errors.
// Only test packages without errors are returned.
-func TestPackagesFor(ctx context.Context, opts PackageOpts, p *Package, cover *TestCover) (pmain, ptest, pxtest, perr *Package) {
- pmain, ptest, pxtest = TestPackagesAndErrors(ctx, nil, opts, p, cover)
+func TestPackagesFor(loaderstate *modload.State, ctx context.Context, opts PackageOpts, p *Package, cover *TestCover) (pmain, ptest, pxtest, perr *Package) {
+ pmain, ptest, pxtest = TestPackagesAndErrors(loaderstate, ctx, nil, opts, p, cover)
for _, p1 := range []*Package{ptest, pxtest, pmain} {
if p1 == nil {
// pxtest may be nil
//
// The caller is expected to have checked that len(p.TestGoFiles)+len(p.XTestGoFiles) > 0,
// or else there's no point in any of this.
-func TestPackagesAndErrors(ctx context.Context, done func(), opts PackageOpts, p *Package, cover *TestCover) (pmain, ptest, pxtest *Package) {
+func TestPackagesAndErrors(loaderstate *modload.State, ctx context.Context, done func(), opts PackageOpts, p *Package, cover *TestCover) (pmain, ptest, pxtest *Package) {
ctx, span := trace.StartSpan(ctx, "load.TestPackagesAndErrors")
defer span.Done()
defer pre.flush()
allImports := append([]string{}, p.TestImports...)
allImports = append(allImports, p.XTestImports...)
- pre.preloadImports(modload.LoaderState, ctx, opts, allImports, p.Internal.Build)
+ pre.preloadImports(loaderstate, ctx, opts, allImports, p.Internal.Build)
var ptestErr, pxtestErr *PackageError
var imports, ximports []*Package
stk.Push(ImportInfo{Pkg: p.ImportPath + " (test)"})
rawTestImports := str.StringList(p.TestImports)
for i, path := range p.TestImports {
- p1, err := loadImport(modload.LoaderState, ctx, opts, pre, path, p.Dir, p, &stk, p.Internal.Build.TestImportPos[path], ResolveImport)
+ p1, err := loadImport(loaderstate, ctx, opts, pre, path, p.Dir, p, &stk, p.Internal.Build.TestImportPos[path], ResolveImport)
if err != nil && ptestErr == nil {
ptestErr = err
incomplete = true
var pxtestIncomplete bool
rawXTestImports := str.StringList(p.XTestImports)
for i, path := range p.XTestImports {
- p1, err := loadImport(modload.LoaderState, ctx, opts, pre, path, p.Dir, p, &stk, p.Internal.Build.XTestImportPos[path], ResolveImport)
+ p1, err := loadImport(loaderstate, ctx, opts, pre, path, p.Dir, p, &stk, p.Internal.Build.XTestImportPos[path], ResolveImport)
if err != nil && pxtestErr == nil {
pxtestErr = err
}
}
pb := p.Internal.Build
- pmain.DefaultGODEBUG = defaultGODEBUG(modload.LoaderState, pmain, pb.Directives, pb.TestDirectives, pb.XTestDirectives)
+ pmain.DefaultGODEBUG = defaultGODEBUG(loaderstate, pmain, pb.Directives, pb.TestDirectives, pb.XTestDirectives)
if pmain.Internal.BuildInfo == nil || pmain.DefaultGODEBUG != p.DefaultGODEBUG {
// Either we didn't generate build info for the package under test (because it wasn't package main), or
// the DefaultGODEBUG used to build the test main package is different from the DefaultGODEBUG
if dep == ptest.ImportPath {
pmain.Internal.Imports = append(pmain.Internal.Imports, ptest)
} else {
- p1, err := loadImport(modload.LoaderState, ctx, opts, pre, dep, "", nil, &stk, nil, 0)
+ p1, err := loadImport(loaderstate, ctx, opts, pre, dep, "", nil, &stk, nil, 0)
if err != nil && pmain.Error == nil {
pmain.Error = err
pmain.Incomplete = true
var mods []*ModuleJSON
type token struct{}
sem := make(chan token, runtime.GOMAXPROCS(0))
- infos, infosErr := modload.ListModules(ctx, args, 0, *downloadReuse)
+ infos, infosErr := modload.ListModules(modload.LoaderState, ctx, args, 0, *downloadReuse)
// There is a bit of a chicken-and-egg problem here: ideally we need to know
// which Go version to switch to download the requested modules, but if we
goVersion := ""
if includeGoVersions {
- goVersion = modload.ModuleInfo(ctx, m.Path).GoVersion
+ goVersion = modload.ModuleInfo(modload.LoaderState, ctx, m.Path).GoVersion
}
switch {
case isExplicit[m] && goVersion != "":
}
}
- mods, err := modload.ListModules(ctx, args, 0, "")
+ mods, err := modload.ListModules(modload.LoaderState, ctx, args, 0, "")
if err != nil {
base.Fatal(err)
}
return root
}
-func ModuleInfo(ctx context.Context, path string) *modinfo.ModulePublic {
- if !Enabled(LoaderState) {
+func ModuleInfo(loaderstate *State, ctx context.Context, path string) *modinfo.ModulePublic {
+ if !Enabled(loaderstate) {
return nil
}
if path, vers, found := strings.Cut(path, "@"); found {
m := module.Version{Path: path, Version: vers}
- return moduleInfo(LoaderState, ctx, nil, m, 0, nil)
+ return moduleInfo(loaderstate, ctx, nil, m, 0, nil)
}
- rs := LoadModFile(LoaderState, ctx)
+ rs := LoadModFile(loaderstate, ctx)
var (
v string
ok bool
)
if rs.pruning == pruned {
- v, ok = rs.rootSelected(LoaderState, path)
+ v, ok = rs.rootSelected(loaderstate, path)
}
if !ok {
- mg, err := rs.Graph(LoaderState, ctx)
+ mg, err := rs.Graph(loaderstate, ctx)
if err != nil {
base.Fatal(err)
}
}
}
- return moduleInfo(LoaderState, ctx, rs, module.Version{Path: path, Version: v}, 0, nil)
+ return moduleInfo(loaderstate, ctx, rs, module.Version{Path: path, Version: v}, 0, nil)
}
// addUpdate fills in m.Update if an updated version is available.
-func addUpdate(ctx context.Context, m *modinfo.ModulePublic) {
+func addUpdate(loaderstate *State, ctx context.Context, m *modinfo.ModulePublic) {
if m.Version == "" {
return
}
- info, err := Query(LoaderState, ctx, m.Path, "upgrade", m.Version, CheckAllowed)
+ info, err := Query(loaderstate, ctx, m.Path, "upgrade", m.Version, CheckAllowed)
if _, ok := errors.AsType[*NoMatchingVersionError](err); ok ||
errors.Is(err, fs.ErrNotExist) ||
errors.Is(err, ErrDisallowed) {
// addVersions fills in m.Versions with the list of known versions.
// Excluded versions will be omitted. If listRetracted is false, retracted
// versions will also be omitted.
-func addVersions(ctx context.Context, m *modinfo.ModulePublic, listRetracted bool) {
+func addVersions(loaderstate *State, ctx context.Context, m *modinfo.ModulePublic, listRetracted bool) {
// TODO(bcmills): Would it make sense to check for reuse here too?
// Perhaps that doesn't buy us much, though: we would always have to fetch
// all of the version tags to list the available versions anyway.
if listRetracted {
allowed = CheckExclusions
}
- v, origin, err := versions(LoaderState, ctx, m.Path, allowed)
+ v, origin, err := versions(loaderstate, ctx, m.Path, allowed)
if err != nil && m.Error == nil {
m.Error = &modinfo.ModuleError{Err: err.Error()}
}
// addDeprecation fills in m.Deprecated if the module was deprecated by its
// author. m.Error is set if there's an error loading deprecation information.
-func addDeprecation(ctx context.Context, m *modinfo.ModulePublic) {
- deprecation, err := CheckDeprecation(LoaderState, ctx, module.Version{Path: m.Path, Version: m.Version})
+func addDeprecation(loaderstate *State, ctx context.Context, m *modinfo.ModulePublic) {
+ deprecation, err := CheckDeprecation(loaderstate, ctx, module.Version{Path: m.Path, Version: m.Version})
if _, ok := errors.AsType[*NoMatchingVersionError](err); ok || errors.Is(err, fs.ErrNotExist) {
// Ignore "no matching version" and "not found" errors.
// This means the proxy has no matching version or no versions at all.
// along with any error preventing additional matches from being identified.
//
// The returned slice can be nonempty even if the error is non-nil.
-func ListModules(ctx context.Context, args []string, mode ListMode, reuseFile string) ([]*modinfo.ModulePublic, error) {
+func ListModules(loaderstate *State, ctx context.Context, args []string, mode ListMode, reuseFile string) ([]*modinfo.ModulePublic, error) {
var reuse map[module.Version]*modinfo.ModulePublic
if reuseFile != "" {
data, err := os.ReadFile(reuseFile)
}
}
- rs, mods, err := listModules(ctx, LoadModFile(LoaderState, ctx), args, mode, reuse)
+ rs, mods, err := listModules(loaderstate, ctx, LoadModFile(loaderstate, ctx), args, mode, reuse)
type token struct{}
sem := make(chan token, runtime.GOMAXPROCS(0))
sem <- token{}
go func() {
if mode&ListU != 0 {
- addUpdate(ctx, m)
+ addUpdate(loaderstate, ctx, m)
}
if mode&ListVersions != 0 {
- addVersions(ctx, m, mode&ListRetractedVersions != 0)
+ addVersions(loaderstate, ctx, m, mode&ListRetractedVersions != 0)
}
if mode&ListRetracted != 0 {
- addRetraction(LoaderState, ctx, m)
+ addRetraction(loaderstate, ctx, m)
}
if mode&ListDeprecated != 0 {
- addDeprecation(ctx, m)
+ addDeprecation(loaderstate, ctx, m)
}
<-sem
}()
}
if err == nil {
- LoaderState.requirements = rs
+ loaderstate.requirements = rs
// TODO(#61605): The extra ListU clause fixes a problem with Go 1.21rc3
// where "go mod tidy" and "go list -m -u all" fight over whether the go.sum
// should be considered up-to-date. The fix for now is to always treat the
// but in general list -u is looking up other checksums in the checksum database
// that won't be necessary later, so it makes sense not to write the go.sum back out.
if !ExplicitWriteGoMod && mode&ListU == 0 {
- err = commitRequirements(LoaderState, ctx, WriteOpts{})
+ err = commitRequirements(loaderstate, ctx, WriteOpts{})
}
}
return mods, err
}
-func listModules(ctx context.Context, rs *Requirements, args []string, mode ListMode, reuse map[module.Version]*modinfo.ModulePublic) (_ *Requirements, mods []*modinfo.ModulePublic, mgErr error) {
+func listModules(loaderstate *State, ctx context.Context, rs *Requirements, args []string, mode ListMode, reuse map[module.Version]*modinfo.ModulePublic) (_ *Requirements, mods []*modinfo.ModulePublic, mgErr error) {
if len(args) == 0 {
var ms []*modinfo.ModulePublic
- for _, m := range LoaderState.MainModules.Versions() {
+ for _, m := range loaderstate.MainModules.Versions() {
if gover.IsToolchain(m.Path) {
continue
}
- ms = append(ms, moduleInfo(LoaderState, ctx, rs, m, mode, reuse))
+ ms = append(ms, moduleInfo(loaderstate, ctx, rs, m, mode, reuse))
}
return rs, ms, nil
}
}
if arg == "all" || strings.Contains(arg, "...") {
needFullGraph = true
- if !HasModRoot(LoaderState) {
+ if !HasModRoot(loaderstate) {
base.Fatalf("go: cannot match %q: %v", arg, ErrNoModRoot)
}
continue
}
if path, vers, found := strings.Cut(arg, "@"); found {
if vers == "upgrade" || vers == "patch" {
- if _, ok := rs.rootSelected(LoaderState, path); !ok || rs.pruning == unpruned {
+ if _, ok := rs.rootSelected(loaderstate, path); !ok || rs.pruning == unpruned {
needFullGraph = true
- if !HasModRoot(LoaderState) {
+ if !HasModRoot(loaderstate) {
base.Fatalf("go: cannot match %q: %v", arg, ErrNoModRoot)
}
}
}
continue
}
- if _, ok := rs.rootSelected(LoaderState, arg); !ok || rs.pruning == unpruned {
+ if _, ok := rs.rootSelected(loaderstate, arg); !ok || rs.pruning == unpruned {
needFullGraph = true
- if mode&ListVersions == 0 && !HasModRoot(LoaderState) {
+ if mode&ListVersions == 0 && !HasModRoot(loaderstate) {
base.Fatalf("go: cannot match %q without -versions or an explicit version: %v", arg, ErrNoModRoot)
}
}
var mg *ModuleGraph
if needFullGraph {
- rs, mg, mgErr = expandGraph(LoaderState, ctx, rs)
+ rs, mg, mgErr = expandGraph(loaderstate, ctx, rs)
}
matchedModule := map[module.Version]bool{}
if path, vers, found := strings.Cut(arg, "@"); found {
var current string
if mg == nil {
- current, _ = rs.rootSelected(LoaderState, path)
+ current, _ = rs.rootSelected(loaderstate, path)
} else {
current = mg.Selected(path)
}
// specific revision or used 'go list -retracted'.
allowed = nil
}
- info, err := queryReuse(LoaderState, ctx, path, vers, current, allowed, reuse)
+ info, err := queryReuse(loaderstate, ctx, path, vers, current, allowed, reuse)
if err != nil {
var origin *codehost.Origin
if info != nil {
// *Requirements instead.
var noRS *Requirements
- mod := moduleInfo(LoaderState, ctx, noRS, module.Version{Path: path, Version: info.Version}, mode, reuse)
+ mod := moduleInfo(loaderstate, ctx, noRS, module.Version{Path: path, Version: info.Version}, mode, reuse)
if vers != mod.Version {
mod.Query = vers
}
var v string
if mg == nil {
var ok bool
- v, ok = rs.rootSelected(LoaderState, arg)
+ v, ok = rs.rootSelected(loaderstate, arg)
if !ok {
// We checked rootSelected(arg) in the earlier args loop, so if there
// is no such root we should have loaded a non-nil mg.
continue
}
if v != "none" {
- mods = append(mods, moduleInfo(LoaderState, ctx, rs, module.Version{Path: arg, Version: v}, mode, reuse))
+ mods = append(mods, moduleInfo(loaderstate, ctx, rs, module.Version{Path: arg, Version: v}, mode, reuse))
} else if cfg.BuildMod == "vendor" {
// In vendor mode, we can't determine whether a missing module is “a
// known dependency” because the module graph is incomplete.
fetchedMods := make([]*modinfo.ModulePublic, len(matches))
for i, m := range matches {
q.Add(func() {
- fetchedMods[i] = moduleInfo(LoaderState, ctx, rs, m, mode, reuse)
+ fetchedMods[i] = moduleInfo(loaderstate, ctx, rs, m, mode, reuse)
})
}
<-q.Idle()
Paths: cfg.BuildCoverPkg,
}
}
- pmain, ptest, pxtest, perr := load.TestPackagesFor(ctx, pkgOpts, p, cover)
+ pmain, ptest, pxtest, perr := load.TestPackagesFor(modload.LoaderState, ctx, pkgOpts, p, cover)
if perr != nil {
return nil, nil, nil, perr, perr.Error
}
root := &work.Action{Mode: "go " + cmd.Name()}
for _, p := range pkgs {
- _, ptest, pxtest, perr := load.TestPackagesFor(ctx, pkgOpts, p, nil)
+ _, ptest, pxtest, perr := load.TestPackagesFor(modload.LoaderState, ctx, pkgOpts, p, nil)
if perr != nil {
base.Errorf("%v", perr.Error)
continue
}
// AutoAction returns the "right" action for go build or go install of p.
-func (b *Builder) AutoAction(mode, depMode BuildMode, p *load.Package) *Action {
+func (b *Builder) AutoAction(loaderstate *modload.State, mode, depMode BuildMode, p *load.Package) *Action {
if p.Name == "main" {
- return b.LinkAction(modload.LoaderState, mode, depMode, p)
+ return b.LinkAction(loaderstate, mode, depMode, p)
}
return b.CompileAction(mode, depMode, p)
}
p.Target += cfg.ExeSuffix
p.Stale = true
p.StaleReason = "build -o flag in use"
- a.Deps = append(a.Deps, b.AutoAction(ModeInstall, depMode, p))
+ a.Deps = append(a.Deps, b.AutoAction(modload.LoaderState, ModeInstall, depMode, p))
}
if len(a.Deps) == 0 {
base.Fatalf("go: no main packages to build")
p.Target = cfg.BuildO
p.Stale = true // must build - not up to date
p.StaleReason = "build -o flag in use"
- a := b.AutoAction(ModeInstall, depMode, p)
+ a := b.AutoAction(modload.LoaderState, ModeInstall, depMode, p)
b.Do(ctx, a)
return
}
a := &Action{Mode: "go build"}
for _, p := range pkgs {
- a.Deps = append(a.Deps, b.AutoAction(ModeBuild, depMode, p))
+ a.Deps = append(a.Deps, b.AutoAction(modload.LoaderState, ModeBuild, depMode, p))
}
if cfg.BuildBuildmode == "shared" {
a = b.buildmodeShared(ModeBuild, depMode, args, pkgs, a)
// If p is a tool, delay the installation until the end of the build.
// This avoids installing assemblers/compilers that are being executed
// by other steps in the build.
- a1 := b.AutoAction(ModeInstall, depMode, p)
+ a1 := b.AutoAction(modload.LoaderState, ModeInstall, depMode, p)
if load.InstallTargetDir(p) == load.ToTool {
a.Deps = append(a.Deps, a1.Deps...)
a1.Deps = append(a1.Deps, a)