-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go: Update autobuilder to deal with the upcoming deprecation of the legacy GOPATH mode #15361
Conversation
I think we should check there aren't go.mod files inside the proposed root dir before doing this -- otherwise the strategy you described of running |
45c349a
to
4ad0e0f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would benefit from a block comment or a short doc outlining the different scenarios you hope to deal with and how you want to deal with them -- that would make it clearer if there are any cases not accounted for
for i, use := range workFile.Use { | ||
if filepath.IsAbs(use.Path) { | ||
// TODO: This case might be problematic for some other logic (e.g. stray file detection) | ||
goModFilePaths[i] = filepath.Join(use.Path, "go.mod") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check is under baseDir?
// TODO: This case might be problematic for some other logic (e.g. stray file detection) | ||
goModFilePaths[i] = filepath.Join(use.Path, "go.mod") | ||
} else { | ||
goModFilePaths[i] = filepath.Join(filepath.Dir(workFilePath), use.Path, "go.mod") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check is under baseDir?
1a2e829
to
6d4a31d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks plausible. Would still benefit from writing down explicitly what you intend to happen in odd cases, like stray go files outside modules (I think you're creating a new module at the repository root in this case?)
ef4c1cd
to
021cf80
Compare
021cf80
to
8ef53f4
Compare
The corresponding integration test now successfully extracts the project
8ef53f4
to
6267506
Compare
@@ -480,9 +480,17 @@ func installDependencies(workspace project.GoWorkspace) { | |||
|
|||
// get dependencies for all modules | |||
for _, module := range workspace.Modules { | |||
path := filepath.Dir(module.Path) | |||
|
|||
if util.DirExists(filepath.Join(path, "vendor")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this happens on both the existing module and the temporary module for legacy project paths. What are the expected consequences in each case?
The point of the |
extractedFiles | ||
| work/subdir/go.mod:0:0:0:0 | work/subdir/go.mod | | ||
| work/subdir/test.go:0:0:0:0 | work/subdir/test.go | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is work/go.mod
not in this list? And is this the reason that we still produce the "Go files were found but not processed" diagnostic?
I vaguely thought that we might be able to get rid of the "rearrange files in $GOPATH" behaviour now (which would be nice as it's a bit brittle), but I see it's still there. Can you explain a situation when we need it? |
if semver.Compare(toolchain.GetEnvGoSemVer(), "v1.21.0") < 0 && greatestGoVersion.Found && semver.Compare("v"+greatestGoVersion.Version, toolchain.GetEnvGoSemVer()) > 0 { | ||
diagnostics.EmitNewerGoVersionNeeded(toolchain.GetEnvGoSemVer(), "v"+greatestGoVersion.Version) | ||
if val, _ := os.LookupEnv("GITHUB_ACTIONS"); val == "true" { | ||
log.Printf( | ||
"The go.mod file requires version %s of Go, but version %s is installed. Consider adding an actions/setup-go step to your workflow.\n", | ||
"v"+goVersionInfo.Version, | ||
getEnvGoSemVer()) | ||
"A go.mod file requires version %s of Go, but version %s is installed. Consider adding an actions/setup-go step to your workflow.\n", | ||
"v"+greatestGoVersion.Version, | ||
toolchain.GetEnvGoSemVer()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason this was moved after the $GOPATH rearrangement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the $GOPATH
rearrangement ahead of this to address @smowton's comment in https://github.com/github/codeql/pull/15361/files/008585eeba2c455deb85b58e608a1822bf494dea#r1476152501
Do you have a concern about something I may have missed as part of this rearrangement?
if strings.Contains(string(out), "is relative, but relative import paths are not supported in module mode") { | ||
diagnostics.EmitRelativeImportPaths() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! I thought relative import paths did work in module mode. As that seems to not be the case, we should update the message for this diagnostic and remove the suggestion to use a Go module.
} | ||
} | ||
|
||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This preserves the old behaviour, so it should stay like this. But I wonder if in future we might want to remove this return
so that we get some other diagnostics in this case as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've finished reviewing. I think it would be okay to merge this. I've only given minor suggestions, which could be dealt with in follow-up PRs.
This PR makes changes to the Go autobuilder to account for the deprecation of the legacy GOPATH mode in Go 1.22. In the process we refactor parts of the Go autobuilder to both account for that change and be able to handle multiple Go modules as well as Go workspaces.
We are now able to successfully extract the code for the following, existing integration tests:
go-files-found-not-processed
(Multiplego.mod
files)single-go-work-not-in-root
(go.work
file)two-go-mods-nested-none-in-root
(Multiplego.mod
files)two-go-mods-not-nested
(Multiplego.mod
files)This PR also adds
query predicate
s to the integration tests to query the list of extracted files, so that we can now verify that the files we expect to be extracted have been extracted.Best reviewed commit-by-commit.