mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: remove final references to modfetch.Fetcher_
This commit removes the final references to the global Fetcher_ variable from the modfetch and modload packages. This completes the removal of global state from the modfetch package. Change-Id: Ibb5309acdc7d05f1a7591ddcf890b44b6cc4cb2f Reviewed-on: https://go-review.googlesource.com/c/go/+/724249 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
08bf23cb97
commit
4976606a2f
9 changed files with 67 additions and 69 deletions
|
|
@ -2050,7 +2050,7 @@ func (p *Package) load(loaderstate *modload.State, ctx context.Context, opts Pac
|
||||||
// Consider starting this as a background goroutine and retrieving the result
|
// Consider starting this as a background goroutine and retrieving the result
|
||||||
// asynchronously when we're actually ready to build the package, or when we
|
// asynchronously when we're actually ready to build the package, or when we
|
||||||
// actually need to evaluate whether the package's metadata is stale.
|
// actually need to evaluate whether the package's metadata is stale.
|
||||||
p.setBuildInfo(ctx, opts.AutoVCS)
|
p.setBuildInfo(ctx, loaderstate.Fetcher(), opts.AutoVCS)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If cgo is not enabled, ignore cgo supporting sources
|
// If cgo is not enabled, ignore cgo supporting sources
|
||||||
|
|
@ -2323,7 +2323,7 @@ func appendBuildSetting(info *debug.BuildInfo, key, value string) {
|
||||||
//
|
//
|
||||||
// Note that the GoVersion field is not set here to avoid encoding it twice.
|
// Note that the GoVersion field is not set here to avoid encoding it twice.
|
||||||
// It is stored separately in the binary, mostly for historical reasons.
|
// It is stored separately in the binary, mostly for historical reasons.
|
||||||
func (p *Package) setBuildInfo(ctx context.Context, autoVCS bool) {
|
func (p *Package) setBuildInfo(ctx context.Context, f *modfetch.Fetcher, autoVCS bool) {
|
||||||
setPkgErrorf := func(format string, args ...any) {
|
setPkgErrorf := func(format string, args ...any) {
|
||||||
if p.Error == nil {
|
if p.Error == nil {
|
||||||
p.Error = &PackageError{Err: fmt.Errorf(format, args...)}
|
p.Error = &PackageError{Err: fmt.Errorf(format, args...)}
|
||||||
|
|
@ -2595,7 +2595,7 @@ func (p *Package) setBuildInfo(ctx context.Context, autoVCS bool) {
|
||||||
if !ok {
|
if !ok {
|
||||||
goto omitVCS
|
goto omitVCS
|
||||||
}
|
}
|
||||||
repo := modfetch.LookupLocal(ctx, codeRoot, p.Module.Path, repoDir)
|
repo := f.LookupLocal(ctx, codeRoot, p.Module.Path, repoDir)
|
||||||
revInfo, err := repo.Stat(ctx, st.Revision)
|
revInfo, err := repo.Stat(ctx, st.Revision)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
goto omitVCS
|
goto omitVCS
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@ func TestPackagesAndErrors(loaderstate *modload.State, ctx context.Context, done
|
||||||
// pmain won't have buildinfo set (since we copy it from the package under test). If the default GODEBUG
|
// pmain won't have buildinfo set (since we copy it from the package under test). If the default GODEBUG
|
||||||
// used for the package under test is different from that of the test main, the BuildInfo assigned above from the package
|
// used for the package under test is different from that of the test main, the BuildInfo assigned above from the package
|
||||||
// under test incorrect for the test main package. Either set or correct pmain's build info.
|
// under test incorrect for the test main package. Either set or correct pmain's build info.
|
||||||
pmain.setBuildInfo(ctx, opts.AutoVCS)
|
pmain.setBuildInfo(ctx, loaderstate.Fetcher(), opts.AutoVCS)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The generated main also imports testing, regexp, and os.
|
// The generated main also imports testing, regexp, and os.
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ func lockVersion(ctx context.Context, mod module.Version) (unlock func(), err er
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil {
|
if err := os.MkdirAll(filepath.Dir(path), 0o777); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return lockedfile.MutexAt(path).Lock()
|
return lockedfile.MutexAt(path).Lock()
|
||||||
|
|
@ -172,7 +172,7 @@ func SideLock(ctx context.Context) (unlock func(), err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
path := filepath.Join(cfg.GOMODCACHE, "cache", "lock")
|
path := filepath.Join(cfg.GOMODCACHE, "cache", "lock")
|
||||||
if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil {
|
if err := os.MkdirAll(filepath.Dir(path), 0o777); err != nil {
|
||||||
return nil, fmt.Errorf("failed to create cache directory: %w", err)
|
return nil, fmt.Errorf("failed to create cache directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,12 +194,14 @@ type cachingRepo struct {
|
||||||
once sync.Once
|
once sync.Once
|
||||||
initRepo func(context.Context) (Repo, error)
|
initRepo func(context.Context) (Repo, error)
|
||||||
r Repo
|
r Repo
|
||||||
|
fetcher *Fetcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCachingRepo(ctx context.Context, path string, initRepo func(context.Context) (Repo, error)) *cachingRepo {
|
func newCachingRepo(ctx context.Context, fetcher *Fetcher, path string, initRepo func(context.Context) (Repo, error)) *cachingRepo {
|
||||||
return &cachingRepo{
|
return &cachingRepo{
|
||||||
path: path,
|
path: path,
|
||||||
initRepo: initRepo,
|
initRepo: initRepo,
|
||||||
|
fetcher: fetcher,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,7 +228,6 @@ func (r *cachingRepo) Versions(ctx context.Context, prefix string) (*Versions, e
|
||||||
v, err := r.versionsCache.Do(prefix, func() (*Versions, error) {
|
v, err := r.versionsCache.Do(prefix, func() (*Versions, error) {
|
||||||
return r.repo(ctx).Versions(ctx, prefix)
|
return r.repo(ctx).Versions(ctx, prefix)
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -309,7 +310,7 @@ func (r *cachingRepo) GoMod(ctx context.Context, version string) ([]byte, error)
|
||||||
return r.repo(ctx).GoMod(ctx, version)
|
return r.repo(ctx).GoMod(ctx, version)
|
||||||
}
|
}
|
||||||
text, err := r.gomodCache.Do(version, func() ([]byte, error) {
|
text, err := r.gomodCache.Do(version, func() ([]byte, error) {
|
||||||
file, text, err := Fetcher_.readDiskGoMod(ctx, r.path, version)
|
file, text, err := r.fetcher.readDiskGoMod(ctx, r.path, version)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Note: readDiskGoMod already called checkGoMod.
|
// Note: readDiskGoMod already called checkGoMod.
|
||||||
return text, nil
|
return text, nil
|
||||||
|
|
@ -317,7 +318,7 @@ func (r *cachingRepo) GoMod(ctx context.Context, version string) ([]byte, error)
|
||||||
|
|
||||||
text, err = r.repo(ctx).GoMod(ctx, version)
|
text, err = r.repo(ctx).GoMod(ctx, version)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err := checkGoMod(Fetcher_, r.path, version, text); err != nil {
|
if err := checkGoMod(r.fetcher, r.path, version, text); err != nil {
|
||||||
return text, err
|
return text, err
|
||||||
}
|
}
|
||||||
if err := writeDiskGoMod(ctx, file, text); err != nil {
|
if err := writeDiskGoMod(ctx, file, text); err != nil {
|
||||||
|
|
@ -653,13 +654,13 @@ func writeDiskCache(ctx context.Context, file string, data []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Make sure directory for file exists.
|
// Make sure directory for file exists.
|
||||||
if err := os.MkdirAll(filepath.Dir(file), 0777); err != nil {
|
if err := os.MkdirAll(filepath.Dir(file), 0o777); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the file to a temporary location, and then rename it to its final
|
// Write the file to a temporary location, and then rename it to its final
|
||||||
// path to reduce the likelihood of a corrupt file existing at that final path.
|
// path to reduce the likelihood of a corrupt file existing at that final path.
|
||||||
f, err := tempFile(ctx, filepath.Dir(file), filepath.Base(file), 0666)
|
f, err := tempFile(ctx, filepath.Dir(file), filepath.Base(file), 0o666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -812,7 +813,7 @@ func checkCacheDir(ctx context.Context) error {
|
||||||
statCacheErr = fmt.Errorf("could not create module cache: %w", err)
|
statCacheErr = fmt.Errorf("could not create module cache: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(cfg.GOMODCACHE, 0777); err != nil {
|
if err := os.MkdirAll(cfg.GOMODCACHE, 0o777); err != nil {
|
||||||
statCacheErr = fmt.Errorf("could not create module cache: %w", err)
|
statCacheErr = fmt.Errorf("could not create module cache: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMain(m *testing.M) (err error) {
|
func testMain(m *testing.M) (err error) {
|
||||||
|
|
||||||
cfg.GOPROXY = "direct"
|
cfg.GOPROXY = "direct"
|
||||||
|
|
||||||
// The sum database is populated using a released version of the go command,
|
// The sum database is populated using a released version of the go command,
|
||||||
|
|
@ -56,7 +55,7 @@ func testMain(m *testing.M) (err error) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
cfg.GOMODCACHE = filepath.Join(dir, "modcache")
|
cfg.GOMODCACHE = filepath.Join(dir, "modcache")
|
||||||
if err := os.Mkdir(cfg.GOMODCACHE, 0755); err != nil {
|
if err := os.Mkdir(cfg.GOMODCACHE, 0o755); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -589,6 +588,7 @@ var codeRepoTests = []codeRepoTest{
|
||||||
func TestCodeRepo(t *testing.T) {
|
func TestCodeRepo(t *testing.T) {
|
||||||
testenv.MustHaveExternalNetwork(t)
|
testenv.MustHaveExternalNetwork(t)
|
||||||
tmpdir := t.TempDir()
|
tmpdir := t.TempDir()
|
||||||
|
fetcher := NewFetcher()
|
||||||
|
|
||||||
for _, tt := range codeRepoTests {
|
for _, tt := range codeRepoTests {
|
||||||
f := func(tt codeRepoTest) func(t *testing.T) {
|
f := func(tt codeRepoTest) func(t *testing.T) {
|
||||||
|
|
@ -603,7 +603,7 @@ func TestCodeRepo(t *testing.T) {
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
repo := Fetcher_.Lookup(ctx, "direct", tt.path)
|
repo := fetcher.Lookup(ctx, "direct", tt.path)
|
||||||
|
|
||||||
if tt.mpath == "" {
|
if tt.mpath == "" {
|
||||||
tt.mpath = tt.path
|
tt.mpath = tt.path
|
||||||
|
|
@ -817,7 +817,7 @@ var codeRepoVersionsTests = []struct {
|
||||||
|
|
||||||
func TestCodeRepoVersions(t *testing.T) {
|
func TestCodeRepoVersions(t *testing.T) {
|
||||||
testenv.MustHaveExternalNetwork(t)
|
testenv.MustHaveExternalNetwork(t)
|
||||||
|
fetcher := NewFetcher()
|
||||||
for _, tt := range codeRepoVersionsTests {
|
for _, tt := range codeRepoVersionsTests {
|
||||||
tt := tt
|
tt := tt
|
||||||
t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) {
|
t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) {
|
||||||
|
|
@ -831,7 +831,7 @@ func TestCodeRepoVersions(t *testing.T) {
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
repo := Fetcher_.Lookup(ctx, "direct", tt.path)
|
repo := fetcher.Lookup(ctx, "direct", tt.path)
|
||||||
list, err := repo.Versions(ctx, tt.prefix)
|
list, err := repo.Versions(ctx, tt.prefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Versions(%q): %v", tt.prefix, err)
|
t.Fatalf("Versions(%q): %v", tt.prefix, err)
|
||||||
|
|
@ -898,7 +898,7 @@ var latestTests = []struct {
|
||||||
|
|
||||||
func TestLatest(t *testing.T) {
|
func TestLatest(t *testing.T) {
|
||||||
testenv.MustHaveExternalNetwork(t)
|
testenv.MustHaveExternalNetwork(t)
|
||||||
|
fetcher := NewFetcher()
|
||||||
for _, tt := range latestTests {
|
for _, tt := range latestTests {
|
||||||
name := strings.ReplaceAll(tt.path, "/", "_")
|
name := strings.ReplaceAll(tt.path, "/", "_")
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
|
@ -909,7 +909,7 @@ func TestLatest(t *testing.T) {
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
repo := Fetcher_.Lookup(ctx, "direct", tt.path)
|
repo := fetcher.Lookup(ctx, "direct", tt.path)
|
||||||
info, err := repo.Latest(ctx)
|
info, err := repo.Latest(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if tt.err != "" {
|
if tt.err != "" {
|
||||||
|
|
|
||||||
|
|
@ -475,8 +475,6 @@ type Fetcher struct {
|
||||||
sumState sumState
|
sumState sumState
|
||||||
}
|
}
|
||||||
|
|
||||||
var Fetcher_ *Fetcher = NewFetcher()
|
|
||||||
|
|
||||||
func NewFetcher() *Fetcher {
|
func NewFetcher() *Fetcher {
|
||||||
f := new(Fetcher)
|
f := new(Fetcher)
|
||||||
f.lookupCache = new(par.Cache[lookupCacheKey, Repo])
|
f.lookupCache = new(par.Cache[lookupCacheKey, Repo])
|
||||||
|
|
@ -498,15 +496,15 @@ func (f *Fetcher) AddWorkspaceGoSumFile(file string) {
|
||||||
|
|
||||||
// Reset resets globals in the modfetch package, so previous loads don't affect
|
// Reset resets globals in the modfetch package, so previous loads don't affect
|
||||||
// contents of go.sum files.
|
// contents of go.sum files.
|
||||||
func Reset() {
|
func (f *Fetcher) Reset() {
|
||||||
SetState(NewFetcher())
|
f.SetState(NewFetcher())
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetState sets the global state of the modfetch package to the newState, and returns the previous
|
// SetState sets the global state of the modfetch package to the newState, and returns the previous
|
||||||
// global state. newState should have been returned by SetState, or be an empty State.
|
// global state. newState should have been returned by SetState, or be an empty State.
|
||||||
// There should be no concurrent calls to any of the exported functions of this package with
|
// There should be no concurrent calls to any of the exported functions of this package with
|
||||||
// a call to SetState because it will modify the global state in a non-thread-safe way.
|
// a call to SetState because it will modify the global state in a non-thread-safe way.
|
||||||
func SetState(newState *Fetcher) (oldState *Fetcher) {
|
func (f *Fetcher) SetState(newState *Fetcher) (oldState *Fetcher) {
|
||||||
if newState.lookupCache == nil {
|
if newState.lookupCache == nil {
|
||||||
newState.lookupCache = new(par.Cache[lookupCacheKey, Repo])
|
newState.lookupCache = new(par.Cache[lookupCacheKey, Repo])
|
||||||
}
|
}
|
||||||
|
|
@ -514,26 +512,26 @@ func SetState(newState *Fetcher) (oldState *Fetcher) {
|
||||||
newState.downloadCache = new(par.ErrCache[module.Version, string])
|
newState.downloadCache = new(par.ErrCache[module.Version, string])
|
||||||
}
|
}
|
||||||
|
|
||||||
Fetcher_.mu.Lock()
|
f.mu.Lock()
|
||||||
defer Fetcher_.mu.Unlock()
|
defer f.mu.Unlock()
|
||||||
|
|
||||||
oldState = &Fetcher{
|
oldState = &Fetcher{
|
||||||
goSumFile: Fetcher_.goSumFile,
|
goSumFile: f.goSumFile,
|
||||||
workspaceGoSumFiles: Fetcher_.workspaceGoSumFiles,
|
workspaceGoSumFiles: f.workspaceGoSumFiles,
|
||||||
lookupCache: Fetcher_.lookupCache,
|
lookupCache: f.lookupCache,
|
||||||
downloadCache: Fetcher_.downloadCache,
|
downloadCache: f.downloadCache,
|
||||||
sumState: Fetcher_.sumState,
|
sumState: f.sumState,
|
||||||
}
|
}
|
||||||
|
|
||||||
Fetcher_.SetGoSumFile(newState.goSumFile)
|
f.SetGoSumFile(newState.goSumFile)
|
||||||
Fetcher_.workspaceGoSumFiles = newState.workspaceGoSumFiles
|
f.workspaceGoSumFiles = newState.workspaceGoSumFiles
|
||||||
// Uses of lookupCache and downloadCache both can call checkModSum,
|
// Uses of lookupCache and downloadCache both can call checkModSum,
|
||||||
// which in turn sets the used bit on goSum.status for modules.
|
// which in turn sets the used bit on goSum.status for modules.
|
||||||
// Set (or reset) them so used can be computed properly.
|
// Set (or reset) them so used can be computed properly.
|
||||||
Fetcher_.lookupCache = newState.lookupCache
|
f.lookupCache = newState.lookupCache
|
||||||
Fetcher_.downloadCache = newState.downloadCache
|
f.downloadCache = newState.downloadCache
|
||||||
// Set, or reset all fields on goSum. If being reset to empty, it will be initialized later.
|
// Set, or reset all fields on goSum. If being reset to empty, it will be initialized later.
|
||||||
Fetcher_.sumState = newState.sumState
|
f.sumState = newState.sumState
|
||||||
|
|
||||||
return oldState
|
return oldState
|
||||||
}
|
}
|
||||||
|
|
@ -666,20 +664,20 @@ func HaveSum(f *Fetcher, mod module.Version) bool {
|
||||||
// The entry's hash must be generated with a known hash algorithm.
|
// 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.Version may have a "/go.mod" suffix to distinguish sums for
|
||||||
// .mod and .zip files.
|
// .mod and .zip files.
|
||||||
func RecordedSum(mod module.Version) (sum string, ok bool) {
|
func (f *Fetcher) RecordedSum(mod module.Version) (sum string, ok bool) {
|
||||||
Fetcher_.mu.Lock()
|
f.mu.Lock()
|
||||||
defer Fetcher_.mu.Unlock()
|
defer f.mu.Unlock()
|
||||||
inited, err := Fetcher_.initGoSum()
|
inited, err := f.initGoSum()
|
||||||
foundSum := ""
|
foundSum := ""
|
||||||
if err != nil || !inited {
|
if err != nil || !inited {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
for _, goSums := range Fetcher_.sumState.w {
|
for _, goSums := range f.sumState.w {
|
||||||
for _, h := range goSums[mod] {
|
for _, h := range goSums[mod] {
|
||||||
if !strings.HasPrefix(h, "h1:") {
|
if !strings.HasPrefix(h, "h1:") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !Fetcher_.sumState.status[modSum{mod, h}].dirty {
|
if !f.sumState.status[modSum{mod, h}].dirty {
|
||||||
if foundSum != "" && foundSum != h { // conflicting sums exist
|
if foundSum != "" && foundSum != h { // conflicting sums exist
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
@ -687,11 +685,11 @@ func RecordedSum(mod module.Version) (sum string, ok bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, h := range Fetcher_.sumState.m[mod] {
|
for _, h := range f.sumState.m[mod] {
|
||||||
if !strings.HasPrefix(h, "h1:") {
|
if !strings.HasPrefix(h, "h1:") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !Fetcher_.sumState.status[modSum{mod, h}].dirty {
|
if !f.sumState.status[modSum{mod, h}].dirty {
|
||||||
if foundSum != "" && foundSum != h { // conflicting sums exist
|
if foundSum != "" && foundSum != h { // conflicting sums exist
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
@ -977,14 +975,14 @@ Outer:
|
||||||
|
|
||||||
// TidyGoSum returns a tidy version of the go.sum file.
|
// TidyGoSum returns a tidy version of the go.sum file.
|
||||||
// A missing go.sum file is treated as if empty.
|
// A missing go.sum file is treated as if empty.
|
||||||
func TidyGoSum(keep map[module.Version]bool) (before, after []byte) {
|
func (f *Fetcher) TidyGoSum(keep map[module.Version]bool) (before, after []byte) {
|
||||||
Fetcher_.mu.Lock()
|
f.mu.Lock()
|
||||||
defer Fetcher_.mu.Unlock()
|
defer f.mu.Unlock()
|
||||||
before, err := lockedfile.Read(Fetcher_.goSumFile)
|
before, err := lockedfile.Read(f.goSumFile)
|
||||||
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||||
base.Fatalf("reading go.sum: %v", err)
|
base.Fatalf("reading go.sum: %v", err)
|
||||||
}
|
}
|
||||||
after = tidyGoSum(Fetcher_, before, keep)
|
after = tidyGoSum(f, before, keep)
|
||||||
return before, after
|
return before, after
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1041,10 +1039,10 @@ func sumInWorkspaceModulesLocked(f *Fetcher, m module.Version) bool {
|
||||||
// keep is used to check whether a sum should be retained in go.mod. It should
|
// keep is used to check whether a sum should be retained in go.mod. It should
|
||||||
// have entries for both module content sums and go.mod sums (version ends
|
// have entries for both module content sums and go.mod sums (version ends
|
||||||
// with "/go.mod").
|
// with "/go.mod").
|
||||||
func TrimGoSum(keep map[module.Version]bool) {
|
func (f *Fetcher) TrimGoSum(keep map[module.Version]bool) {
|
||||||
Fetcher_.mu.Lock()
|
f.mu.Lock()
|
||||||
defer Fetcher_.mu.Unlock()
|
defer f.mu.Unlock()
|
||||||
inited, err := Fetcher_.initGoSum()
|
inited, err := f.initGoSum()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
base.Fatalf("%s", err)
|
base.Fatalf("%s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -1052,12 +1050,12 @@ func TrimGoSum(keep map[module.Version]bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for m, hs := range Fetcher_.sumState.m {
|
for m, hs := range f.sumState.m {
|
||||||
if !keep[m] {
|
if !keep[m] {
|
||||||
for _, h := range hs {
|
for _, h := range hs {
|
||||||
Fetcher_.sumState.status[modSum{m, h}] = modSumStatus{used: false, dirty: true}
|
f.sumState.status[modSum{m, h}] = modSumStatus{used: false, dirty: true}
|
||||||
}
|
}
|
||||||
Fetcher_.sumState.overwrite = true
|
f.sumState.overwrite = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ func (f *Fetcher) Lookup(ctx context.Context, proxy, path string) Repo {
|
||||||
}
|
}
|
||||||
|
|
||||||
return f.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) {
|
return newCachingRepo(ctx, f, path, func(ctx context.Context) (Repo, error) {
|
||||||
r, err := lookup(f, ctx, proxy, path)
|
r, err := lookup(f, ctx, proxy, path)
|
||||||
if err == nil && traceRepo {
|
if err == nil && traceRepo {
|
||||||
r = newLoggingRepo(r)
|
r = newLoggingRepo(r)
|
||||||
|
|
@ -223,13 +223,13 @@ var lookupLocalCache = new(par.Cache[string, Repo]) // path, Repo
|
||||||
// codeRoot is the module path of the root module in the repository.
|
// codeRoot is the module path of the root module in the repository.
|
||||||
// path is the module path of the module being looked up.
|
// path is the module path of the module being looked up.
|
||||||
// dir is the file system path of the repository containing the module.
|
// dir is the file system path of the repository containing the module.
|
||||||
func LookupLocal(ctx context.Context, codeRoot string, path string, dir string) Repo {
|
func (f *Fetcher) LookupLocal(ctx context.Context, codeRoot string, path string, dir string) Repo {
|
||||||
if traceRepo {
|
if traceRepo {
|
||||||
defer logCall("LookupLocal(%q)", path)()
|
defer logCall("LookupLocal(%q)", path)()
|
||||||
}
|
}
|
||||||
|
|
||||||
return lookupLocalCache.Do(path, func() Repo {
|
return lookupLocalCache.Do(path, func() Repo {
|
||||||
return newCachingRepo(ctx, path, func(ctx context.Context) (Repo, error) {
|
return newCachingRepo(ctx, f, path, func(ctx context.Context) (Repo, error) {
|
||||||
repoDir, vcsCmd, err := vcs.FromDir(dir, "")
|
repoDir, vcsCmd, err := vcs.FromDir(dir, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -368,7 +368,7 @@ func moduleInfo(loaderstate *State, ctx context.Context, rs *Requirements, m mod
|
||||||
m.GoMod = gomod
|
m.GoMod = gomod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gomodsum, ok := modfetch.RecordedSum(modkey(mod)); ok {
|
if gomodsum, ok := loaderstate.fetcher.RecordedSum(modkey(mod)); ok {
|
||||||
m.GoModSum = gomodsum
|
m.GoModSum = gomodsum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -377,7 +377,7 @@ func moduleInfo(loaderstate *State, ctx context.Context, rs *Requirements, m mod
|
||||||
if err == nil {
|
if err == nil {
|
||||||
m.Dir = dir
|
m.Dir = dir
|
||||||
}
|
}
|
||||||
if sum, ok := modfetch.RecordedSum(mod); ok {
|
if sum, ok := loaderstate.fetcher.RecordedSum(mod); ok {
|
||||||
m.Sum = sum
|
m.Sum = sum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func EnterModule(loaderstate *State, ctx context.Context, enterModroot string) {
|
||||||
loaderstate.MainModules = nil // reset MainModules
|
loaderstate.MainModules = nil // reset MainModules
|
||||||
loaderstate.requirements = nil
|
loaderstate.requirements = nil
|
||||||
loaderstate.workFilePath = "" // Force module mode
|
loaderstate.workFilePath = "" // Force module mode
|
||||||
modfetch.Reset()
|
loaderstate.Fetcher().Reset()
|
||||||
|
|
||||||
loaderstate.modRoots = []string{enterModroot}
|
loaderstate.modRoots = []string{enterModroot}
|
||||||
LoadModFile(loaderstate, ctx)
|
LoadModFile(loaderstate, ctx)
|
||||||
|
|
@ -411,8 +411,7 @@ func (s *State) setState(new *State) (old *State) {
|
||||||
// The modfetch package's global state is used to compute
|
// The modfetch package's global state is used to compute
|
||||||
// the go.sum file, so save and restore it along with the
|
// the go.sum file, so save and restore it along with the
|
||||||
// modload state.
|
// modload state.
|
||||||
s.fetcher = new.fetcher
|
old.fetcher = s.fetcher.SetState(new.fetcher)
|
||||||
old.fetcher = modfetch.SetState(s.fetcher) // TODO(jitsu): remove after completing global state elimination
|
|
||||||
|
|
||||||
return old
|
return old
|
||||||
}
|
}
|
||||||
|
|
@ -457,7 +456,7 @@ type State struct {
|
||||||
|
|
||||||
func NewState() *State {
|
func NewState() *State {
|
||||||
s := new(State)
|
s := new(State)
|
||||||
s.fetcher = modfetch.Fetcher_
|
s.fetcher = modfetch.NewFetcher()
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -462,13 +462,13 @@ func LoadPackages(loaderstate *State, ctx context.Context, opts PackageOpts, pat
|
||||||
}
|
}
|
||||||
goModDiff := diff.Diff("current/go.mod", currentGoMod, "tidy/go.mod", updatedGoMod)
|
goModDiff := diff.Diff("current/go.mod", currentGoMod, "tidy/go.mod", updatedGoMod)
|
||||||
|
|
||||||
modfetch.TrimGoSum(keep)
|
loaderstate.Fetcher().TrimGoSum(keep)
|
||||||
// Dropping compatibility for 1.16 may result in a strictly smaller go.sum.
|
// Dropping compatibility for 1.16 may result in a strictly smaller go.sum.
|
||||||
// Update the keep map with only the loaded.requirements.
|
// Update the keep map with only the loaded.requirements.
|
||||||
if gover.Compare(compatVersion, "1.16") > 0 {
|
if gover.Compare(compatVersion, "1.16") > 0 {
|
||||||
keep = keepSums(loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums)
|
keep = keepSums(loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums)
|
||||||
}
|
}
|
||||||
currentGoSum, tidyGoSum := modfetch.TidyGoSum(keep)
|
currentGoSum, tidyGoSum := loaderstate.fetcher.TidyGoSum(keep)
|
||||||
goSumDiff := diff.Diff("current/go.sum", currentGoSum, "tidy/go.sum", tidyGoSum)
|
goSumDiff := diff.Diff("current/go.sum", currentGoSum, "tidy/go.sum", tidyGoSum)
|
||||||
|
|
||||||
if len(goModDiff) > 0 {
|
if len(goModDiff) > 0 {
|
||||||
|
|
@ -483,7 +483,7 @@ func LoadPackages(loaderstate *State, ctx context.Context, opts PackageOpts, pat
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ExplicitWriteGoMod {
|
if !ExplicitWriteGoMod {
|
||||||
modfetch.TrimGoSum(keep)
|
loaderstate.Fetcher().TrimGoSum(keep)
|
||||||
|
|
||||||
// commitRequirements below will also call WriteGoSum, but the "keep" map
|
// commitRequirements below will also call WriteGoSum, but the "keep" map
|
||||||
// we have here could be strictly larger: commitRequirements only commits
|
// we have here could be strictly larger: commitRequirements only commits
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue