]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/toolchain: remove references to modfetch.Fetcher_
authorIan Alexander <jitsu@google.com>
Mon, 24 Nov 2025 23:48:32 +0000 (18:48 -0500)
committerIan Alexander <jitsu@google.com>
Wed, 26 Nov 2025 17:32:25 +0000 (09:32 -0800)
This commit removes references to the global modfetch.Fetcher_
variable from the toolchain package.

Change-Id: Id366bec88e5904098b90371ec103f92d402174d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/724248
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>

src/cmd/go/internal/toolchain/select.go
src/cmd/go/internal/toolchain/switch.go

index c27bcb5bbdd634ad0c84b7aad12e51698db4eebc..192fb62fc26b14797c37426960c6352bfe2c303d 100644 (file)
@@ -25,7 +25,6 @@ import (
        "cmd/go/internal/base"
        "cmd/go/internal/cfg"
        "cmd/go/internal/gover"
-       "cmd/go/internal/modfetch"
        "cmd/go/internal/modload"
        "cmd/go/internal/run"
        "cmd/go/internal/work"
@@ -86,8 +85,10 @@ func FilterEnv(env []string) []string {
        return out
 }
 
-var counterErrorsInvalidToolchainInFile = counter.New("go/errors:invalid-toolchain-in-file")
-var toolchainTrace = godebug.New("#toolchaintrace").Value() == "1"
+var (
+       counterErrorsInvalidToolchainInFile = counter.New("go/errors:invalid-toolchain-in-file")
+       toolchainTrace                      = godebug.New("#toolchaintrace").Value() == "1"
+)
 
 // Select invokes a different Go toolchain if directed by
 // the GOTOOLCHAIN environment variable or the user's configuration
@@ -360,7 +361,7 @@ func Exec(s *modload.State, gotoolchain string) {
                Path:    gotoolchainModule,
                Version: gotoolchainVersion + "-" + gotoolchain + "." + runtime.GOOS + "-" + runtime.GOARCH,
        }
-       dir, err := modfetch.Fetcher_.Download(context.Background(), m)
+       dir, err := s.Fetcher().Download(context.Background(), m)
        if err != nil {
                if errors.Is(err, fs.ErrNotExist) {
                        toolVers := gover.FromToolchain(gotoolchain)
@@ -380,7 +381,7 @@ func Exec(s *modload.State, gotoolchain string) {
                if err != nil {
                        base.Fatalf("download %s: %v", gotoolchain, err)
                }
-               if info.Mode()&0111 == 0 {
+               if info.Mode()&0o111 == 0 {
                        // allowExec sets the exec permission bits on all files found in dir if pattern is the empty string,
                        // or only those files that match the pattern if it's non-empty.
                        allowExec := func(dir, pattern string) {
@@ -399,7 +400,7 @@ func Exec(s *modload.State, gotoolchain string) {
                                                if err != nil {
                                                        return err
                                                }
-                                               if err := os.Chmod(path, info.Mode()&0777|0111); err != nil {
+                                               if err := os.Chmod(path, info.Mode()&0o777|0o111); err != nil {
                                                        return err
                                                }
                                        }
index 4ddc28a0e90bfe0ac430ec6959910efc8dd40340..ff4fce03074832249f5d4b287b29fd989a2a1c6f 100644 (file)
@@ -97,7 +97,7 @@ func (s *Switcher) Switch(ctx context.Context) {
        }
 
        // Switch to newer Go toolchain if necessary and possible.
-       tv, err := NewerToolchain(ctx, s.TooNew.GoVersion)
+       tv, err := NewerToolchain(ctx, s.loaderstate.Fetcher(), s.TooNew.GoVersion)
        if err != nil {
                for _, err := range s.Errors {
                        base.Error(err)
@@ -130,8 +130,11 @@ func SwitchOrFatal(loaderstate *modload.State, ctx context.Context, err error) {
 // If the latest major release is 1.N.0, we use the latest patch release of 1.(N-1) if that's >= version.
 // Otherwise we use the latest 1.N if that's allowed.
 // Otherwise we use the latest release.
-func NewerToolchain(ctx context.Context, version string) (string, error) {
-       fetch := autoToolchains
+func NewerToolchain(ctx context.Context, f *modfetch.Fetcher, version string) (string, error) {
+       fetch := func(ctx context.Context) ([]string, error) {
+               return autoToolchains(ctx, f)
+       }
+
        if !HasAuto() {
                fetch = pathToolchains
        }
@@ -143,10 +146,10 @@ func NewerToolchain(ctx context.Context, version string) (string, error) {
 }
 
 // autoToolchains returns the list of toolchain versions available to GOTOOLCHAIN=auto or =min+auto mode.
-func autoToolchains(ctx context.Context) ([]string, error) {
+func autoToolchains(ctx context.Context, f *modfetch.Fetcher) ([]string, error) {
        var versions *modfetch.Versions
        err := modfetch.TryProxies(func(proxy string) error {
-               v, err := modfetch.Fetcher_.Lookup(ctx, proxy, "go").Versions(ctx, "")
+               v, err := f.Lookup(ctx, proxy, "go").Versions(ctx, "")
                if err != nil {
                        return err
                }