mirror of
https://github.com/github/codeql.git
synced 2026-04-27 09:45:15 +02:00
Go: Replace exec.Command("go" with toolchain.GoCommand(
This commit is contained in:
@@ -67,13 +67,13 @@ func restoreRepoLayout(fromDir string, dirEntries []string, scratchDirName strin
|
||||
|
||||
// addVersionToMod add a go version directive, e.g. `go 1.14` to a `go.mod` file.
|
||||
func addVersionToMod(version string) bool {
|
||||
cmd := exec.Command("go", "mod", "edit", "-go="+version)
|
||||
cmd := toolchain.GoCommand("mod", "edit", "-go="+version)
|
||||
return util.RunCmd(cmd)
|
||||
}
|
||||
|
||||
// checkVendor tests to see whether a vendor directory is inconsistent according to the go frontend
|
||||
func checkVendor() bool {
|
||||
vendorCheckCmd := exec.Command("go", "list", "-mod=vendor", "./...")
|
||||
vendorCheckCmd := toolchain.GoCommand("list", "-mod=vendor", "./...")
|
||||
outp, err := vendorCheckCmd.CombinedOutput()
|
||||
if err != nil {
|
||||
badVendorRe := regexp.MustCompile(`(?m)^go: inconsistent vendoring in .*:$`)
|
||||
@@ -438,7 +438,7 @@ func installDependencies(workspace project.GoWorkspace) {
|
||||
util.RunCmd(vendor)
|
||||
}
|
||||
|
||||
install = exec.Command("go", "get", "-v", "./...")
|
||||
install = toolchain.GoCommand("get", "-v", "./...")
|
||||
install.Dir = path
|
||||
log.Printf("Installing dependencies using `go get -v ./...` in `%s`.\n", path)
|
||||
util.RunCmd(install)
|
||||
|
||||
@@ -137,9 +137,14 @@ func SupportsWorkspaces() bool {
|
||||
return GetEnvGoSemVer().IsAtLeast(V1_18)
|
||||
}
|
||||
|
||||
// Constructs a `*exec.Cmd` for `go` with the specified arguments.
|
||||
func GoCommand(arg ...string) *exec.Cmd {
|
||||
return exec.Command("go", arg...)
|
||||
}
|
||||
|
||||
// Run `go mod tidy -e` in the directory given by `path`.
|
||||
func TidyModule(path string) *exec.Cmd {
|
||||
cmd := exec.Command("go", "mod", "tidy", "-e")
|
||||
cmd := GoCommand("mod", "tidy", "-e")
|
||||
cmd.Dir = path
|
||||
return cmd
|
||||
}
|
||||
@@ -159,21 +164,21 @@ func InitModule(path string) *exec.Cmd {
|
||||
}
|
||||
}
|
||||
|
||||
modInit := exec.Command("go", "mod", "init", moduleName)
|
||||
modInit := GoCommand("mod", "init", moduleName)
|
||||
modInit.Dir = path
|
||||
return modInit
|
||||
}
|
||||
|
||||
// Constructs a command to run `go mod vendor -e` in the directory given by `path`.
|
||||
func VendorModule(path string) *exec.Cmd {
|
||||
modVendor := exec.Command("go", "mod", "vendor", "-e")
|
||||
modVendor := GoCommand("mod", "vendor", "-e")
|
||||
modVendor.Dir = path
|
||||
return modVendor
|
||||
}
|
||||
|
||||
// Constructs a command to run `go version`.
|
||||
func Version() *exec.Cmd {
|
||||
version := exec.Command("go", "version")
|
||||
version := GoCommand("version")
|
||||
return version
|
||||
}
|
||||
|
||||
@@ -209,7 +214,7 @@ func RunListWithEnv(format string, patterns []string, additionalEnv []string, fl
|
||||
func ListWithEnv(format string, patterns []string, additionalEnv []string, flags ...string) *exec.Cmd {
|
||||
args := append([]string{"list", "-e", "-f", format}, flags...)
|
||||
args = append(args, patterns...)
|
||||
cmd := exec.Command("go", args...)
|
||||
cmd := GoCommand(args...)
|
||||
cmd.Env = append(os.Environ(), additionalEnv...)
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user