]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: pass go language version to cmd/compile
authorIan Lance Taylor <iant@golang.org>
Fri, 2 Nov 2018 23:00:33 +0000 (16:00 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 8 Nov 2018 01:55:42 +0000 (01:55 +0000)
Pass the Go language version specified in the go.mod file to
cmd/compile.

Also, 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: I46803813e7872d4a418a3fd5299880be3b73a971
Reviewed-on: https://go-review.googlesource.com/c/147278
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/internal/work/gc.go
src/cmd/go/testdata/script/mod_go_version.txt

index d9c59aab80061ff503f6b7f0c0acc2f3a745c375..92e814ee6f26593b63f9b5b3c3ada16b8f3a1938 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 6e5333ccbc40d45465c6ab42c7430bbf5a91b32e..5a0bd1c2cf1089b8acd64fbf0f814a5da62f67ca 100644 (file)
@@ -53,6 +53,9 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg []byte, a
                pkgpath = "main"
        }
        gcargs := []string{"-p", pkgpath}
+       if p.Module != nil && p.Module.GoVersion != "" && allowedVersion(p.Module.GoVersion) {
+               gcargs = append(gcargs, "-lang=go"+p.Module.GoVersion)
+       }
        if p.Standard {
                gcargs = append(gcargs, "-std")
        }
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