From: Michael Matloob Date: Thu, 23 May 2024 19:00:49 +0000 (-0400) Subject: cmd/go/internal/modload: fix bug in error message X-Git-Tag: go1.23rc1~145 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=378c48df3b485da1ed287f59e5d1f59ad232e554;p=gostls13.git cmd/go/internal/modload: fix bug in error message CL 513756 moved the usage of modGo after it was set to its proper value, so the error message text always listed the version of go as "unspecified". Fix the error message in the case where the version was set in the go.mod, and provide an error message where it wasn't. Fixes #67587 Change-Id: I763f6be7ee811da32fcb7e785682fd6f48145981 Reviewed-on: https://go-review.googlesource.com/c/go/+/588075 Reviewed-by: Sam Thanawalla LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index 89eeb5c71a..4ba1bf98ee 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -1472,13 +1472,12 @@ func setDefaultBuildMod() { vendorDir = filepath.Join(modRoots[0], "vendor") } if fi, err := fsys.Stat(vendorDir); err == nil && fi.IsDir() { - modGo := "unspecified" if goVersion != "" { if gover.Compare(goVersion, "1.14") < 0 { // The go version is less than 1.14. Don't set -mod=vendor by default. // Since a vendor directory exists, we should record why we didn't use it. // This message won't normally be shown, but it may appear with import errors. - cfg.BuildModReason = fmt.Sprintf("Go version in "+versionSource+" is %s, so vendor directory was not used.", modGo) + cfg.BuildModReason = fmt.Sprintf("Go version in "+versionSource+" is %s, so vendor directory was not used.", goVersion) } else { vendoredWorkspace, err := modulesTextIsForWorkspace(vendorDir) if err != nil { @@ -1499,9 +1498,9 @@ func setDefaultBuildMod() { return } } - modGo = goVersion + } else { + cfg.BuildModReason = fmt.Sprintf("Go version in " + versionSource + " is unspecified, so vendor directory was not used.") } - } } diff --git a/src/cmd/go/testdata/script/list_buildmod_reason_issue67587.txt b/src/cmd/go/testdata/script/list_buildmod_reason_issue67587.txt new file mode 100644 index 0000000000..a89f0e4f9d --- /dev/null +++ b/src/cmd/go/testdata/script/list_buildmod_reason_issue67587.txt @@ -0,0 +1,26 @@ +cd thirteen +! go list -deps +stderr '(Go version in go.mod is 1.13, so vendor directory was not used.)' + +cd ../unspecified +! go list -deps +stderr '(Go version in go.mod is unspecified, so vendor directory was not used.)' + +-- thirteen/foo.go -- +package foo + +import _ "github.com/foo/bar" +-- thirteen/go.mod -- +module example.com + +go 1.13 +-- thirteen/vendor/github.com/foo/bar/bar.go -- +package bar +-- unspecified/foo.go -- +package foo + +import _ "github.com/foo/bar" +-- unspecified/go.mod -- +module example.com +-- unspecified/vendor/github.com/foo/bar/bar.go -- +package bar \ No newline at end of file