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>
--- /dev/null
+// 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)
+ }
+ }
+}
"cmd/internal/sys"
"flag"
"fmt"
- "go/build"
+ "internal/goversion"
"io"
"io/ioutil"
"log"
// 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
"debug/elf",
"debug/macho",
"debug/pe",
+ "internal/goversion",
"internal/xcoff",
"math/big",
"math/bits",
"go/parser"
"go/token"
"internal/goroot"
+ "internal/goversion"
"io"
"io/ioutil"
"log"
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))
}
"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"},
--- /dev/null
+// 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