Skip to content

Commit

Permalink
cmd/go: print not-defaults arch-env
Browse files Browse the repository at this point in the history
Fixes golang#67492
For golang#34208

Change-Id: I33a029f307d4a199dc338387cde41d49764f8fd7
  • Loading branch information
qiulaidongfeng committed Jul 3, 2024
1 parent 148755a commit 5461498
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 37 deletions.
22 changes: 15 additions & 7 deletions src/cmd/dist/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ var (
isRelease bool

vflag int // verbosity

defaultGO386 = "sse2"
defaultGOAMD64 = "v1"
defaultGOMIPS = "hardfloat"
defaultGOMIPS64 = "hardfloat"
defaultGOPPC64 = "power8"
defaultGORISCV64 = "rva20u64"
defaultGOARM64 = "v8.0"
)

// The known architectures.
Expand Down Expand Up @@ -144,43 +152,43 @@ func xinit() {

b = os.Getenv("GOARM64")
if b == "" {
b = "v8.0"
b = defaultGOARM64
}
goarm64 = b

b = os.Getenv("GO386")
if b == "" {
b = "sse2"
b = defaultGO386
}
go386 = b

b = os.Getenv("GOAMD64")
if b == "" {
b = "v1"
b = defaultGOAMD64
}
goamd64 = b

b = os.Getenv("GOMIPS")
if b == "" {
b = "hardfloat"
b = defaultGOMIPS
}
gomips = b

b = os.Getenv("GOMIPS64")
if b == "" {
b = "hardfloat"
b = defaultGOMIPS64
}
gomips64 = b

b = os.Getenv("GOPPC64")
if b == "" {
b = "power8"
b = defaultGOPPC64
}
goppc64 = b

b = os.Getenv("GORISCV64")
if b == "" {
b = "rva20u64"
b = defaultGORISCV64
}
goriscv64 = b

Expand Down
16 changes: 8 additions & 8 deletions src/cmd/dist/buildruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ func mkbuildcfg(file string) {
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "import \"runtime\"\n")
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "const defaultGO386 = `%s`\n", go386)
fmt.Fprintf(&buf, "const defaultGOAMD64 = `%s`\n", goamd64)
fmt.Fprintf(&buf, "const defaultGOARM = `%s`\n", goarm)
fmt.Fprintf(&buf, "const defaultGOARM64 = `%s`\n", goarm64)
fmt.Fprintf(&buf, "const defaultGOMIPS = `%s`\n", gomips)
fmt.Fprintf(&buf, "const defaultGOMIPS64 = `%s`\n", gomips64)
fmt.Fprintf(&buf, "const defaultGOPPC64 = `%s`\n", goppc64)
fmt.Fprintf(&buf, "const defaultGORISCV64 = `%s`\n", goriscv64)
fmt.Fprintf(&buf, "const DefaultGO386 = `%s`\n", defaultGO386)
fmt.Fprintf(&buf, "const DefaultGOAMD64 = `%s`\n", defaultGOAMD64)
fmt.Fprintf(&buf, "const DefaultGOARM = `%s`\n", xgetgoarm())
fmt.Fprintf(&buf, "const DefaultGOARM64 = `%s`\n", defaultGOARM64)
fmt.Fprintf(&buf, "const DefaultGOMIPS = `%s`\n", defaultGOMIPS)
fmt.Fprintf(&buf, "const DefaultGOMIPS64 = `%s`\n", defaultGOMIPS64)
fmt.Fprintf(&buf, "const DefaultGOPPC64 = `%s`\n", defaultGOPPC64)
fmt.Fprintf(&buf, "const DefaultGORISCV64 = `%s`\n", defaultGORISCV64)
fmt.Fprintf(&buf, "const defaultGOEXPERIMENT = `%s`\n", goexperiment)
fmt.Fprintf(&buf, "const defaultGO_EXTLINK_ENABLED = `%s`\n", goextlinkenabled)
fmt.Fprintf(&buf, "const defaultGO_LDSO = `%s`\n", defaultldso)
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/go/internal/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,14 @@ var (
GOMODCACHE, GOMODCACHEChanged = EnvOrAndChanged("GOMODCACHE", gopathDir("pkg/mod"))

// Used in envcmd.MkEnv and build ID computations.
GOARM64, goARM64Changed = EnvOrAndChanged("GOARM64", fmt.Sprint(buildcfg.GOARM64))
GOARM, goARMChanged = EnvOrAndChanged("GOARM", fmt.Sprint(buildcfg.GOARM))
GO386, go386Changed = EnvOrAndChanged("GO386", buildcfg.GO386)
GOAMD64, goAMD64Changed = EnvOrAndChanged("GOAMD64", fmt.Sprintf("%s%d", "v", buildcfg.GOAMD64))
GOMIPS, goMIPSChanged = EnvOrAndChanged("GOMIPS", buildcfg.GOMIPS)
GOMIPS64, goMIPS64Changed = EnvOrAndChanged("GOMIPS64", buildcfg.GOMIPS64)
GOPPC64, goPPC64Changed = EnvOrAndChanged("GOPPC64", fmt.Sprintf("%s%d", "power", buildcfg.GOPPC64))
GORISCV64, goRISCV64Changed = EnvOrAndChanged("GORISCV64", fmt.Sprintf("rva%du64", buildcfg.GORISCV64))
GOARM64, goARM64Changed = EnvOrAndChanged("GOARM64", buildcfg.DefaultGOARM64)
GOARM, goARMChanged = EnvOrAndChanged("GOARM", buildcfg.DefaultGOARM)
GO386, go386Changed = EnvOrAndChanged("GO386", buildcfg.DefaultGO386)
GOAMD64, goAMD64Changed = EnvOrAndChanged("GOAMD64", buildcfg.DefaultGOAMD64)
GOMIPS, goMIPSChanged = EnvOrAndChanged("GOMIPS", buildcfg.DefaultGOMIPS)
GOMIPS64, goMIPS64Changed = EnvOrAndChanged("GOMIPS64", buildcfg.DefaultGOMIPS64)
GOPPC64, goPPC64Changed = EnvOrAndChanged("GOPPC64", buildcfg.DefaultGOPPC64)
GORISCV64, goRISCV64Changed = EnvOrAndChanged("GORISCV64", buildcfg.DefaultGORISCV64)
GOWASM, goWASMChanged = EnvOrAndChanged("GOWASM", fmt.Sprint(buildcfg.GOWASM))

GOPROXY, GOPROXYChanged = EnvOrAndChanged("GOPROXY", "")
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/go/testdata/script/env_changed.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ go env -changed -json GOARCH
[GOARCH:amd64] stdout '"GOARCH": "arm64"'
[!GOARCH:amd64] stdout '"GOARCH": "amd64"'

env GOAMD64=v3
go env -changed
stdout 'GOAMD64=''?v3''?'

env GOPROXY=s
go env -changed GOPROXY
! stdout 'GOPROXY'
Expand Down
28 changes: 14 additions & 14 deletions src/internal/buildcfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
GOROOT = os.Getenv("GOROOT") // cached for efficiency
GOARCH = envOr("GOARCH", defaultGOARCH)
GOOS = envOr("GOOS", defaultGOOS)
GO386 = envOr("GO386", defaultGO386)
GO386 = envOr("GO386", DefaultGO386)
GOAMD64 = goamd64()
GOARM = goarm()
GOARM64 = goarm64()
Expand Down Expand Up @@ -56,7 +56,7 @@ func envOr(key, value string) string {
}

func goamd64() int {
switch v := envOr("GOAMD64", defaultGOAMD64); v {
switch v := envOr("GOAMD64", DefaultGOAMD64); v {
case "v1":
return 1
case "v2":
Expand All @@ -67,7 +67,7 @@ func goamd64() int {
return 4
}
Error = fmt.Errorf("invalid GOAMD64: must be v1, v2, v3, v4")
return int(defaultGOAMD64[len("v")] - '0')
return int(DefaultGOAMD64[len("v")] - '0')
}

type goarmFeatures struct {
Expand All @@ -90,7 +90,7 @@ func goarm() (g goarmFeatures) {
softFloatOpt = ",softfloat"
hardFloatOpt = ",hardfloat"
)
def := defaultGOARM
def := DefaultGOARM
if GOOS == "android" && GOARCH == "arm" {
// Android arm devices always support GOARM=7.
def = "7"
Expand Down Expand Up @@ -186,14 +186,14 @@ func ParseGoarm64(v string) (g Goarm64Features, e error) {
default:
e = fmt.Errorf("invalid GOARM64: must start with v8.{0-9} or v9.{0-5} and may optionally end in %q and/or %q",
lseOpt, cryptoOpt)
g.Version = defaultGOARM64
g.Version = DefaultGOARM64
}

return
}

func goarm64() (g Goarm64Features) {
g, Error = ParseGoarm64(envOr("GOARM64", defaultGOARM64))
g, Error = ParseGoarm64(envOr("GOARM64", DefaultGOARM64))
return
}

Expand Down Expand Up @@ -229,25 +229,25 @@ func (g Goarm64Features) Supports(s string) bool {
}

func gomips() string {
switch v := envOr("GOMIPS", defaultGOMIPS); v {
switch v := envOr("GOMIPS", DefaultGOMIPS); v {
case "hardfloat", "softfloat":
return v
}
Error = fmt.Errorf("invalid GOMIPS: must be hardfloat, softfloat")
return defaultGOMIPS
return DefaultGOMIPS
}

func gomips64() string {
switch v := envOr("GOMIPS64", defaultGOMIPS64); v {
switch v := envOr("GOMIPS64", DefaultGOMIPS64); v {
case "hardfloat", "softfloat":
return v
}
Error = fmt.Errorf("invalid GOMIPS64: must be hardfloat, softfloat")
return defaultGOMIPS64
return DefaultGOMIPS64
}

func goppc64() int {
switch v := envOr("GOPPC64", defaultGOPPC64); v {
switch v := envOr("GOPPC64", DefaultGOPPC64); v {
case "power8":
return 8
case "power9":
Expand All @@ -256,18 +256,18 @@ func goppc64() int {
return 10
}
Error = fmt.Errorf("invalid GOPPC64: must be power8, power9, power10")
return int(defaultGOPPC64[len("power")] - '0')
return int(DefaultGOPPC64[len("power")] - '0')
}

func goriscv64() int {
switch v := envOr("GORISCV64", defaultGORISCV64); v {
switch v := envOr("GORISCV64", DefaultGORISCV64); v {
case "rva20u64":
return 20
case "rva22u64":
return 22
}
Error = fmt.Errorf("invalid GORISCV64: must be rva20u64, rva22u64")
v := defaultGORISCV64[len("rva"):]
v := DefaultGORISCV64[len("rva"):]
i := strings.IndexFunc(v, func(r rune) bool {
return r < '0' || r > '9'
})
Expand Down

0 comments on commit 5461498

Please sign in to comment.