mirror of
https://github.com/golang/go
synced 2024-11-17 14:14:56 -07:00
internal/goversion: add new package, move Go 1.x constant there out of go/build
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>
This commit is contained in:
parent
97252f620f
commit
64e29f94e2
26
src/cmd/compile/internal/gc/dep_test.go
Normal file
26
src/cmd/compile/internal/gc/dep_test.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
1
src/cmd/dist/buildtool.go
vendored
1
src/cmd/dist/buildtool.go
vendored
@ -89,6 +89,7 @@ var bootstrapDirs = []string{
|
||||
"debug/elf",
|
||||
"debug/macho",
|
||||
"debug/pe",
|
||||
"internal/goversion",
|
||||
"internal/xcoff",
|
||||
"math/big",
|
||||
"math/bits",
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
|
@ -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"},
|
||||
|
13
src/internal/goversion/goversion.go
Normal file
13
src/internal/goversion/goversion.go
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user