File tree Expand file tree Collapse file tree 3 files changed +22
-9
lines changed
Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments