Skip to content

Commit 378c48d

Browse files
committed
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 2785f4f commit 378c48d

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/cmd/go/internal/modload/init.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,13 +1472,12 @@ func setDefaultBuildMod() {
14721472
vendorDir = filepath.Join(modRoots[0], "vendor")
14731473
}
14741474
if fi, err := fsys.Stat(vendorDir); err == nil && fi.IsDir() {
1475-
modGo := "unspecified"
14761475
if goVersion != "" {
14771476
if gover.Compare(goVersion, "1.14") < 0 {
14781477
// The go version is less than 1.14. Don't set -mod=vendor by default.
14791478
// Since a vendor directory exists, we should record why we didn't use it.
14801479
// This message won't normally be shown, but it may appear with import errors.
1481-
cfg.BuildModReason = fmt.Sprintf("Go version in "+versionSource+" is %s, so vendor directory was not used.", modGo)
1480+
cfg.BuildModReason = fmt.Sprintf("Go version in "+versionSource+" is %s, so vendor directory was not used.", goVersion)
14821481
} else {
14831482
vendoredWorkspace, err := modulesTextIsForWorkspace(vendorDir)
14841483
if err != nil {
@@ -1499,9 +1498,9 @@ func setDefaultBuildMod() {
14991498
return
15001499
}
15011500
}
1502-
modGo = goVersion
1501+
} else {
1502+
cfg.BuildModReason = fmt.Sprintf("Go version in " + versionSource + " is unspecified, so vendor directory was not used.")
15031503
}
1504-
15051504
}
15061505
}
15071506

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
cd thirteen
2+
! go list -deps
3+
stderr '(Go version in go.mod is 1.13, so vendor directory was not used.)'
4+
5+
cd ../unspecified
6+
! go list -deps
7+
stderr '(Go version in go.mod is unspecified, so vendor directory was not used.)'
8+
9+
-- thirteen/foo.go --
10+
package foo
11+
12+
import _ "github.com/foo/bar"
13+
-- thirteen/go.mod --
14+
module example.com
15+
16+
go 1.13
17+
-- thirteen/vendor/github.com/foo/bar/bar.go --
18+
package bar
19+
-- unspecified/foo.go --
20+
package foo
21+
22+
import _ "github.com/foo/bar"
23+
-- unspecified/go.mod --
24+
module example.com
25+
-- unspecified/vendor/github.com/foo/bar/bar.go --
26+
package bar

0 commit comments

Comments
 (0)