mirror of
https://github.com/github/codeql.git
synced 2026-01-29 06:12:58 +01:00
Fix autobuilder Go version comparison
The semver package requires versions of the form v1.2.3, and unhelpfully evaluates any malformed versions as equal.
This commit is contained in:
@@ -47,6 +47,7 @@ variable is 32.
|
||||
|
||||
var goVersion = ""
|
||||
|
||||
// Returns the current Go version as returned by 'go version', e.g. go1.14.4
|
||||
func getEnvGoVersion() string {
|
||||
if goVersion == "" {
|
||||
gover, err := exec.Command("go", "version").CombinedOutput()
|
||||
@@ -58,6 +59,15 @@ func getEnvGoVersion() string {
|
||||
return goVersion
|
||||
}
|
||||
|
||||
// Returns the current Go version in semver format, e.g. v1.14.4
|
||||
func getEnvGoSemVer() string {
|
||||
goVersion := getEnvGoVersion()
|
||||
if !strings.HasPrefix(goVersion, "go") {
|
||||
log.Fatalf("Expected 'go version' output of the form 'go1.2.3'; got '%s'", goVersion)
|
||||
}
|
||||
return "v" + goVersion[2:]
|
||||
}
|
||||
|
||||
func run(cmd *exec.Cmd) bool {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
@@ -164,11 +174,12 @@ func (m ModMode) argsForGoVersion(version string) []string {
|
||||
case ModReadonly:
|
||||
return []string{"-mod=readonly"}
|
||||
case ModMod:
|
||||
if semver.Compare(getEnvGoVersion(), "1.14") < 0 {
|
||||
log.Printf("%s < %s", getEnvGoVersion(), "1.14")
|
||||
if !semver.IsValid(version) {
|
||||
log.Fatalf("Invalid Go semver: '%s'", version)
|
||||
}
|
||||
if semver.Compare(version, "v1.14") < 0 {
|
||||
return []string{} // -mod=mod is the default behaviour for go <= 1.13, and is not accepted as an argument
|
||||
} else {
|
||||
log.Printf("%s >= %s", getEnvGoVersion(), "1.14")
|
||||
return []string{"-mod=mod"}
|
||||
}
|
||||
case ModVendor:
|
||||
@@ -505,7 +516,7 @@ func main() {
|
||||
|
||||
extractorArgs := []string{}
|
||||
if depMode == GoGetWithModules {
|
||||
extractorArgs = append(extractorArgs, modMode.argsForGoVersion(getEnvGoVersion())...)
|
||||
extractorArgs = append(extractorArgs, modMode.argsForGoVersion(getEnvGoSemVer())...)
|
||||
}
|
||||
extractorArgs = append(extractorArgs, "./...")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user