Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c8744c5

Browse files
committedMay 7, 2024··
n
Change-Id: Iabbb564b16abf1be55280d39152155f6748ec5fb
1 parent a7a7804 commit c8744c5

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed
 

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ var (
103103
// explanation why GOPATH is unset.
104104
GoPathError string
105105
GOPATHChanged bool
106+
CGOChanged bool
106107
)
107108

108109
func defaultContext() build.Context {
@@ -131,7 +132,7 @@ func defaultContext() build.Context {
131132
// 3. Otherwise, use built-in default for GOOS/GOARCH.
132133
// Recreate that logic here with the new GOOS/GOARCH setting.
133134
if v := Getenv("CGO_ENABLED"); v == "0" || v == "1" {
134-
ctxt.CgoEnabled = v[0] == '1'
135+
ctxt.CgoEnabled, CGOChanged = v[0] == '1', v[0] != '0'
135136
} else if ctxt.GOOS != runtime.GOOS || ctxt.GOARCH != runtime.GOARCH {
136137
ctxt.CgoEnabled = false
137138
} else {
@@ -411,7 +412,7 @@ var (
411412
GOMIPS, goMIPSChanged = EnvOrAndChanged("GOMIPS", buildcfg.GOMIPS)
412413
GOMIPS64, goMIPS64Changed = EnvOrAndChanged("GOMIPS64", buildcfg.GOMIPS64)
413414
GOPPC64, goPPC64Changed = EnvOrAndChanged("GOPPC64", fmt.Sprintf("%s%d", "power", buildcfg.GOPPC64))
414-
GORISCV64, gORISCV64Changed = EnvOrAndChanged("GORISCV64", fmt.Sprintf("rva%du64", buildcfg.GORISCV64))
415+
GORISCV64, goRISCV64Changed = EnvOrAndChanged("GORISCV64", fmt.Sprintf("rva%du64", buildcfg.GORISCV64))
415416
GOWASM, goWASMChanged = EnvOrAndChanged("GOWASM", fmt.Sprint(buildcfg.GOWASM))
416417

417418
GOPROXY, GOPROXYChanged = EnvOrAndChanged("GOPROXY", "")
@@ -456,7 +457,7 @@ func GetArchEnv() (key, val string, changed bool) {
456457
case "ppc64", "ppc64le":
457458
return "GOPPC64", GOPPC64, goPPC64Changed
458459
case "riscv64":
459-
return "GORISCV64", GORISCV64, gORISCV64Changed
460+
return "GORISCV64", GORISCV64, goRISCV64Changed
460461
case "wasm":
461462
return "GOWASM", GOWASM, goWASMChanged
462463
}

‎src/cmd/go/internal/envcmd/env.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ func MkEnv() []cfg.EnvVar {
162162
env = append(env, cfg.EnvVar{Name: "CXX", Value: cxx, Changed: cxxChanged})
163163

164164
if cfg.BuildContext.CgoEnabled {
165-
env = append(env, cfg.EnvVar{Name: "CGO_ENABLED", Value: "1", Changed: true})
165+
env = append(env, cfg.EnvVar{Name: "CGO_ENABLED", Value: "1", Changed: cfg.CGOChanged})
166166
} else {
167-
env = append(env, cfg.EnvVar{Name: "CGO_ENABLED", Value: "0"})
167+
env = append(env, cfg.EnvVar{Name: "CGO_ENABLED", Value: "0", Changed: cfg.CGOChanged})
168168
}
169169

170170
return env

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ env CGO_CPPFLAGS=nodefault
1010
go env -changed
1111
# linux output like GOTOOLCHAIN='local'
1212
# windows output like GOTOOLCHAIN=local
13-
stdout 'GOTOOLCHAIN=local|GOTOOLCHAIN=''local'''
14-
stdout 'GOSUMDB=nodefault|GOSUMDB=''nodefault'''
15-
stdout 'GOPROXY=nodefault|GOPROXY=''nodefault'''
16-
stdout 'GO111MODULE=auto|GO111MODULE=''auto'''
17-
stdout 'CGO_CFLAGS=nodefault|CGO_CFLAGS=''nodefault'''
18-
stdout 'CGO_CPPFLAGS=nodefault|CGO_CPPFLAGS=''nodefault'''
13+
stdout 'GOTOOLCHAIN=''?local''?'
14+
stdout 'GOSUMDB=''?nodefault''?'
15+
stdout 'GOPROXY=''?nodefault''?'
16+
stdout 'GO111MODULE=''?auto''?'
17+
stdout 'CGO_CFLAGS=''?nodefault''?'
18+
stdout 'CGO_CPPFLAGS=''?nodefault''?'
1919

2020
go env -changed -json
2121
stdout '"GOTOOLCHAIN": "local"'

‎src/go/build/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func (ctxt *Context) SrcDirs() []string {
286286
// if set, or else the compiled code's GOARCH, GOOS, and GOROOT.
287287
var Default Context = defaultContext()
288288

289-
// defaultGOPATH now semantics are actually the same in cmd/go/internal/cfg.gopath.
289+
// Keep consistent with cmd/go/internal/cfg.defaultGOPATH.
290290
func defaultGOPATH() string {
291291
env := "HOME"
292292
if runtime.GOOS == "windows" {

‎src/go/build/deps_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var depsRules = `
4040
# No dependencies allowed for any of these packages.
4141
NONE
4242
< cmp, container/list, container/ring,
43-
internal/coverage, internal/coverage/rtcov,
43+
internal/cfg, internal/coverage, internal/coverage/rtcov,
4444
internal/coverage/uleb128, internal/coverage/calloc,
4545
internal/cpu, internal/goarch, internal/godebugs,
4646
internal/goexperiment, internal/goos,
@@ -323,9 +323,7 @@ var depsRules = `
323323
go/doc/comment, go/parser, internal/lazyregexp, text/template
324324
< go/doc;
325325
326-
os, path/filepath, runtime < internal/cfg;
327-
328-
go/build/constraint, go/doc, go/parser, internal/buildcfg, internal/goroot, internal/goversion, internal/platform, internal/cfg
326+
go/build/constraint, go/doc, go/parser, internal/buildcfg, internal/goroot, internal/goversion, internal/platform
329327
< go/build;
330328
331329
# databases

0 commit comments

Comments
 (0)