]> Cypherpunks repositories - gostls13.git/commitdiff
internal/goversion: add new package, move Go 1.x constant there out of go/build
authorBrad Fitzpatrick <bradfitz@golang.org>
Fri, 19 Apr 2019 16:09:17 +0000 (16:09 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 19 Apr 2019 18:04:35 +0000 (18:04 +0000)
Found by Josh, who says in the bug that it shrinks cmd/compile by 1.6 MB (6.5%).

Fixes #31563

Change-Id: I35127af539630e628a0a4f2273af519093536c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/172997
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/gc/dep_test.go [new file with mode: 0644]
src/cmd/compile/internal/gc/main.go
src/cmd/dist/buildtool.go
src/go/build/build.go
src/go/build/deps_test.go
src/internal/goversion/goversion.go [new file with mode: 0644]

diff --git a/src/cmd/compile/internal/gc/dep_test.go b/src/cmd/compile/internal/gc/dep_test.go
new file mode 100644 (file)
index 0000000..7fc9be5
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package gc
+
+import (
+       "internal/testenv"
+       "os/exec"
+       "strings"
+       "testing"
+)
+
+func TestDeps(t *testing.T) {
+       testenv.MustHaveGoBuild(t)
+       out, err := exec.Command("go", "list", "-f", "{{.Deps}}", "cmd/compile/internal/gc").Output()
+       if err != nil {
+               t.Fatal(err)
+       }
+       for _, dep := range strings.Fields(strings.Trim(string(out), "[]")) {
+               switch dep {
+               case "go/build", "go/token":
+                       t.Errorf("undesired dependency on %q", dep)
+               }
+       }
+}
index 71a4024765244b06af5d8a04ef8c3d2949601fe4..969b5969073e81e2cb961e0f2bf5a4b6ff8bce68 100644 (file)
@@ -19,7 +19,7 @@ import (
        "cmd/internal/sys"
        "flag"
        "fmt"
-       "go/build"
+       "internal/goversion"
        "io"
        "io/ioutil"
        "log"
@@ -1426,8 +1426,7 @@ var flag_lang string
 
 // currentLang returns the current language version.
 func currentLang() string {
-       tags := build.Default.ReleaseTags
-       return tags[len(tags)-1]
+       return fmt.Sprintf("go1.%d", goversion.Version)
 }
 
 // goVersionRE is a regular expression that matches the valid
index 7b85927785e882b21ffd54dcb177d30340bb7b6d..26e12991a4808758b1dabde02534e471cacf5b1d 100644 (file)
@@ -89,6 +89,7 @@ var bootstrapDirs = []string{
        "debug/elf",
        "debug/macho",
        "debug/pe",
+       "internal/goversion",
        "internal/xcoff",
        "math/big",
        "math/bits",
index 1be10f1fb8c367610097b972675a2863ff7c5c43..1ad076089db76b54a0da89328fdd6367054cef6c 100644 (file)
@@ -13,6 +13,7 @@ import (
        "go/parser"
        "go/token"
        "internal/goroot"
+       "internal/goversion"
        "io"
        "io/ioutil"
        "log"
@@ -292,15 +293,14 @@ func defaultContext() Context {
        c.GOPATH = envOr("GOPATH", defaultGOPATH())
        c.Compiler = runtime.Compiler
 
-       // Each major Go release in the Go 1.x series should add a tag here.
-       // Old tags should not be removed. That is, the go1.x tag is present
-       // in all releases >= Go 1.x. Code that requires Go 1.x or later should
-       // say "+build go1.x", and code that should only be built before Go 1.x
-       // (perhaps it is the stub to use in that case) should say "+build !go1.x".
-       // NOTE: If you add to this list, also update the doc comment in doc.go.
-       // NOTE: The last element in ReleaseTags should be the current release.
-       const version = 13 // go1.13
-       for i := 1; i <= version; i++ {
+       // Each major Go release in the Go 1.x series adds a new
+       // "go1.x" release tag. That is, the go1.x tag is present in
+       // all releases >= Go 1.x. Code that requires Go 1.x or later
+       // should say "+build go1.x", and code that should only be
+       // built before Go 1.x (perhaps it is the stub to use in that
+       // case) should say "+build !go1.x".
+       // The last element in ReleaseTags is the current release.
+       for i := 1; i <= goversion.Version; i++ {
                c.ReleaseTags = append(c.ReleaseTags, "go1."+strconv.Itoa(i))
        }
 
index c81d313b72aab9153a9464513a475faa75096d56..50650bd37396b8cb876811dd6fc83637096bd3a0 100644 (file)
@@ -268,7 +268,7 @@ var pkgDeps = map[string][]string{
        "encoding/pem":                   {"L4"},
        "encoding/xml":                   {"L4", "encoding"},
        "flag":                           {"L4", "OS"},
-       "go/build":                       {"L4", "OS", "GOPARSER", "internal/goroot"},
+       "go/build":                       {"L4", "OS", "GOPARSER", "internal/goroot", "internal/goversion"},
        "html":                           {"L4"},
        "image/draw":                     {"L4", "image/internal/imageutil"},
        "image/gif":                      {"L4", "compress/lzw", "image/color/palette", "image/draw"},
diff --git a/src/internal/goversion/goversion.go b/src/internal/goversion/goversion.go
new file mode 100644 (file)
index 0000000..8f9c7c9
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package goversion
+
+// Version is the current Go 1.x version. During development cycles on
+// the master branch it changes to be the version of the next Go 1.x
+// release.
+//
+// When incrementing this, also add to the list at src/go/build/doc.go
+// (search for "onward").
+const Version = 13