File tree Expand file tree Collapse file tree 3 files changed +10
-9
lines changed Expand file tree Collapse file tree 3 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -154,8 +154,7 @@ func getNeedGopath(workspace project.GoWorkspace, importpath string) bool {
154154// Try to update `go.mod` and `go.sum` if the go version is >= 1.16.
155155func tryUpdateGoModAndGoSum (workspace project.GoWorkspace ) {
156156 // Go 1.16 and later won't automatically attempt to update go.mod / go.sum during package loading, so try to update them here:
157- v1_16 := util .NewSemVer ("v1.16" )
158- if workspace .ModMode != project .ModVendor && workspace .DepMode == project .GoGetWithModules && toolchain .GetEnvGoSemVer ().IsAtLeast (v1_16 ) {
157+ if workspace .ModMode != project .ModVendor && workspace .DepMode == project .GoGetWithModules && toolchain .GetEnvGoSemVer ().IsAtLeast (toolchain .V1_16 ) {
159158 for _ , goMod := range workspace .Modules {
160159 // stat go.mod and go.sum
161160 goModPath := goMod .Path
@@ -541,8 +540,7 @@ func installDependenciesAndBuild() {
541540
542541 // This diagnostic is not required if the system Go version is 1.21 or greater, since the
543542 // Go tooling should install required Go versions as needed.
544- v1_21 := util .NewSemVer ("v1.21.0" )
545- if toolchain .GetEnvGoSemVer ().IsOlderThan (v1_21 ) && greatestGoVersion != nil && greatestGoVersion .IsNewerThan (toolchain .GetEnvGoSemVer ()) {
543+ if toolchain .GetEnvGoSemVer ().IsOlderThan (toolchain .V1_21 ) && greatestGoVersion != nil && greatestGoVersion .IsNewerThan (toolchain .GetEnvGoSemVer ()) {
546544 diagnostics .EmitNewerGoVersionNeeded (toolchain .GetEnvGoSemVer ().String (), greatestGoVersion .String ())
547545 if val , _ := os .LookupEnv ("GITHUB_ACTIONS" ); val == "true" {
548546 log .Printf (
Original file line number Diff line number Diff line change @@ -175,9 +175,8 @@ var toolchainVersionRe *regexp.Regexp = regexp.MustCompile(`(?m)^([0-9]+\.[0-9]+
175175// Returns true if the `go.mod` file specifies a Go language version, that version is `1.21` or greater, and
176176// there is no `toolchain` directive, and the Go language version is not a valid toolchain version.
177177func hasInvalidToolchainVersion (modFile * modfile.File ) bool {
178- v1_21 := util .NewSemVer ("v1.21.0" )
179178 return modFile .Toolchain == nil && modFile .Go != nil &&
180- ! toolchainVersionRe .Match ([]byte (modFile .Go .Version )) && util .NewSemVer (modFile .Go .Version ).IsAtLeast (v1_21 )
179+ ! toolchainVersionRe .Match ([]byte (modFile .Go .Version )) && util .NewSemVer (modFile .Go .Version ).IsAtLeast (toolchain . V1_21 )
181180}
182181
183182// Given a list of `go.mod` file paths, try to parse them all. The resulting array of `GoModule` objects
@@ -538,8 +537,7 @@ func (m ModMode) ArgsForGoVersion(version util.SemVer) []string {
538537 case ModReadonly :
539538 return []string {"-mod=readonly" }
540539 case ModMod :
541- v1_14 := util .NewSemVer ("v1.14" )
542- if version .IsOlderThan (v1_14 ) {
540+ if version .IsOlderThan (toolchain .V1_14 ) {
543541 return []string {} // -mod=mod is the default behaviour for go <= 1.13, and is not accepted as an argument
544542 } else {
545543 return []string {"-mod=mod" }
Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ import (
1313 "github.com/github/codeql-go/extractor/util"
1414)
1515
16+ var V1_14 = util .NewSemVer ("v1.14.0" )
17+ var V1_16 = util .NewSemVer ("v1.16.0" )
18+ var V1_18 = util .NewSemVer ("v1.18.0" )
19+ var V1_21 = util .NewSemVer ("v1.21.0" )
20+
1621// Check if Go is installed in the environment.
1722func IsInstalled () bool {
1823 _ , err := exec .LookPath ("go" )
@@ -128,7 +133,7 @@ func parseGoVersion(data string) string {
128133
129134// Returns a value indicating whether the system Go toolchain supports workspaces.
130135func SupportsWorkspaces () bool {
131- return GetEnvGoSemVer ().IsAtLeast (util . NewSemVer ( "v1.18.0" ) )
136+ return GetEnvGoSemVer ().IsAtLeast (V1_18 )
132137}
133138
134139// Run `go mod tidy -e` in the directory given by `path`.
You can’t perform that action at this time.
0 commit comments