]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.11] cmd/go: don't fail if requested Go version is later than...
authorIan Lance Taylor <iant@golang.org>
Tue, 27 Nov 2018 23:40:39 +0000 (15:40 -0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 3 Dec 2018 05:00:14 +0000 (05:00 +0000)
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>
src/cmd/go/internal/work/exec.go
src/cmd/go/testdata/script/mod_go_version.txt

index 91c4816fd09b7082600cc59f8ae881b743efec6c..88d9e6453f3f63de899d6cd6fa0efa4a58f4d196 100644 (file)
@@ -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 {
index f2de74cee87dfeafe0a15b6bcbdf584552be6302..37f173531b699b83800216196d29418f7a178bfe 100644 (file)
@@ -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