Skip to content

Commit f154f9f

Browse files
dagoodgdams
authored andcommitted
Also unassign GOROOT in run-builder
1 parent 128a598 commit f154f9f

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

eng/_util/buildutil/buildutil.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,19 @@ func AppendExperimentEnv(experiment string) {
104104
panic(err)
105105
}
106106
}
107+
108+
// UnassignGOROOT unsets the GOROOT env var if it is set.
109+
//
110+
// Setting GOROOT explicitly in the environment has not been necessary since Go
111+
// 1.9 (https://go.dev/doc/go1.9#goroot), but a dev or build machine may still
112+
// have it set. It interferes with attempts to run the built Go (such as when
113+
// building the race runtime), so remove the explicit GOROOT if set.
114+
func UnassignGOROOT() error {
115+
if explicitRoot, ok := os.LookupEnv("GOROOT"); ok {
116+
fmt.Printf("---- Removing explicit GOROOT from environment: %v\n", explicitRoot)
117+
if err := os.Unsetenv("GOROOT"); err != nil {
118+
return err
119+
}
120+
}
121+
return nil
122+
}

eng/_util/cmd/build/build.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,8 @@ func build(o *options) error {
138138
}
139139
fmt.Printf("---- Target platform: %v_%v\n", targetOS, targetArch)
140140

141-
// Setting GOROOT explicitly in the environment has not been necessary since Go 1.9
142-
// (https://go.dev/doc/go1.9#goroot), but a dev or build machine may still have it set. It
143-
// interferes with attempts to run the built Go (such as when building the race runtime), so
144-
// remove the explicit GOROOT if set.
145-
if explicitRoot, ok := os.LookupEnv("GOROOT"); ok {
146-
fmt.Printf("---- Removing explicit GOROOT from environment: %v\n", explicitRoot)
147-
if err := os.Unsetenv("GOROOT"); err != nil {
148-
return err
149-
}
141+
if err := buildutil.UnassignGOROOT(); err != nil {
142+
return err
150143
}
151144

152145
// The upstream build scripts in {repo-root}/src require your working directory to be src, or

eng/_util/cmd/run-builder/run-builder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ func main() {
105105
env("GO_TEST_TIMEOUT_SCALE", strconv.Itoa(timeoutScale))
106106
}
107107

108+
if err := buildutil.UnassignGOROOT(); err != nil {
109+
log.Fatal(err)
110+
}
111+
108112
buildCmdline := []string{"pwsh", "eng/run.ps1", "build"}
109113

110114
// run.ps1 compiles Go code, so we can't use the experiment yet. We must pass the experiment

0 commit comments

Comments
 (0)