Skip to content

Commit 52d7033

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/modload: set the default GoVersion in a single location
For #46141 Updates #36460 Change-Id: Ie4c13c73a451650d1e8abb8e5cebfc30d0a71a70 Reviewed-on: https://go-review.googlesource.com/c/go/+/321070 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 05819bc commit 52d7033

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

src/cmd/go/internal/modload/load.go

+17-24
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,6 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma
314314

315315
initialRS, _ := loadModFile(ctx) // Ignore needCommit — we're going to commit at the end regardless.
316316

317-
if opts.GoVersion == "" {
318-
opts.GoVersion = modFileGoVersion()
319-
}
320-
321317
ld := loadFromRoots(ctx, loaderParams{
322318
PackageOpts: opts,
323319
requirements: initialRS,
@@ -380,7 +376,7 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma
380376

381377
// Success! Update go.mod and go.sum (if needed) and return the results.
382378
loaded = ld
383-
commitRequirements(ctx, opts.GoVersion, loaded.requirements)
379+
commitRequirements(ctx, loaded.GoVersion, loaded.requirements)
384380

385381
for _, pkg := range ld.pkgs {
386382
if !pkg.isTest() {
@@ -605,10 +601,8 @@ func ImportFromFiles(ctx context.Context, gofiles []string) {
605601
base.Fatalf("go: %v", err)
606602
}
607603

608-
goVersion := modFileGoVersion()
609604
loaded = loadFromRoots(ctx, loaderParams{
610605
PackageOpts: PackageOpts{
611-
GoVersion: goVersion,
612606
Tags: tags,
613607
ResolveMissingImports: true,
614608
SilencePackageErrors: true,
@@ -620,7 +614,7 @@ func ImportFromFiles(ctx context.Context, gofiles []string) {
620614
return roots
621615
},
622616
})
623-
commitRequirements(ctx, goVersion, loaded.requirements)
617+
commitRequirements(ctx, loaded.GoVersion, loaded.requirements)
624618
}
625619

626620
// DirImportPath returns the effective import path for dir,
@@ -921,26 +915,25 @@ func loadFromRoots(ctx context.Context, params loaderParams) *loader {
921915
work: par.NewQueue(runtime.GOMAXPROCS(0)),
922916
}
923917

924-
if params.GoVersion != "" {
925-
goVersionV := "v" + params.GoVersion
926-
if semver.Compare(goVersionV, narrowAllVersionV) < 0 && !ld.UseVendorAll {
927-
// The module's go version explicitly predates the change in "all" for lazy
928-
// loading, so continue to use the older interpretation.
929-
// (If params.GoVersion is empty, we are probably not in any module at all
930-
// and should use the latest semantics.)
931-
ld.allClosesOverTests = true
932-
}
918+
if ld.GoVersion == "" {
919+
ld.GoVersion = modFileGoVersion()
933920

934-
if ld.Tidy && semver.Compare(goVersionV, "v"+LatestGoVersion()) > 0 {
935-
ld.errorf("go mod tidy: go.mod file indicates go %s, but maximum supported version is %s\n", params.GoVersion, LatestGoVersion())
921+
if ld.Tidy && semver.Compare("v"+ld.GoVersion, "v"+LatestGoVersion()) > 0 {
922+
ld.errorf("go mod tidy: go.mod file indicates go %s, but maximum supported version is %s\n", ld.GoVersion, LatestGoVersion())
936923
base.ExitIfErrors()
937924
}
925+
}
938926

939-
var err error
940-
ld.requirements, err = convertDepth(ctx, ld.requirements, modDepthFromGoVersion(params.GoVersion))
941-
if err != nil {
942-
ld.errorf("go: %v\n", err)
943-
}
927+
if semver.Compare("v"+ld.GoVersion, narrowAllVersionV) < 0 && !ld.UseVendorAll {
928+
// The module's go version explicitly predates the change in "all" for lazy
929+
// loading, so continue to use the older interpretation.
930+
ld.allClosesOverTests = true
931+
}
932+
933+
var err error
934+
ld.requirements, err = convertDepth(ctx, ld.requirements, modDepthFromGoVersion(ld.GoVersion))
935+
if err != nil {
936+
ld.errorf("go: %v\n", err)
944937
}
945938

946939
if ld.requirements.depth == eager {

0 commit comments

Comments
 (0)