Skip to content

Commit cce90c1

Browse files
qiulaidongfengmatloob
authored andcommitted
cmd/go: print not-defaults arch-env
Fixes #67492 For #34208 Change-Id: Idcddf88aad8e18b0274ce8e2ff8a83d57db603a6 GitHub-Last-Rev: 8ef7cf5 GitHub-Pull-Request: #67493 Reviewed-on: https://go-review.googlesource.com/c/go/+/586241 Reviewed-by: David Chase <[email protected]> Reviewed-by: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 3f0b293 commit cce90c1

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

src/cmd/dist/buildruntime.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ func mkbuildcfg(file string) {
5151
fmt.Fprintln(&buf)
5252
fmt.Fprintf(&buf, "import \"runtime\"\n")
5353
fmt.Fprintln(&buf)
54-
fmt.Fprintf(&buf, "const defaultGO386 = `%s`\n", go386)
55-
fmt.Fprintf(&buf, "const defaultGOAMD64 = `%s`\n", goamd64)
56-
fmt.Fprintf(&buf, "const defaultGOARM = `%s`\n", goarm)
57-
fmt.Fprintf(&buf, "const defaultGOARM64 = `%s`\n", goarm64)
58-
fmt.Fprintf(&buf, "const defaultGOMIPS = `%s`\n", gomips)
59-
fmt.Fprintf(&buf, "const defaultGOMIPS64 = `%s`\n", gomips64)
60-
fmt.Fprintf(&buf, "const defaultGOPPC64 = `%s`\n", goppc64)
61-
fmt.Fprintf(&buf, "const defaultGORISCV64 = `%s`\n", goriscv64)
54+
fmt.Fprintf(&buf, "const DefaultGO386 = `%s`\n", go386)
55+
fmt.Fprintf(&buf, "const DefaultGOAMD64 = `%s`\n", goamd64)
56+
fmt.Fprintf(&buf, "const DefaultGOARM = `%s`\n", goarm)
57+
fmt.Fprintf(&buf, "const DefaultGOARM64 = `%s`\n", goarm64)
58+
fmt.Fprintf(&buf, "const DefaultGOMIPS = `%s`\n", gomips)
59+
fmt.Fprintf(&buf, "const DefaultGOMIPS64 = `%s`\n", gomips64)
60+
fmt.Fprintf(&buf, "const DefaultGOPPC64 = `%s`\n", goppc64)
61+
fmt.Fprintf(&buf, "const DefaultGORISCV64 = `%s`\n", goriscv64)
6262
fmt.Fprintf(&buf, "const defaultGOEXPERIMENT = `%s`\n", goexperiment)
6363
fmt.Fprintf(&buf, "const defaultGO_EXTLINK_ENABLED = `%s`\n", goextlinkenabled)
6464
fmt.Fprintf(&buf, "const defaultGO_LDSO = `%s`\n", defaultldso)

src/cmd/go/internal/cfg/cfg.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,14 @@ var (
416416
GOMODCACHE, GOMODCACHEChanged = EnvOrAndChanged("GOMODCACHE", gopathDir("pkg/mod"))
417417

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

429429
GOPROXY, GOPROXYChanged = EnvOrAndChanged("GOPROXY", "")

src/cmd/go/testdata/script/env_changed.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ go env -changed -json GOARCH
4545
[GOARCH:amd64] stdout '"GOARCH": "arm64"'
4646
[!GOARCH:amd64] stdout '"GOARCH": "amd64"'
4747

48+
env GOARCH=amd64
49+
env GOAMD64=v3
50+
go env -changed
51+
stdout 'GOAMD64=''?v3''?'
52+
4853
env GOPROXY=s
4954
go env -changed GOPROXY
5055
! stdout 'GOPROXY'
@@ -58,6 +63,7 @@ go env -changed
5863

5964
-- a/go.env --
6065
GOPROXY=s
66+
GOAMD64=v1
6167

6268
-- b/go.env --
6369
GOTOOLCHAIN=local

src/internal/buildcfg/cfg.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var (
2323
GOROOT = os.Getenv("GOROOT") // cached for efficiency
2424
GOARCH = envOr("GOARCH", defaultGOARCH)
2525
GOOS = envOr("GOOS", defaultGOOS)
26-
GO386 = envOr("GO386", defaultGO386)
26+
GO386 = envOr("GO386", DefaultGO386)
2727
GOAMD64 = goamd64()
2828
GOARM = goarm()
2929
GOARM64 = goarm64()
@@ -56,7 +56,7 @@ func envOr(key, value string) string {
5656
}
5757

5858
func goamd64() int {
59-
switch v := envOr("GOAMD64", defaultGOAMD64); v {
59+
switch v := envOr("GOAMD64", DefaultGOAMD64); v {
6060
case "v1":
6161
return 1
6262
case "v2":
@@ -67,7 +67,7 @@ func goamd64() int {
6767
return 4
6868
}
6969
Error = fmt.Errorf("invalid GOAMD64: must be v1, v2, v3, v4")
70-
return int(defaultGOAMD64[len("v")] - '0')
70+
return int(DefaultGOAMD64[len("v")] - '0')
7171
}
7272

7373
type GoarmFeatures struct {
@@ -90,7 +90,7 @@ func goarm() (g GoarmFeatures) {
9090
softFloatOpt = ",softfloat"
9191
hardFloatOpt = ",hardfloat"
9292
)
93-
def := defaultGOARM
93+
def := DefaultGOARM
9494
if GOOS == "android" && GOARCH == "arm" {
9595
// Android arm devices always support GOARM=7.
9696
def = "7"
@@ -186,14 +186,14 @@ func ParseGoarm64(v string) (g Goarm64Features, e error) {
186186
default:
187187
e = fmt.Errorf("invalid GOARM64: must start with v8.{0-9} or v9.{0-5} and may optionally end in %q and/or %q",
188188
lseOpt, cryptoOpt)
189-
g.Version = defaultGOARM64
189+
g.Version = DefaultGOARM64
190190
}
191191

192192
return
193193
}
194194

195195
func goarm64() (g Goarm64Features) {
196-
g, Error = ParseGoarm64(envOr("GOARM64", defaultGOARM64))
196+
g, Error = ParseGoarm64(envOr("GOARM64", DefaultGOARM64))
197197
return
198198
}
199199

@@ -229,25 +229,25 @@ func (g Goarm64Features) Supports(s string) bool {
229229
}
230230

231231
func gomips() string {
232-
switch v := envOr("GOMIPS", defaultGOMIPS); v {
232+
switch v := envOr("GOMIPS", DefaultGOMIPS); v {
233233
case "hardfloat", "softfloat":
234234
return v
235235
}
236236
Error = fmt.Errorf("invalid GOMIPS: must be hardfloat, softfloat")
237-
return defaultGOMIPS
237+
return DefaultGOMIPS
238238
}
239239

240240
func gomips64() string {
241-
switch v := envOr("GOMIPS64", defaultGOMIPS64); v {
241+
switch v := envOr("GOMIPS64", DefaultGOMIPS64); v {
242242
case "hardfloat", "softfloat":
243243
return v
244244
}
245245
Error = fmt.Errorf("invalid GOMIPS64: must be hardfloat, softfloat")
246-
return defaultGOMIPS64
246+
return DefaultGOMIPS64
247247
}
248248

249249
func goppc64() int {
250-
switch v := envOr("GOPPC64", defaultGOPPC64); v {
250+
switch v := envOr("GOPPC64", DefaultGOPPC64); v {
251251
case "power8":
252252
return 8
253253
case "power9":
@@ -256,18 +256,18 @@ func goppc64() int {
256256
return 10
257257
}
258258
Error = fmt.Errorf("invalid GOPPC64: must be power8, power9, power10")
259-
return int(defaultGOPPC64[len("power")] - '0')
259+
return int(DefaultGOPPC64[len("power")] - '0')
260260
}
261261

262262
func goriscv64() int {
263-
switch v := envOr("GORISCV64", defaultGORISCV64); v {
263+
switch v := envOr("GORISCV64", DefaultGORISCV64); v {
264264
case "rva20u64":
265265
return 20
266266
case "rva22u64":
267267
return 22
268268
}
269269
Error = fmt.Errorf("invalid GORISCV64: must be rva20u64, rva22u64")
270-
v := defaultGORISCV64[len("rva"):]
270+
v := DefaultGORISCV64[len("rva"):]
271271
i := strings.IndexFunc(v, func(r rune) bool {
272272
return r < '0' || r > '9'
273273
})

0 commit comments

Comments
 (0)