if deprecation != "" {
fmt.Fprintf(os.Stderr, "go: module %s is deprecated: %s\n", rootMod.Path, modload.ShortMessage(deprecation, ""))
}
- data, err := modfetch.GoMod(ctx, rootMod.Path, rootMod.Version)
+ data, err := modfetch.Fetcher_.GoMod(ctx, rootMod.Path, rootMod.Version)
if err != nil {
return nil, fmt.Errorf("%s: %w", args[0], err)
}
return r.repo(ctx).GoMod(ctx, version)
}
text, err := r.gomodCache.Do(version, func() ([]byte, error) {
- file, text, err := readDiskGoMod(ctx, r.path, version)
+ file, text, err := Fetcher_.readDiskGoMod(ctx, r.path, version)
if err == nil {
// Note: readDiskGoMod already called checkGoMod.
return text, nil
text, err = r.repo(ctx).GoMod(ctx, version)
if err == nil {
- if err := checkGoMod(r.path, version, text); err != nil {
+ if err := checkGoMod(Fetcher_, r.path, version, text); err != nil {
return text, err
}
if err := writeDiskGoMod(ctx, file, text); err != nil {
var info *RevInfo
var err2info map[error]*RevInfo
err := TryProxies(func(proxy string) error {
- i, err := Lookup(ctx, proxy, path).Stat(ctx, version)
+ i, err := Fetcher_.Lookup(ctx, proxy, path).Stat(ctx, version)
if err == nil {
info = i
} else {
// GoMod is like Lookup(ctx, path).GoMod(rev) but avoids the
// repository path resolution in Lookup if the result is
// already cached on local disk.
-func GoMod(ctx context.Context, path, rev string) ([]byte, error) {
+func (f *Fetcher) GoMod(ctx context.Context, path, rev string) ([]byte, error) {
// Convert commit hash to pseudo-version
// to increase cache hit rate.
if !gover.ModIsValid(path, rev) {
return nil, err
}
err := TryProxies(func(proxy string) error {
- info, err := Lookup(ctx, proxy, path).Stat(ctx, rev)
+ info, err := f.Lookup(ctx, proxy, path).Stat(ctx, rev)
if err == nil {
rev = info.Version
}
}
}
- _, data, err := readDiskGoMod(ctx, path, rev)
+ _, data, err := f.readDiskGoMod(ctx, path, rev)
if err == nil {
return data, nil
}
err = TryProxies(func(proxy string) (err error) {
- data, err = Lookup(ctx, proxy, path).GoMod(ctx, rev)
+ data, err = f.Lookup(ctx, proxy, path).GoMod(ctx, rev)
return err
})
return data, err
if !gover.ModIsValid(path, version) {
return "", fmt.Errorf("invalid version %q", version)
}
- if _, err := GoMod(ctx, path, version); err != nil {
+ if _, err := Fetcher_.GoMod(ctx, path, version); err != nil {
return "", err
}
// GoMod should have populated the disk cache for us.
if !gover.ModIsValid(path, version) {
return "", fmt.Errorf("invalid version %q", version)
}
- data, err := GoMod(ctx, path, version)
+ data, err := Fetcher_.GoMod(ctx, path, version)
if err != nil {
return "", err
}
// returning the name of the cache file and the result.
// If the read fails, the caller can use
// writeDiskGoMod(file, data) to write a new cache entry.
-func readDiskGoMod(ctx context.Context, path, rev string) (file string, data []byte, err error) {
+func (f *Fetcher) readDiskGoMod(ctx context.Context, path, rev string) (file string, data []byte, err error) {
if gover.IsToolchain(path) {
return "", nil, errNotCached
}
}
if err == nil {
- if err := checkGoMod(path, rev, data); err != nil {
+ if err := checkGoMod(f, path, rev, data); err != nil {
return "", nil, err
}
}
}
ctx := context.Background()
- repo := Lookup(ctx, "direct", tt.path)
+ repo := Fetcher_.Lookup(ctx, "direct", tt.path)
if tt.mpath == "" {
tt.mpath = tt.path
}
ctx := context.Background()
- repo := Lookup(ctx, "direct", tt.path)
+ repo := Fetcher_.Lookup(ctx, "direct", tt.path)
list, err := repo.Versions(ctx, tt.prefix)
if err != nil {
t.Fatalf("Versions(%q): %v", tt.prefix, err)
}
ctx := context.Background()
- repo := Lookup(ctx, "direct", tt.path)
+ repo := Fetcher_.Lookup(ctx, "direct", tt.path)
info, err := repo.Latest(ctx)
if err != nil {
if tt.err != "" {
// Return early if the zip and ziphash files exist.
if _, err := os.Stat(zipfile); err == nil {
if _, err := os.Stat(ziphashfile); err == nil {
- if !HaveSum(mod) {
+ if !HaveSum(Fetcher_, mod) {
checkMod(ctx, mod)
}
return zipfile, nil
if unrecoverableErr != nil {
return unrecoverableErr
}
- repo := Lookup(ctx, proxy, mod.Path)
+ repo := Fetcher_.Lookup(ctx, proxy, mod.Path)
err := repo.Zip(ctx, f, mod.Version)
if err != nil {
// Zip may have partially written to f before failing.
if err != nil {
return err
}
- if err := checkModSum(mod, hash); err != nil {
+ if err := checkModSum(Fetcher_, mod, hash); err != nil {
return err
}
hf, err := lockedfile.Create(ziphashfile)
// The boolean it returns reports whether the
// use of go.sum is now enabled.
// The goSum lock must be held.
-func initGoSum() (bool, error) {
- if Fetcher_.goSumFile == "" {
+func (f *Fetcher) initGoSum() (bool, error) {
+ if f.goSumFile == "" {
return false, nil
}
- if Fetcher_.sumState.m != nil {
+ if f.sumState.m != nil {
return true, nil
}
- Fetcher_.sumState.m = make(map[module.Version][]string)
- Fetcher_.sumState.status = make(map[modSum]modSumStatus)
- Fetcher_.sumState.w = make(map[string]map[module.Version][]string)
+ f.sumState.m = make(map[module.Version][]string)
+ f.sumState.status = make(map[modSum]modSumStatus)
+ f.sumState.w = make(map[string]map[module.Version][]string)
- for _, f := range Fetcher_.workspaceGoSumFiles {
- Fetcher_.sumState.w[f] = make(map[module.Version][]string)
- _, err := readGoSumFile(Fetcher_.sumState.w[f], f)
+ for _, fn := range f.workspaceGoSumFiles {
+ f.sumState.w[fn] = make(map[module.Version][]string)
+ _, err := readGoSumFile(f.sumState.w[fn], fn)
if err != nil {
return false, err
}
}
- enabled, err := readGoSumFile(Fetcher_.sumState.m, Fetcher_.goSumFile)
- Fetcher_.sumState.enabled = enabled
+ enabled, err := readGoSumFile(f.sumState.m, f.goSumFile)
+ f.sumState.enabled = enabled
return enabled, err
}
// The entry's hash must be generated with a known hash algorithm.
// mod.Version may have a "/go.mod" suffix to distinguish sums for
// .mod and .zip files.
-func HaveSum(mod module.Version) bool {
- Fetcher_.mu.Lock()
- defer Fetcher_.mu.Unlock()
- inited, err := initGoSum()
+func HaveSum(f *Fetcher, mod module.Version) bool {
+ f.mu.Lock()
+ defer f.mu.Unlock()
+ inited, err := f.initGoSum()
if err != nil || !inited {
return false
}
- for _, goSums := range Fetcher_.sumState.w {
+ for _, goSums := range f.sumState.w {
for _, h := range goSums[mod] {
if !strings.HasPrefix(h, "h1:") {
continue
}
- if !Fetcher_.sumState.status[modSum{mod, h}].dirty {
+ if !f.sumState.status[modSum{mod, h}].dirty {
return true
}
}
}
- for _, h := range Fetcher_.sumState.m[mod] {
+ for _, h := range f.sumState.m[mod] {
if !strings.HasPrefix(h, "h1:") {
continue
}
- if !Fetcher_.sumState.status[modSum{mod, h}].dirty {
+ if !f.sumState.status[modSum{mod, h}].dirty {
return true
}
}
func RecordedSum(mod module.Version) (sum string, ok bool) {
Fetcher_.mu.Lock()
defer Fetcher_.mu.Unlock()
- inited, err := initGoSum()
+ inited, err := Fetcher_.initGoSum()
foundSum := ""
if err != nil || !inited {
return "", false
base.Fatalf("verifying %v", module.VersionError(mod, fmt.Errorf("unexpected ziphash: %q", h)))
}
- if err := checkModSum(mod, h); err != nil {
+ if err := checkModSum(Fetcher_, mod, h); err != nil {
base.Fatalf("%s", err)
}
}
// checkGoMod checks the given module's go.mod checksum;
// data is the go.mod content.
-func checkGoMod(path, version string, data []byte) error {
+func checkGoMod(f *Fetcher, path, version string, data []byte) error {
h, err := goModSum(data)
if err != nil {
return &module.ModuleError{Path: path, Version: version, Err: fmt.Errorf("verifying go.mod: %v", err)}
}
- return checkModSum(module.Version{Path: path, Version: version + "/go.mod"}, h)
+ return checkModSum(f, module.Version{Path: path, Version: version + "/go.mod"}, h)
}
// checkModSum checks that the recorded checksum for mod is h.
//
// mod.Version may have the additional suffix "/go.mod" to request the checksum
// for the module's go.mod file only.
-func checkModSum(mod module.Version, h string) error {
+func checkModSum(f *Fetcher, mod module.Version, h string) error {
// We lock goSum when manipulating it,
// but we arrange to release the lock when calling checkSumDB,
// so that parallel calls to checkModHash can execute parallel calls
// to checkSumDB.
// Check whether mod+h is listed in go.sum already. If so, we're done.
- Fetcher_.mu.Lock()
- inited, err := initGoSum()
+ f.mu.Lock()
+ inited, err := f.initGoSum()
if err != nil {
- Fetcher_.mu.Unlock()
+ f.mu.Unlock()
return err
}
- done := inited && haveModSumLocked(Fetcher_, mod, h)
+ done := inited && haveModSumLocked(f, mod, h)
if inited {
- st := Fetcher_.sumState.status[modSum{mod, h}]
+ st := f.sumState.status[modSum{mod, h}]
st.used = true
- Fetcher_.sumState.status[modSum{mod, h}] = st
+ f.sumState.status[modSum{mod, h}] = st
}
- Fetcher_.mu.Unlock()
+ f.mu.Unlock()
if done {
return nil
// Add mod+h to go.sum, if it hasn't appeared already.
if inited {
- Fetcher_.mu.Lock()
- addModSumLocked(Fetcher_, mod, h)
- st := Fetcher_.sumState.status[modSum{mod, h}]
+ f.mu.Lock()
+ addModSumLocked(f, mod, h)
+ st := f.sumState.status[modSum{mod, h}]
st.dirty = true
- Fetcher_.sumState.status[modSum{mod, h}] = st
- Fetcher_.mu.Unlock()
+ f.sumState.status[modSum{mod, h}] = st
+ f.mu.Unlock()
}
return nil
}
// It should have entries for both module content sums and go.mod sums
// (version ends with "/go.mod"). Existing sums will be preserved unless they
// have been marked for deletion with TrimGoSum.
-func WriteGoSum(ctx context.Context, keep map[module.Version]bool, readonly bool) error {
- Fetcher_.mu.Lock()
- defer Fetcher_.mu.Unlock()
+func (f *Fetcher) WriteGoSum(ctx context.Context, keep map[module.Version]bool, readonly bool) error {
+ f.mu.Lock()
+ defer f.mu.Unlock()
// If we haven't read the go.sum file yet, don't bother writing it.
- if !Fetcher_.sumState.enabled {
+ if !f.sumState.enabled {
return nil
}
// just return without opening go.sum.
dirty := false
Outer:
- for m, hs := range Fetcher_.sumState.m {
+ for m, hs := range f.sumState.m {
for _, h := range hs {
- st := Fetcher_.sumState.status[modSum{m, h}]
+ st := f.sumState.status[modSum{m, h}]
if st.dirty && (!st.used || keep[m]) {
dirty = true
break Outer
if readonly {
return ErrGoSumDirty
}
- if fsys.Replaced(Fetcher_.goSumFile) {
+ if fsys.Replaced(f.goSumFile) {
base.Fatalf("go: updates to go.sum needed, but go.sum is part of the overlay specified with -overlay")
}
defer unlock()
}
- err := lockedfile.Transform(Fetcher_.goSumFile, func(data []byte) ([]byte, error) {
- tidyGoSum := tidyGoSum(Fetcher_, data, keep)
+ err := lockedfile.Transform(f.goSumFile, func(data []byte) ([]byte, error) {
+ tidyGoSum := tidyGoSum(f, data, keep)
return tidyGoSum, nil
})
if err != nil {
return fmt.Errorf("updating go.sum: %w", err)
}
- Fetcher_.sumState.status = make(map[modSum]modSumStatus)
- Fetcher_.sumState.overwrite = false
+ f.sumState.status = make(map[modSum]modSumStatus)
+ f.sumState.overwrite = false
return nil
}
func TrimGoSum(keep map[module.Version]bool) {
Fetcher_.mu.Lock()
defer Fetcher_.mu.Unlock()
- inited, err := initGoSum()
+ inited, err := Fetcher_.initGoSum()
if err != nil {
base.Fatalf("%s", err)
}
//
// A successful return does not guarantee that the module
// has any defined versions.
-func Lookup(ctx context.Context, proxy, path string) Repo {
+func (f *Fetcher) Lookup(ctx context.Context, proxy, path string) Repo {
if traceRepo {
defer logCall("Lookup(%q, %q)", proxy, path)()
}
- return Fetcher_.lookupCache.Do(lookupCacheKey{proxy, path}, func() Repo {
+ return f.lookupCache.Do(lookupCacheKey{proxy, path}, func() Repo {
return newCachingRepo(ctx, path, func(ctx context.Context) (Repo, error) {
- r, err := lookup(ctx, proxy, path)
+ r, err := lookup(f, ctx, proxy, path)
if err == nil && traceRepo {
r = newLoggingRepo(r)
}
}
// lookup returns the module with the given module path.
-func lookup(ctx context.Context, proxy, path string) (r Repo, err error) {
+func lookup(fetcher_ *Fetcher, ctx context.Context, proxy, path string) (r Repo, err error) {
if cfg.BuildMod == "vendor" {
return nil, errLookupDisabled
}
switch path {
case "go", "toolchain":
- return &toolchainRepo{path, Lookup(ctx, proxy, "golang.org/toolchain")}, nil
+ return &toolchainRepo{path, fetcher_.Lookup(ctx, proxy, "golang.org/toolchain")}, nil
}
if module.MatchPrefixPatterns(cfg.GONOPROXY, path) {
if oldRepl := modload.Replacement(loaderstate, old); oldRepl.Path != "" {
oldActual = oldRepl
}
- if mActual == oldActual || mActual.Version == "" || !modfetch.HaveSum(oldActual) {
+ if mActual == oldActual || mActual.Version == "" || !modfetch.HaveSum(modfetch.Fetcher_, oldActual) {
continue
}
r.work.Add(func() {
v, ok = rs.rootSelected(loaderstate, path)
}
if !ok {
- mg, err := rs.Graph(loaderstate, ctx)
+ mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
base.Fatal(err)
}
checksumOk := func(suffix string) bool {
return rs == nil || m.Version == "" || !mustHaveSums(loaderstate) ||
- modfetch.HaveSum(module.Version{Path: m.Path, Version: m.Version + suffix})
+ modfetch.HaveSum(modfetch.Fetcher_, module.Version{Path: m.Path, Version: m.Version + suffix})
}
mod := module.Version{Path: m.Path, Version: m.Version}
if m.GoVersion == "" && checksumOk("/go.mod") {
// Load the go.mod file to determine the Go version, since it hasn't
// already been populated from rawGoVersion.
- if summary, err := rawGoModSummary(loaderstate, mod); err == nil && summary.goVersion != "" {
+ if summary, err := rawGoModSummary(modfetch.Fetcher_, loaderstate, mod); err == nil && summary.goVersion != "" {
m.GoVersion = summary.goVersion
}
}
"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/gover"
+ "cmd/go/internal/modfetch"
"cmd/go/internal/mvs"
"cmd/internal/par"
//
// If the requirements of any relevant module fail to load, Graph also
// returns a non-nil error of type *mvs.BuildListError.
-func (rs *Requirements) Graph(loaderstate *State, ctx context.Context) (*ModuleGraph, error) {
+func (rs *Requirements) Graph(fetcher_ *modfetch.Fetcher, loaderstate *State, ctx context.Context) (*ModuleGraph, error) {
rs.graphOnce.Do(func() {
- mg, mgErr := readModGraph(loaderstate, ctx, rs.pruning, rs.rootModules, nil)
+ mg, mgErr := readModGraph(fetcher_, loaderstate, ctx, rs.pruning, rs.rootModules, nil)
rs.graph.Store(&cachedGraph{mg, mgErr})
})
cached := rs.graph.Load()
//
// Unlike LoadModGraph, readModGraph does not attempt to diagnose or update
// inconsistent roots.
-func readModGraph(loaderstate *State, ctx context.Context, pruning modPruning, roots []module.Version, unprune map[module.Version]bool) (*ModuleGraph, error) {
+func readModGraph(f *modfetch.Fetcher, loaderstate *State, ctx context.Context, pruning modPruning, roots []module.Version, unprune map[module.Version]bool) (*ModuleGraph, error) {
mustHaveGoRoot(roots)
if pruning == pruned {
// Enable diagnostics for lazy module loading
// m's go.mod file indicates that it supports graph pruning.
loadOne := func(m module.Version) (*modFileSummary, error) {
return mg.loadCache.Do(m, func() (*modFileSummary, error) {
- summary, err := goModSummary(loaderstate, m)
+ summary, err := goModSummary(f, loaderstate, m)
mu.Lock()
if err == nil {
rs = newRequirements(loaderstate, unpruned, rs.rootModules, rs.direct)
}
- return rs.Graph(loaderstate, ctx)
+ return rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
}
rs, mg, err := expandGraph(loaderstate, ctx, rs)
// expandGraph returns non-nil requirements and a non-nil graph regardless of
// errors. On error, the roots might not be updated to be consistent.
func expandGraph(loaderstate *State, ctx context.Context, rs *Requirements) (*Requirements, *ModuleGraph, error) {
- mg, mgErr := rs.Graph(loaderstate, ctx)
+ mg, mgErr := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if mgErr != nil {
// Without the graph, we can't update the roots: we don't know which
// versions of transitive dependencies would be selected.
return rs, mg, rsErr
}
rs = newRS
- mg, mgErr = rs.Graph(loaderstate, ctx)
+ mg, mgErr = rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
}
return rs, mg, mgErr
for len(queue) > 0 {
roots = tidy.rootModules
- mg, err := tidy.Graph(loaderstate, ctx)
+ mg, err := tidy.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
return nil, err
}
}
roots = tidy.rootModules
- _, err := tidy.Graph(loaderstate, ctx)
+ _, err := tidy.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
return nil, err
}
if len(roots) > len(tidy.rootModules) {
module.Sort(roots)
tidy = newRequirements(loaderstate, pruned, roots, tidy.direct)
- _, err = tidy.Graph(loaderstate, ctx)
+ _, err = tidy.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
return nil, err
}
rs = newRequirements(loaderstate, pruned, roots, direct)
var err error
- mg, err = rs.Graph(loaderstate, ctx)
+ mg, err = rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
return rs, err
}
// We've already loaded the full module graph, which includes the
// requirements of all of the root modules — even the transitive
// requirements, if they are unpruned!
- mg, _ = rs.Graph(loaderstate, ctx)
+ mg, _ = rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
} else if cfg.BuildMod == "vendor" {
// We can't spot-check the requirements of other modules because we
// don't in general have their go.mod files available in the vendor
// inconsistent in some way; we need to load the full module graph
// so that we can fix the roots properly.
var err error
- mg, err = rs.Graph(loaderstate, ctx)
+ mg, err = rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
return rs, err
}
return
}
- summary, err := goModSummary(loaderstate, m)
+ summary, err := goModSummary(modfetch.Fetcher_, loaderstate, m)
if err != nil {
cancel()
return
// 4. Every version in add is selected at its given version unless upgraded by
// (the dependencies of) an existing root or another module in add.
func updateUnprunedRoots(loaderstate *State, ctx context.Context, direct map[string]bool, rs *Requirements, add []module.Version) (*Requirements, error) {
- mg, err := rs.Graph(loaderstate, ctx)
+ mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
// We can't ignore errors in the module graph even if the user passed the -e
// flag to try to push past them. If we can't load the complete module
// root set! “Include the transitive dependencies of every module in the build
// list” is exactly what happens in a pruned module if we promote every module
// in the build list to a root.
- mg, err := rs.Graph(loaderstate, ctx)
+ mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
return rs, err
}
import (
"cmd/go/internal/cfg"
"cmd/go/internal/gover"
+ "cmd/go/internal/modfetch"
"cmd/go/internal/mvs"
"cmd/internal/par"
"context"
// dependencies, so we need to treat everything in the build list as
// potentially relevant — that is, as what would be a “root” in a module
// with graph pruning enabled.
- mg, err := rs.Graph(loaderstate, ctx)
+ mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
// If we couldn't load the graph, we don't know what its requirements were
// to begin with, so we can't edit those requirements in a coherent way.
// the edit. We want to make sure we consider keeping it as-is,
// even if it wouldn't normally be included. (For example, it might
// be a pseudo-version or pre-release.)
- origMG, _ := orig.Graph(loaderstate, ctx)
+ origMG, _ := orig.Graph(modfetch.Fetcher_, loaderstate, ctx)
origV := origMG.Selected(m.Path)
if conflict.Err != nil && origV == m.Version {
// some root to that version.
func extendGraph(loaderstate *State, ctx context.Context, rootPruning modPruning, roots []module.Version, selectedRoot map[string]string) (mg *ModuleGraph, upgradedRoot map[module.Version]bool, err error) {
for {
- mg, err = readModGraph(loaderstate, ctx, rootPruning, roots, upgradedRoot)
+ mg, err = readModGraph(modfetch.Fetcher_, loaderstate, ctx, rootPruning, roots, upgradedRoot)
// We keep on going even if err is non-nil until we reach a steady state.
// (Note that readModGraph returns a non-nil *ModuleGraph even in case of
// errors.) The caller may be able to fix the errors by adjusting versions,
// of a package in "all", we didn't necessarily load that file
// when we read the module graph, so do it now to be sure.
if !skipModFile && cfg.BuildMod != "vendor" && mods[0].Path != "" && !loaderstate.MainModules.Contains(mods[0].Path) {
- if _, err := goModSummary(loaderstate, mods[0]); err != nil {
+ if _, err := goModSummary(modfetch.Fetcher_, loaderstate, mods[0]); err != nil {
return module.Version{}, "", "", nil, err
}
}
// So far we've checked the root dependencies.
// Load the full module graph and try again.
- mg, err = rs.Graph(loaderstate, ctx)
+ mg, err = rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
// We might be missing one or more transitive (implicit) dependencies from
// the module graph, so we can't return an ImportMissingError here — one
mv = module.ZeroPseudoVersion("v0")
}
}
- mg, err := rs.Graph(loaderstate, ctx)
+ mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
return module.Version{}, err
}
// and return m, dir, ImportMissingError.
fmt.Fprintf(os.Stderr, "go: finding module for package %s\n", path)
- mg, err := rs.Graph(loaderstate, ctx)
+ mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
return module.Version{}, err
}
mod = r
}
- if mustHaveSums(loaderstate) && !modfetch.HaveSum(mod) {
+ if mustHaveSums(loaderstate) && !modfetch.HaveSum(modfetch.Fetcher_, mod) {
return "", false, module.VersionError(mod, &sumMissingError{})
}
if loaderstate.inWorkspaceMode() {
// go.mod files aren't updated in workspace mode, but we still want to
// update the go.work.sum file.
- return modfetch.WriteGoSum(ctx, keepSums(loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate))
+ return modfetch.Fetcher_.WriteGoSum(ctx, keepSums(modfetch.Fetcher_, loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate))
}
_, updatedGoMod, modFile, err := UpdateGoModFromReqs(loaderstate, ctx, opts)
if err != nil {
// Don't write go.mod, but write go.sum in case we added or trimmed sums.
// 'go mod init' shouldn't write go.sum, since it will be incomplete.
if cfg.CmdName != "mod init" {
- if err := modfetch.WriteGoSum(ctx, keepSums(loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate)); err != nil {
+ if err := modfetch.Fetcher_.WriteGoSum(ctx, keepSums(modfetch.Fetcher_, loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate)); err != nil {
return err
}
}
// 'go mod init' shouldn't write go.sum, since it will be incomplete.
if cfg.CmdName != "mod init" {
if err == nil {
- err = modfetch.WriteGoSum(ctx, keepSums(loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate))
+ err = modfetch.Fetcher_.WriteGoSum(ctx, keepSums(modfetch.Fetcher_, loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate))
}
}
}()
// including any go.mod files needed to reconstruct the MVS result
// or identify go versions,
// in addition to the checksums for every module in keepMods.
-func keepSums(loaderstate *State, ctx context.Context, ld *loader, rs *Requirements, which whichSums) map[module.Version]bool {
+func keepSums(fetcher_ *modfetch.Fetcher, loaderstate *State, ctx context.Context, ld *loader, rs *Requirements, which whichSums) map[module.Version]bool {
// Every module in the full module graph contributes its requirements,
// so in order to ensure that the build list itself is reproducible,
// we need sums for every go.mod in the graph (regardless of whether
}
}
- mg, _ := rs.Graph(loaderstate, ctx)
+ mg, _ := rs.Graph(fetcher_, loaderstate, ctx)
for prefix := pkg.path; prefix != "."; prefix = path.Dir(prefix) {
if v := mg.Selected(prefix); v != "none" {
m := module.Version{Path: prefix, Version: v}
}
}
} else {
- mg, _ := rs.Graph(loaderstate, ctx)
+ mg, _ := rs.Graph(fetcher_, loaderstate, ctx)
mg.WalkBreadthFirst(func(m module.Version) {
if _, ok := mg.RequiredBy(m); ok {
// The requirements from m's go.mod file are present in the module graph,
case strings.Contains(m.Pattern(), "..."):
m.Errs = m.Errs[:0]
- mg, err := rs.Graph(loaderstate, ctx)
+ mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
// The module graph is (or may be) incomplete — perhaps we failed to
// load the requirements of some module. This is an error in matching
if opts.Tidy {
if cfg.BuildV {
- mg, _ := ld.requirements.Graph(loaderstate, ctx)
+ mg, _ := ld.requirements.Graph(modfetch.Fetcher_, loaderstate, ctx)
for _, m := range initialRS.rootModules {
var unused bool
if ld.requirements.pruning == unpruned {
}
}
- keep := keepSums(loaderstate, ctx, ld, ld.requirements, loadedZipSumsOnly)
+ keep := keepSums(modfetch.Fetcher_, loaderstate, ctx, ld, ld.requirements, loadedZipSumsOnly)
compatVersion := ld.TidyCompatibleVersion
goVersion := ld.requirements.GoVersion(loaderstate)
if compatVersion == "" {
compatRS := newRequirements(loaderstate, compatPruning, ld.requirements.rootModules, ld.requirements.direct)
ld.checkTidyCompatibility(loaderstate, ctx, compatRS, compatVersion)
- for m := range keepSums(loaderstate, ctx, ld, compatRS, loadedZipSumsOnly) {
+ for m := range keepSums(modfetch.Fetcher_, loaderstate, ctx, ld, compatRS, loadedZipSumsOnly) {
keep[m] = true
}
}
// Dropping compatibility for 1.16 may result in a strictly smaller go.sum.
// Update the keep map with only the loaded.requirements.
if gover.Compare(compatVersion, "1.16") > 0 {
- keep = keepSums(loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums)
+ keep = keepSums(modfetch.Fetcher_, loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums)
}
currentGoSum, tidyGoSum := modfetch.TidyGoSum(keep)
goSumDiff := diff.Diff("current/go.sum", currentGoSum, "tidy/go.sum", tidyGoSum)
// loaded.requirements, but here we may have also loaded (and want to
// preserve checksums for) additional entities from compatRS, which are
// only needed for compatibility with ld.TidyCompatibleVersion.
- if err := modfetch.WriteGoSum(ctx, keep, mustHaveCompleteRequirements(loaderstate)); err != nil {
+ if err := modfetch.Fetcher_.WriteGoSum(ctx, keep, mustHaveCompleteRequirements(loaderstate)); err != nil {
base.Fatal(err)
}
}
// versions of root modules may differ from what we already checked above.
// Re-check those paths too.
- mg, _ := rs.Graph(loaderstate, ctx)
+ mg, _ := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
var importPath string
for _, m := range mg.BuildList() {
var found bool
// pruning and semantics all along, but there may have been — and may
// still be — requirements on higher versions in the graph.
tidy := overrideRoots(loaderstate, ctx, rs, []module.Version{{Path: "go", Version: ld.TidyGoVersion}})
- mg, err := tidy.Graph(loaderstate, ctx)
+ mg, err := tidy.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
ld.error(err)
}
// of the vendor directory anyway.
continue
}
- if mg, err := rs.Graph(loaderstate, ctx); err != nil {
+ if mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx); err != nil {
return false, err
} else if _, ok := mg.RequiredBy(dep.mod); !ok {
// dep.mod is not an explicit dependency, but needs to be.
// The roots of the module graph have changed in some way (not just the
// "direct" markings). Check whether the changes affected any of the loaded
// packages.
- mg, err := rs.Graph(loaderstate, ctx)
+ mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
return false, err
}
var mg *ModuleGraph
if ld.requirements.pruning == unpruned {
var err error
- mg, err = ld.requirements.Graph(loaderstate, ctx)
+ mg, err = ld.requirements.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
// We already checked the error from Graph in loadFromRoots and/or
// updateRequirements, so we ignored the error on purpose and we should
fmt.Fprintf(os.Stderr, "For information about 'go mod tidy' compatibility, see:\n\thttps://go.dev/ref/mod#graph-pruning\n")
}
- mg, err := rs.Graph(loaderstate, ctx)
+ mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
if err != nil {
ld.error(fmt.Errorf("error loading go %s module graph: %w", compatVersion, err))
ld.switchIfErrors(ctx)
if err != nil {
return err
}
- summary, err := rawGoModSummary(s, rm)
+ summary, err := rawGoModSummary(modfetch.Fetcher_, s, rm)
if err != nil && !errors.Is(err, gover.ErrTooNew) {
return err
}
if err != nil {
return "", err
}
- summary, err := rawGoModSummary(loaderstate, latest)
+ summary, err := rawGoModSummary(modfetch.Fetcher_, loaderstate, latest)
if err != nil && !errors.Is(err, gover.ErrTooNew) {
return "", err
}
// module versions.
//
// The caller must not modify the returned summary.
-func goModSummary(loaderstate *State, m module.Version) (*modFileSummary, error) {
+func goModSummary(fetcher_ *modfetch.Fetcher, loaderstate *State, m module.Version) (*modFileSummary, error) {
if m.Version == "" && !loaderstate.inWorkspaceMode() && loaderstate.MainModules.Contains(m.Path) {
panic("internal error: goModSummary called on a main module")
}
if gover.IsToolchain(m.Path) {
- return rawGoModSummary(loaderstate, m)
+ return rawGoModSummary(fetcher_, loaderstate, m)
}
if cfg.BuildMod == "vendor" {
actual := resolveReplacement(loaderstate, m)
if mustHaveSums(loaderstate) && actual.Version != "" {
key := module.Version{Path: actual.Path, Version: actual.Version + "/go.mod"}
- if !modfetch.HaveSum(key) {
+ if !modfetch.HaveSum(fetcher_, key) {
suggestion := fmt.Sprintf(" for go.mod file; to add it:\n\tgo mod download %s", m.Path)
return nil, module.VersionError(actual, &sumMissingError{suggestion: suggestion})
}
}
- summary, err := rawGoModSummary(loaderstate, actual)
+ summary, err := rawGoModSummary(fetcher_, loaderstate, actual)
if err != nil {
return nil, err
}
// rawGoModSummary cannot be used on the main module outside of workspace mode.
// The modFileSummary can still be used for retractions and deprecations
// even if a TooNewError is returned.
-func rawGoModSummary(loaderstate *State, m module.Version) (*modFileSummary, error) {
+func rawGoModSummary(fetcher_ *modfetch.Fetcher, loaderstate *State, m module.Version) (*modFileSummary, error) {
if gover.IsToolchain(m.Path) {
if m.Path == "go" && gover.Compare(m.Version, gover.GoStrictVersion) >= 0 {
// Declare that go 1.21.3 requires toolchain 1.21.3,
}
}
return rawGoModSummaryCache.Do(m, func() (*modFileSummary, error) {
- name, data, err := rawGoModData(loaderstate, m)
+ name, data, err := rawGoModData(fetcher_, loaderstate, m)
if err != nil {
return nil, err
}
//
// Unlike rawGoModSummary, rawGoModData does not cache its results in memory.
// Use rawGoModSummary instead unless you specifically need these bytes.
-func rawGoModData(loaderstate *State, m module.Version) (name string, data []byte, err error) {
+func rawGoModData(fetcher_ *modfetch.Fetcher, loaderstate *State, m module.Version) (name string, data []byte, err error) {
if m.Version == "" {
dir := m.Path
if !filepath.IsAbs(dir) {
base.Fatalf("go: internal error: %s@%s: unexpected invalid semantic version", m.Path, m.Version)
}
name = "go.mod"
- data, err = modfetch.GoMod(context.TODO(), m.Path, m.Version)
+ data, err = fetcher_.GoMod(context.TODO(), m.Path, m.Version)
}
return name, data, err
}
return nil, nil
}
- summary, err := goModSummary(r.loaderstate, mod)
+ summary, err := goModSummary(modfetch.Fetcher_, r.loaderstate, mod)
if err != nil {
return nil, err
}
// we don't need to verify it in go.sum. This makes 'go list -m -u' faster
// and simpler.
func versionHasGoMod(loaderstate *State, _ context.Context, m module.Version) (bool, error) {
- _, data, err := rawGoModData(loaderstate, m)
+ _, data, err := rawGoModData(modfetch.Fetcher_, loaderstate, m)
if err != nil {
return false, err
}
err = module.CheckPath(path)
}
if err == nil {
- repo = modfetch.Lookup(ctx, proxy, path)
+ repo = modfetch.Fetcher_.Lookup(ctx, proxy, path)
} else {
repo = emptyRepo{path: path, err: err}
}
"cmd/go/internal/fsys"
"cmd/go/internal/gover"
"cmd/go/internal/imports"
+ "cmd/go/internal/modfetch"
"cmd/go/internal/modindex"
"cmd/go/internal/search"
"cmd/go/internal/str"
if err != nil {
continue
}
- summary, err := goModSummary(loaderstate, mod)
+ summary, err := goModSummary(modfetch.Fetcher_, loaderstate, mod)
if err != nil {
continue
}
func autoToolchains(ctx context.Context) ([]string, error) {
var versions *modfetch.Versions
err := modfetch.TryProxies(func(proxy string) error {
- v, err := modfetch.Lookup(ctx, proxy, "go").Versions(ctx, "")
+ v, err := modfetch.Fetcher_.Lookup(ctx, proxy, "go").Versions(ctx, "")
if err != nil {
return err
}