aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-11-27 15:40:39 -0800
committerIan Lance Taylor <iant@golang.org>2018-12-03 05:00:14 +0000
commit9cc0209ef1393ae472aed93335c6915cf3269f21 (patch)
tree49a3eed886670c05ff0ab7446519ca222a754bb9
parent6fa0ace1288bce4eeb5228caeb7050c11e232858 (diff)
downloadgo-9cc0209ef1393ae472aed93335c6915cf3269f21.tar.gz
go-9cc0209ef1393ae472aed93335c6915cf3269f21.zip
[release-branch.go1.11] cmd/go: don't fail if requested Go version is later than current one
This is a partial backport of CL 147278 from tip to the Go 1.11 branch. Change the behavior when the go.mod file requests a Go version that is later than the current one. Previously cmd/go would give a fatal error in this situation. With this change it attempts the compilation, and if (and only if) the compilation fails it adds a note saying that the requested Go version is newer than the known version. This is as described in https://golang.org/issue/28221. Updates #28221 Change-Id: Iea03ca574b6b1a046655f2bb2e554126f877fb66 Reviewed-on: https://go-review.googlesource.com/c/151358 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
-rw-r--r--src/cmd/go/internal/work/exec.go13
-rw-r--r--src/cmd/go/testdata/script/mod_go_version.txt16
2 files changed, 22 insertions, 7 deletions
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index 91c4816fd0..88d9e6453f 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -434,10 +434,6 @@ func (b *Builder) build(a *Action) (err error) {
return fmt.Errorf("missing or invalid binary-only package; expected file %q", a.Package.Target)
}
- if p.Module != nil && !allowedVersion(p.Module.GoVersion) {
- return fmt.Errorf("module requires Go %s", p.Module.GoVersion)
- }
-
if err := b.Mkdir(a.Objdir); err != nil {
return err
}
@@ -638,12 +634,19 @@ func (b *Builder) build(a *Action) (err error) {
objpkg := objdir + "_pkg_.a"
ofile, out, err := BuildToolchain.gc(b, a, objpkg, icfg.Bytes(), len(sfiles) > 0, gofiles)
if len(out) > 0 {
- b.showOutput(a, a.Package.Dir, a.Package.Desc(), b.processOutput(out))
+ output := b.processOutput(out)
+ if p.Module != nil && !allowedVersion(p.Module.GoVersion) {
+ output += "note: module requires Go " + p.Module.GoVersion
+ }
+ b.showOutput(a, a.Package.Dir, a.Package.Desc(), output)
if err != nil {
return errPrintedOutput
}
}
if err != nil {
+ if p.Module != nil && !allowedVersion(p.Module.GoVersion) {
+ b.showOutput(a, a.Package.Dir, a.Package.Desc(), "note: module requires Go "+p.Module.GoVersion)
+ }
return err
}
if ofile != objpkg {
diff --git a/src/cmd/go/testdata/script/mod_go_version.txt b/src/cmd/go/testdata/script/mod_go_version.txt
index f2de74cee8..37f173531b 100644
--- a/src/cmd/go/testdata/script/mod_go_version.txt
+++ b/src/cmd/go/testdata/script/mod_go_version.txt
@@ -3,9 +3,10 @@
env GO111MODULE=on
go list
-! go build
-stderr 'module requires Go 1.999'
+go build
go build sub.1
+go build subver.1
+! stderr 'module requires'
! go build badsub.1
stderr 'module requires Go 1.11111'
@@ -19,11 +20,13 @@ module m
go 1.999
require (
sub.1 v1.0.0
+ subver.1 v1.0.0
badsub.1 v1.0.0
versioned.1 v1.0.0
)
replace (
sub.1 => ./sub
+ subver.1 => ./subver
badsub.1 => ./badsub
versioned.1 v1.0.0 => ./versioned1
versioned.1 v1.1.0 => ./versioned2
@@ -39,12 +42,20 @@ go 1.11
-- sub/x.go --
package x
+-- subver/go.mod --
+module m
+go 1.11111
+
+-- subver/x.go --
+package x
+
-- badsub/go.mod --
module m
go 1.11111
-- badsub/x.go --
package x
+invalid syntax
-- versioned1/go.mod --
module versioned
@@ -59,3 +70,4 @@ go 1.99999
-- versioned2/x.go --
package x
+invalid syntax