Skip to content

Commit 69b87a6

Browse files
author
Paolo Tranquilli
committed
Go: remove invalid toolchain version diagnostics
This diagnostic was introduced by #15979. However in the meantime the Go team [has backtracked](golang/go#62278 (comment)) on their decision, which leads to confusing alerts for user (e.g. github/codeql-action#2868). Even using Go toolchains from 1.21 to 1.22 we weren't immediately able to reproduce the problem that this diagnostics was meant to guard against. Therefore it was deemed simpler to just remove it. _En passant_ the `Makefile` now accepts `rtjo` not being set.
1 parent ea83ecf commit 69b87a6

File tree

12 files changed

+11
-155
lines changed

12 files changed

+11
-155
lines changed

go/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# and that we actually get are too big, the build fails on CI.
66
BAZEL := $(shell bash -c "which bazel")
77

8+
rtjo ?= none
9+
810
all: gen extractor
911

1012
EXTRACTOR_PACK_OUT = extractor-pack

go/extractor/cli/go-autobuilder/go-autobuilder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func installDependencies(workspace project.GoWorkspace) {
425425
} else {
426426
if workspace.Modules == nil {
427427
project.InitGoModForLegacyProject(workspace.BaseDir)
428-
workspace.Modules = project.LoadGoModules(true, []string{filepath.Join(workspace.BaseDir, "go.mod")})
428+
workspace.Modules = project.LoadGoModules([]string{filepath.Join(workspace.BaseDir, "go.mod")})
429429
}
430430

431431
// get dependencies for all modules

go/extractor/diagnostics/diagnostics.go

-15
Original file line numberDiff line numberDiff line change
@@ -508,18 +508,3 @@ func EmitExtractionFailedForProjects(path []string) {
508508
noLocation,
509509
)
510510
}
511-
512-
func EmitInvalidToolchainVersion(goModPath string, version string) {
513-
emitDiagnostic(
514-
"go/autobuilder/invalid-go-toolchain-version",
515-
"Invalid Go toolchain version",
516-
strings.Join([]string{
517-
"As of Go 1.21, toolchain versions [must use the 1.N.P syntax](https://go.dev/doc/toolchain#version).",
518-
fmt.Sprintf("`%s` in `%s` does not match this syntax and there is no additional `toolchain` directive, which may cause some `go` commands to fail.", version, goModPath),
519-
},
520-
"\n\n"),
521-
severityWarning,
522-
fullVisibility,
523-
&locationStruct{File: goModPath},
524-
)
525-
}

go/extractor/project/project.go

+8-26
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,10 @@ func findGoModFiles(root string) []string {
192192
return util.FindAllFilesWithName(root, "go.mod", util.SkipVendorChecks...)
193193
}
194194

195-
// A regular expression for the Go toolchain version syntax.
196-
var toolchainVersionRe *regexp.Regexp = regexp.MustCompile(`(?m)^([0-9]+\.[0-9]+(\.[0-9]+|rc[0-9]+))$`)
197-
198-
// Returns true if the `go.mod` file specifies a Go language version, that version is `1.21` or greater, and
199-
// there is no `toolchain` directive, and the Go language version is not a valid toolchain version.
200-
func hasInvalidToolchainVersion(modFile *modfile.File) bool {
201-
return modFile.Toolchain == nil && modFile.Go != nil &&
202-
!toolchainVersionRe.Match([]byte(modFile.Go.Version)) && util.NewSemVer(modFile.Go.Version).IsAtLeast(toolchain.V1_21)
203-
}
204-
205195
// Given a list of `go.mod` file paths, try to parse them all. The resulting array of `GoModule` objects
206196
// will be the same length as the input array and the objects will contain at least the `go.mod` path.
207197
// If parsing the corresponding file is successful, then the parsed contents will also be available.
208-
func LoadGoModules(emitDiagnostics bool, goModFilePaths []string) []*GoModule {
198+
func LoadGoModules(goModFilePaths []string) []*GoModule {
209199
results := make([]*GoModule, len(goModFilePaths))
210200

211201
for i, goModFilePath := range goModFilePaths {
@@ -227,14 +217,6 @@ func LoadGoModules(emitDiagnostics bool, goModFilePaths []string) []*GoModule {
227217
}
228218

229219
results[i].Module = modFile
230-
231-
// If this `go.mod` file specifies a Go language version, that version is `1.21` or greater, and
232-
// there is no `toolchain` directive, check that it is a valid Go toolchain version. Otherwise,
233-
// `go` commands which try to download the right version of the Go toolchain will fail. We detect
234-
// this situation and emit a diagnostic.
235-
if hasInvalidToolchainVersion(modFile) {
236-
diagnostics.EmitInvalidToolchainVersion(goModFilePath, modFile.Go.Version)
237-
}
238220
}
239221

240222
return results
@@ -243,7 +225,7 @@ func LoadGoModules(emitDiagnostics bool, goModFilePaths []string) []*GoModule {
243225
// Given a path to a `go.work` file, this function attempts to parse the `go.work` file. If unsuccessful,
244226
// we attempt to discover `go.mod` files within subdirectories of the directory containing the `go.work`
245227
// file ourselves.
246-
func discoverWorkspace(emitDiagnostics bool, workFilePath string) GoWorkspace {
228+
func discoverWorkspace(workFilePath string) GoWorkspace {
247229
log.Printf("Loading %s...\n", workFilePath)
248230
baseDir := filepath.Dir(workFilePath)
249231
workFileSrc, err := os.ReadFile(workFilePath)
@@ -257,7 +239,7 @@ func discoverWorkspace(emitDiagnostics bool, workFilePath string) GoWorkspace {
257239

258240
return GoWorkspace{
259241
BaseDir: baseDir,
260-
Modules: LoadGoModules(emitDiagnostics, goModFilePaths),
242+
Modules: LoadGoModules(goModFilePaths),
261243
DepMode: GoGetWithModules,
262244
ModMode: getModMode(GoGetWithModules, baseDir),
263245
}
@@ -274,7 +256,7 @@ func discoverWorkspace(emitDiagnostics bool, workFilePath string) GoWorkspace {
274256

275257
return GoWorkspace{
276258
BaseDir: baseDir,
277-
Modules: LoadGoModules(emitDiagnostics, goModFilePaths),
259+
Modules: LoadGoModules(goModFilePaths),
278260
DepMode: GoGetWithModules,
279261
ModMode: getModMode(GoGetWithModules, baseDir),
280262
}
@@ -297,7 +279,7 @@ func discoverWorkspace(emitDiagnostics bool, workFilePath string) GoWorkspace {
297279
return GoWorkspace{
298280
BaseDir: baseDir,
299281
WorkspaceFile: workFile,
300-
Modules: LoadGoModules(emitDiagnostics, goModFilePaths),
282+
Modules: LoadGoModules(goModFilePaths),
301283
DepMode: GoGetWithModules,
302284
ModMode: ModReadonly, // Workspaces only support "readonly"
303285
}
@@ -325,7 +307,7 @@ func discoverWorkspaces(emitDiagnostics bool) []GoWorkspace {
325307
for i, goModFile := range goModFiles {
326308
results[i] = GoWorkspace{
327309
BaseDir: filepath.Dir(goModFile),
328-
Modules: LoadGoModules(emitDiagnostics, []string{goModFile}),
310+
Modules: LoadGoModules([]string{goModFile}),
329311
DepMode: GoGetWithModules,
330312
ModMode: getModMode(GoGetWithModules, filepath.Dir(goModFile)),
331313
}
@@ -342,7 +324,7 @@ func discoverWorkspaces(emitDiagnostics bool) []GoWorkspace {
342324

343325
results := make([]GoWorkspace, len(goWorkFiles))
344326
for i, workFilePath := range goWorkFiles {
345-
results[i] = discoverWorkspace(emitDiagnostics, workFilePath)
327+
results[i] = discoverWorkspace(workFilePath)
346328
}
347329

348330
// Add all stray `go.mod` files (i.e. those not referenced by `go.work` files)
@@ -374,7 +356,7 @@ func discoverWorkspaces(emitDiagnostics bool) []GoWorkspace {
374356
log.Printf("Module %s is not referenced by any go.work file; adding it separately.\n", goModFile)
375357
results = append(results, GoWorkspace{
376358
BaseDir: filepath.Dir(goModFile),
377-
Modules: LoadGoModules(emitDiagnostics, []string{goModFile}),
359+
Modules: LoadGoModules([]string{goModFile}),
378360
DepMode: GoGetWithModules,
379361
ModMode: getModMode(GoGetWithModules, filepath.Dir(goModFile)),
380362
})

go/extractor/project/project_test.go

-29
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,6 @@ func parseModFile(t *testing.T, contents string) *modfile.File {
3939
return modFile
4040
}
4141

42-
func testHasInvalidToolchainVersion(t *testing.T, contents string) bool {
43-
return hasInvalidToolchainVersion(parseModFile(t, contents))
44-
}
45-
46-
func TestHasInvalidToolchainVersion(t *testing.T) {
47-
invalid := []string{
48-
"go 1.21\n",
49-
"go 1.22\n",
50-
}
51-
52-
for _, v := range invalid {
53-
if !testHasInvalidToolchainVersion(t, v) {
54-
t.Errorf("Expected testHasInvalidToolchainVersion(\"%s\") to be true, but got false", v)
55-
}
56-
}
57-
58-
valid := []string{
59-
"go 1.20\n",
60-
"go 1.21.1\n",
61-
"go 1.22\n\ntoolchain go1.22.0\n",
62-
}
63-
64-
for _, v := range valid {
65-
if testHasInvalidToolchainVersion(t, v) {
66-
t.Errorf("Expected testHasInvalidToolchainVersion(\"%s\") to be false, but got true", v)
67-
}
68-
}
69-
}
70-
7142
func parseWorkFile(t *testing.T, contents string) *modfile.WorkFile {
7243
workFile, err := modfile.ParseWork("go.work", []byte(contents), nil)
7344

go/ql/integration-tests/diagnostics/invalid-toolchain-version/build_environment.expected

-5
This file was deleted.

go/ql/integration-tests/diagnostics/invalid-toolchain-version/diagnostics.expected

-31
This file was deleted.

go/ql/integration-tests/diagnostics/invalid-toolchain-version/src/go.mod

-3
This file was deleted.

go/ql/integration-tests/diagnostics/invalid-toolchain-version/src/main.go

-5
This file was deleted.

go/ql/integration-tests/diagnostics/invalid-toolchain-version/test.py

-6
This file was deleted.

go/ql/integration-tests/go-version-bump/diagnostics.expected

-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
{
2-
"location": {
3-
"file": "go.mod"
4-
},
5-
"markdownMessage": "As of Go 1.21, toolchain versions [must use the 1.N.P syntax](https://go.dev/doc/toolchain#version).\n\n`1.21` in `go.mod` does not match this syntax and there is no additional `toolchain` directive, which may cause some `go` commands to fail.",
6-
"severity": "warning",
7-
"source": {
8-
"extractorName": "go",
9-
"id": "go/autobuilder/invalid-go-toolchain-version",
10-
"name": "Invalid Go toolchain version"
11-
},
12-
"visibility": {
13-
"cliSummaryTable": true,
14-
"statusPage": true,
15-
"telemetry": true
16-
}
17-
}
181
{
192
"markdownMessage": "A single `go.mod` file was found.\n\n`go.mod`",
203
"severity": "note",

go/ql/integration-tests/resolve-build-environment/newer-go-needed/diagnostics.expected

-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
{
2-
"location": {
3-
"file": "go.mod"
4-
},
5-
"markdownMessage": "As of Go 1.21, toolchain versions [must use the 1.N.P syntax](https://go.dev/doc/toolchain#version).\n\n`1.22` in `go.mod` does not match this syntax and there is no additional `toolchain` directive, which may cause some `go` commands to fail.",
6-
"severity": "warning",
7-
"source": {
8-
"extractorName": "go",
9-
"id": "go/autobuilder/invalid-go-toolchain-version",
10-
"name": "Invalid Go toolchain version"
11-
},
12-
"visibility": {
13-
"cliSummaryTable": true,
14-
"statusPage": true,
15-
"telemetry": true
16-
}
17-
}
181
{
192
"markdownMessage": "A single `go.mod` file was found.\n\n`go.mod`",
203
"severity": "note",

0 commit comments

Comments
 (0)