mirror of
https://github.com/golang/go
synced 2024-11-26 16:07:00 -07:00
cmd/internal/objabi: centralize GOEXPERIMENT parsing
objabi parses GOEXPERIMENT, but most of the consumers look at the raw GOEXPERIMENT string that objabi gets from the environment. Centralize this logic by only exposing the parsed GOEXPERIMENT value from objabi. This sets us up for the next few changes. It also has the nice but mostly useless property that the order of experiment names will be canonicalized in build cache hashes. After this, the only remaining place that looks at raw GOEXPERIMENT is cmd/dist, which we'll fix in the next CL. For #40724. Change-Id: Idb150f848e17c184fae91372ca8b361591472f51 Reviewed-on: https://go-review.googlesource.com/c/go/+/302049 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
b7cb92ad12
commit
06ca809410
@ -258,7 +258,6 @@ var (
|
|||||||
GOMIPS64 = envOr("GOMIPS64", objabi.GOMIPS64)
|
GOMIPS64 = envOr("GOMIPS64", objabi.GOMIPS64)
|
||||||
GOPPC64 = envOr("GOPPC64", fmt.Sprintf("%s%d", "power", objabi.GOPPC64))
|
GOPPC64 = envOr("GOPPC64", fmt.Sprintf("%s%d", "power", objabi.GOPPC64))
|
||||||
GOWASM = envOr("GOWASM", fmt.Sprint(objabi.GOWASM))
|
GOWASM = envOr("GOWASM", fmt.Sprint(objabi.GOWASM))
|
||||||
GOEXPERIMENT = envOr("GOEXPERIMENT", objabi.GOEXPERIMENT)
|
|
||||||
|
|
||||||
GOPROXY = envOr("GOPROXY", "https://proxy.golang.org,direct")
|
GOPROXY = envOr("GOPROXY", "https://proxy.golang.org,direct")
|
||||||
GOSUMDB = envOr("GOSUMDB", "sum.golang.org")
|
GOSUMDB = envOr("GOSUMDB", "sum.golang.org")
|
||||||
|
@ -8,7 +8,6 @@ package work
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"cmd/go/internal/fsys"
|
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@ -31,10 +30,12 @@ import (
|
|||||||
"cmd/go/internal/base"
|
"cmd/go/internal/base"
|
||||||
"cmd/go/internal/cache"
|
"cmd/go/internal/cache"
|
||||||
"cmd/go/internal/cfg"
|
"cmd/go/internal/cfg"
|
||||||
|
"cmd/go/internal/fsys"
|
||||||
"cmd/go/internal/load"
|
"cmd/go/internal/load"
|
||||||
"cmd/go/internal/modload"
|
"cmd/go/internal/modload"
|
||||||
"cmd/go/internal/str"
|
"cmd/go/internal/str"
|
||||||
"cmd/go/internal/trace"
|
"cmd/go/internal/trace"
|
||||||
|
"cmd/internal/objabi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// actionList returns the list of actions in the dag rooted at root
|
// actionList returns the list of actions in the dag rooted at root
|
||||||
@ -276,8 +277,8 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
|
|||||||
key, val := cfg.GetArchEnv()
|
key, val := cfg.GetArchEnv()
|
||||||
fmt.Fprintf(h, "%s=%s\n", key, val)
|
fmt.Fprintf(h, "%s=%s\n", key, val)
|
||||||
|
|
||||||
if exp := cfg.GOEXPERIMENT; exp != "" {
|
if objabi.GOEXPERIMENT != "" {
|
||||||
fmt.Fprintf(h, "GOEXPERIMENT=%q\n", exp)
|
fmt.Fprintf(h, "GOEXPERIMENT=%q\n", objabi.GOEXPERIMENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(rsc): Convince compiler team not to add more magic environment variables,
|
// TODO(rsc): Convince compiler team not to add more magic environment variables,
|
||||||
@ -1250,8 +1251,8 @@ func (b *Builder) printLinkerConfig(h io.Writer, p *load.Package) {
|
|||||||
key, val := cfg.GetArchEnv()
|
key, val := cfg.GetArchEnv()
|
||||||
fmt.Fprintf(h, "%s=%s\n", key, val)
|
fmt.Fprintf(h, "%s=%s\n", key, val)
|
||||||
|
|
||||||
if exp := cfg.GOEXPERIMENT; exp != "" {
|
if objabi.GOEXPERIMENT != "" {
|
||||||
fmt.Fprintf(h, "GOEXPERIMENT=%q\n", exp)
|
fmt.Fprintf(h, "GOEXPERIMENT=%q\n", objabi.GOEXPERIMENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The linker writes source file paths that say GOROOT_FINAL, but
|
// The linker writes source file paths that say GOROOT_FINAL, but
|
||||||
|
@ -52,15 +52,10 @@ func BuildInit() {
|
|||||||
// build tag with the same name but prefixed by "goexperiment." which can be
|
// build tag with the same name but prefixed by "goexperiment." which can be
|
||||||
// used for compiling alternative files for the experiment. This allows
|
// used for compiling alternative files for the experiment. This allows
|
||||||
// changes for the experiment, like extra struct fields in the runtime,
|
// changes for the experiment, like extra struct fields in the runtime,
|
||||||
// without affecting the base non-experiment code at all. [2:] strips the
|
// without affecting the base non-experiment code at all.
|
||||||
// leading "X:" from objabi.Expstring().
|
for _, expt := range strings.Split(objabi.GOEXPERIMENT, ",") {
|
||||||
exp := objabi.Expstring()[2:]
|
|
||||||
if exp != "none" {
|
|
||||||
experiments := strings.Split(exp, ",")
|
|
||||||
for _, expt := range experiments {
|
|
||||||
cfg.BuildContext.BuildTags = append(cfg.BuildContext.BuildTags, "goexperiment."+expt)
|
cfg.BuildContext.BuildTags = append(cfg.BuildContext.BuildTags, "goexperiment."+expt)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func instrumentInit() {
|
func instrumentInit() {
|
||||||
|
@ -95,7 +95,7 @@ func (versionFlag) Set(s string) error {
|
|||||||
// to distinguish go1.10.2 with an experiment
|
// to distinguish go1.10.2 with an experiment
|
||||||
// from go1.10.2 without an experiment.
|
// from go1.10.2 without an experiment.
|
||||||
p := Expstring()
|
p := Expstring()
|
||||||
if p == DefaultExpstring() {
|
if p == defaultExpstring {
|
||||||
p = ""
|
p = ""
|
||||||
}
|
}
|
||||||
sep := ""
|
sep := ""
|
||||||
|
@ -24,7 +24,6 @@ var (
|
|||||||
GOROOT = envOr("GOROOT", defaultGOROOT)
|
GOROOT = envOr("GOROOT", defaultGOROOT)
|
||||||
GOARCH = envOr("GOARCH", defaultGOARCH)
|
GOARCH = envOr("GOARCH", defaultGOARCH)
|
||||||
GOOS = envOr("GOOS", defaultGOOS)
|
GOOS = envOr("GOOS", defaultGOOS)
|
||||||
GOEXPERIMENT = envOr("GOEXPERIMENT", defaultGOEXPERIMENT)
|
|
||||||
GO386 = envOr("GO386", defaultGO386)
|
GO386 = envOr("GO386", defaultGO386)
|
||||||
GOARM = goarm()
|
GOARM = goarm()
|
||||||
GOMIPS = gomips()
|
GOMIPS = gomips()
|
||||||
@ -33,6 +32,12 @@ var (
|
|||||||
GOWASM = gowasm()
|
GOWASM = gowasm()
|
||||||
GO_LDSO = defaultGO_LDSO
|
GO_LDSO = defaultGO_LDSO
|
||||||
Version = version
|
Version = version
|
||||||
|
|
||||||
|
// GOEXPERIMENT is a comma-separated list of enabled
|
||||||
|
// experiments. This is derived from the GOEXPERIMENT
|
||||||
|
// environment variable if set, or the value of GOEXPERIMENT
|
||||||
|
// when make.bash was run if not.
|
||||||
|
GOEXPERIMENT string // Set by package init
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -125,7 +130,12 @@ func Getgoextlinkenabled() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
for _, f := range strings.Split(GOEXPERIMENT, ",") {
|
// Capture "default" experiments.
|
||||||
|
defaultExpstring = Expstring()
|
||||||
|
|
||||||
|
goexperiment := envOr("GOEXPERIMENT", defaultGOEXPERIMENT)
|
||||||
|
|
||||||
|
for _, f := range strings.Split(goexperiment, ",") {
|
||||||
if f != "" {
|
if f != "" {
|
||||||
addexp(f)
|
addexp(f)
|
||||||
}
|
}
|
||||||
@ -135,6 +145,9 @@ func init() {
|
|||||||
if GOARCH != "amd64" {
|
if GOARCH != "amd64" {
|
||||||
Regabi_enabled = 0
|
Regabi_enabled = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set GOEXPERIMENT to the parsed and canonicalized set of experiments.
|
||||||
|
GOEXPERIMENT = expList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: must agree with runtime.framepointer_enabled.
|
// Note: must agree with runtime.framepointer_enabled.
|
||||||
@ -171,7 +184,6 @@ var (
|
|||||||
// Toolchain experiments.
|
// Toolchain experiments.
|
||||||
// These are controlled by the GOEXPERIMENT environment
|
// These are controlled by the GOEXPERIMENT environment
|
||||||
// variable recorded when the toolchain is built.
|
// variable recorded when the toolchain is built.
|
||||||
// This list is also known to cmd/gc.
|
|
||||||
var exper = []struct {
|
var exper = []struct {
|
||||||
name string
|
name string
|
||||||
val *int
|
val *int
|
||||||
@ -182,21 +194,29 @@ var exper = []struct {
|
|||||||
{"regabi", &Regabi_enabled},
|
{"regabi", &Regabi_enabled},
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultExpstring = Expstring()
|
var defaultExpstring string
|
||||||
|
|
||||||
func DefaultExpstring() string {
|
// expList returns the list of enabled GOEXPERIMENTS as a
|
||||||
return defaultExpstring
|
// commas-separated list.
|
||||||
}
|
func expList() string {
|
||||||
|
buf := ""
|
||||||
func Expstring() string {
|
|
||||||
buf := "X"
|
|
||||||
for i := range exper {
|
for i := range exper {
|
||||||
if *exper[i].val != 0 {
|
if *exper[i].val != 0 {
|
||||||
buf += "," + exper[i].name
|
buf += "," + exper[i].name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if buf == "X" {
|
if len(buf) == 0 {
|
||||||
buf += ",none"
|
return ""
|
||||||
}
|
}
|
||||||
return "X:" + buf[2:]
|
return buf[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expstring returns the GOEXPERIMENT string that should appear in Go
|
||||||
|
// version signatures. This always starts with "X:".
|
||||||
|
func Expstring() string {
|
||||||
|
list := expList()
|
||||||
|
if list == "" {
|
||||||
|
return "X:none"
|
||||||
|
}
|
||||||
|
return "X:" + list
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user