fix: problem detecting stdlib modules when using toolchains #329
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If the pkg.Module is
nil, it's either part of the stdlib or it's not something that go-licenses can analyze correctly. Let's just skip modules like this instead of reporting an error.The problem with the existing check is that it assumes that stdlib packages will have source files under
build.Default.GOROOT. But if the module you're trying to analyze has atoolchaindirective in its go.mod file that differs from the version of Go installed, the package will have a path outside of this directory.I think we could possibly also remove the code that checks for a specific prefix based off the GOROOT, but I wasn't 100% sure of that so I've left it in for now. I figure it doesn't do any harm (other than add a bit of confusion for future potentially).
Reproducing the problem is pretty simple:
toolchain <go-version>directive in the go.mod file where that version is different to your installed Go version (e.g. 1.24.2).The crossplane project referenced in #302 actually has an example of this in their go.mod file (presumably the cause of the problem).
I think this should resolve the following issues:
go 1.21.X#244.go 1.N.Pgo.mod syntax #324.