mirror of
https://github.com/golang/go.git
synced 2025-11-11 14:11:04 +00:00
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 <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
05819bc104
commit
52d7033ff6
1 changed files with 17 additions and 24 deletions
|
|
@ -314,10 +314,6 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma
|
||||||
|
|
||||||
initialRS, _ := loadModFile(ctx) // Ignore needCommit — we're going to commit at the end regardless.
|
initialRS, _ := loadModFile(ctx) // Ignore needCommit — we're going to commit at the end regardless.
|
||||||
|
|
||||||
if opts.GoVersion == "" {
|
|
||||||
opts.GoVersion = modFileGoVersion()
|
|
||||||
}
|
|
||||||
|
|
||||||
ld := loadFromRoots(ctx, loaderParams{
|
ld := loadFromRoots(ctx, loaderParams{
|
||||||
PackageOpts: opts,
|
PackageOpts: opts,
|
||||||
requirements: initialRS,
|
requirements: initialRS,
|
||||||
|
|
@ -380,7 +376,7 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma
|
||||||
|
|
||||||
// Success! Update go.mod and go.sum (if needed) and return the results.
|
// Success! Update go.mod and go.sum (if needed) and return the results.
|
||||||
loaded = ld
|
loaded = ld
|
||||||
commitRequirements(ctx, opts.GoVersion, loaded.requirements)
|
commitRequirements(ctx, loaded.GoVersion, loaded.requirements)
|
||||||
|
|
||||||
for _, pkg := range ld.pkgs {
|
for _, pkg := range ld.pkgs {
|
||||||
if !pkg.isTest() {
|
if !pkg.isTest() {
|
||||||
|
|
@ -605,10 +601,8 @@ func ImportFromFiles(ctx context.Context, gofiles []string) {
|
||||||
base.Fatalf("go: %v", err)
|
base.Fatalf("go: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
goVersion := modFileGoVersion()
|
|
||||||
loaded = loadFromRoots(ctx, loaderParams{
|
loaded = loadFromRoots(ctx, loaderParams{
|
||||||
PackageOpts: PackageOpts{
|
PackageOpts: PackageOpts{
|
||||||
GoVersion: goVersion,
|
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
ResolveMissingImports: true,
|
ResolveMissingImports: true,
|
||||||
SilencePackageErrors: true,
|
SilencePackageErrors: true,
|
||||||
|
|
@ -620,7 +614,7 @@ func ImportFromFiles(ctx context.Context, gofiles []string) {
|
||||||
return roots
|
return roots
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
commitRequirements(ctx, goVersion, loaded.requirements)
|
commitRequirements(ctx, loaded.GoVersion, loaded.requirements)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DirImportPath returns the effective import path for dir,
|
// DirImportPath returns the effective import path for dir,
|
||||||
|
|
@ -921,26 +915,25 @@ func loadFromRoots(ctx context.Context, params loaderParams) *loader {
|
||||||
work: par.NewQueue(runtime.GOMAXPROCS(0)),
|
work: par.NewQueue(runtime.GOMAXPROCS(0)),
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.GoVersion != "" {
|
if ld.GoVersion == "" {
|
||||||
goVersionV := "v" + params.GoVersion
|
ld.GoVersion = modFileGoVersion()
|
||||||
if semver.Compare(goVersionV, narrowAllVersionV) < 0 && !ld.UseVendorAll {
|
|
||||||
// The module's go version explicitly predates the change in "all" for lazy
|
|
||||||
// loading, so continue to use the older interpretation.
|
|
||||||
// (If params.GoVersion is empty, we are probably not in any module at all
|
|
||||||
// and should use the latest semantics.)
|
|
||||||
ld.allClosesOverTests = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if ld.Tidy && semver.Compare(goVersionV, "v"+LatestGoVersion()) > 0 {
|
if ld.Tidy && semver.Compare("v"+ld.GoVersion, "v"+LatestGoVersion()) > 0 {
|
||||||
ld.errorf("go mod tidy: go.mod file indicates go %s, but maximum supported version is %s\n", params.GoVersion, LatestGoVersion())
|
ld.errorf("go mod tidy: go.mod file indicates go %s, but maximum supported version is %s\n", ld.GoVersion, LatestGoVersion())
|
||||||
base.ExitIfErrors()
|
base.ExitIfErrors()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
if semver.Compare("v"+ld.GoVersion, narrowAllVersionV) < 0 && !ld.UseVendorAll {
|
||||||
ld.requirements, err = convertDepth(ctx, ld.requirements, modDepthFromGoVersion(params.GoVersion))
|
// The module's go version explicitly predates the change in "all" for lazy
|
||||||
if err != nil {
|
// loading, so continue to use the older interpretation.
|
||||||
ld.errorf("go: %v\n", err)
|
ld.allClosesOverTests = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
ld.requirements, err = convertDepth(ctx, ld.requirements, modDepthFromGoVersion(ld.GoVersion))
|
||||||
|
if err != nil {
|
||||||
|
ld.errorf("go: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ld.requirements.depth == eager {
|
if ld.requirements.depth == eager {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue