@@ -48,7 +48,7 @@ func GetEnvGoVersion() string {
4848 // Go version in tests and also allows users to override the system default more generally.
4949 _ , hasToolchainVar := os .LookupEnv ("GOTOOLCHAIN" )
5050 if ! hasToolchainVar {
51- cmd .Env = append ( os . Environ (), "GOTOOLCHAIN=local" )
51+ cmd .AppendEnv ( "GOTOOLCHAIN=local" )
5252 }
5353
5454 out , err := cmd .CombinedOutput ()
@@ -82,10 +82,10 @@ func InstallVersion(workingDir string, version util.SemVer) bool {
8282 // should then work even with an invalid version that's still in `go.mod`
8383 toolchainArg := "GOTOOLCHAIN=go" + version .String ()[1 :]
8484 versionCmd := Version ()
85- versionCmd .Dir = workingDir
86- versionCmd .Env = append ( os . Environ (), toolchainArg )
87- versionCmd .Stdout = os .Stdout
88- versionCmd .Stderr = os .Stderr
85+ versionCmd .SetDir ( workingDir )
86+ versionCmd .AppendEnv ( toolchainArg )
87+ versionCmd .SetStdout ( os .Stdout )
88+ versionCmd .SetStderr ( os .Stderr )
8989
9090 log .Printf (
9191 "Trying to install Go %s using its canonical representation in `%s`." ,
@@ -99,7 +99,7 @@ func InstallVersion(workingDir string, version util.SemVer) bool {
9999 log .Printf (
100100 "Failed to invoke `%s go version` in %s: %s\n " ,
101101 toolchainArg ,
102- versionCmd . Dir ,
102+ workingDir ,
103103 versionErr .Error (),
104104 )
105105
@@ -145,21 +145,20 @@ func SupportsWorkspaces() bool {
145145}
146146
147147// Constructs a `*exec.Cmd` for `go` with the specified arguments.
148- func GoCommand (arg ... string ) * exec.Cmd {
149- cmd := exec .Command ("go" , arg ... )
150- registries .ApplyProxyEnvVars (cmd )
148+ func GoCommand (arg ... string ) * registries.ProxiedCmd {
149+ cmd := registries .Command ("go" , arg ... )
151150 return cmd
152151}
153152
154153// Run `go mod tidy -e` in the directory given by `path`.
155- func TidyModule (path string ) * exec. Cmd {
154+ func TidyModule (path string ) * registries. ProxiedCmd {
156155 cmd := GoCommand ("mod" , "tidy" , "-e" )
157- cmd .Dir = path
156+ cmd .SetDir ( path )
158157 return cmd
159158}
160159
161160// Run `go mod init` in the directory given by `path`.
162- func InitModule (path string ) * exec. Cmd {
161+ func InitModule (path string ) * registries. ProxiedCmd {
163162 moduleName := "codeql/auto-project"
164163
165164 if importpath := util .GetImportPath (); importpath != "" {
@@ -174,19 +173,19 @@ func InitModule(path string) *exec.Cmd {
174173 }
175174
176175 modInit := GoCommand ("mod" , "init" , moduleName )
177- modInit .Dir = path
176+ modInit .SetDir ( path )
178177 return modInit
179178}
180179
181180// Constructs a command to run `go mod vendor -e` in the directory given by `path`.
182- func VendorModule (path string ) * exec. Cmd {
181+ func VendorModule (path string ) * registries. ProxiedCmd {
183182 modVendor := GoCommand ("mod" , "vendor" , "-e" )
184- modVendor .Dir = path
183+ modVendor .SetDir ( path )
185184 return modVendor
186185}
187186
188187// Constructs a command to run `go version`.
189- func Version () * exec. Cmd {
188+ func Version () * registries. ProxiedCmd {
190189 version := GoCommand ("version" )
191190 return version
192191}
@@ -197,7 +196,7 @@ func RunList(format string, patterns []string, flags ...string) (string, error)
197196}
198197
199198// Constructs a `go list` command with `format`, `patterns`, and `flags` for the respective inputs.
200- func List (format string , patterns []string , flags ... string ) * exec. Cmd {
199+ func List (format string , patterns []string , flags ... string ) * registries. ProxiedCmd {
201200 return ListWithEnv (format , patterns , nil , flags ... )
202201}
203202
@@ -220,11 +219,11 @@ func RunListWithEnv(format string, patterns []string, additionalEnv []string, fl
220219
221220// Constructs a `go list` command with `format`, `patterns`, and `flags` for the respective inputs
222221// and the extra environment variables given by `additionalEnv`.
223- func ListWithEnv (format string , patterns []string , additionalEnv []string , flags ... string ) * exec. Cmd {
222+ func ListWithEnv (format string , patterns []string , additionalEnv []string , flags ... string ) * registries. ProxiedCmd {
224223 args := append ([]string {"list" , "-e" , "-f" , format }, flags ... )
225224 args = append (args , patterns ... )
226225 cmd := GoCommand (args ... )
227- cmd .Env = append ( os . Environ (), additionalEnv ... )
226+ cmd .AppendEnv ( additionalEnv ... )
228227 return cmd
229228}
230229
0 commit comments