Skip to content

Commit

Permalink
refactor(GoMod): Ignore the version constraint for go earlier
Browse files Browse the repository at this point in the history
As of Go version 1.21.0 the module graph contains a version constraint
for the `go` version. As this does not represent a dependency it can be
filtered out. In fact the entry would be filtered out by the below
`graph.subgraph(vendorModules)`. However, the code crashes before
reaching that line. In particular, `parseModuleEntry(columns[1])` fails
because there is no `ModuleInfo` for "go".

Avoid that issue by ignoring the corresponding edge when parsing the
module graph. This is a preparation for upgrading to the latest Go
version.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Oct 5, 2023
1 parent 0ce3a4f commit 6b39660
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion analyzer/src/main/kotlin/managers/GoMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,13 @@ class GoMod(
val columns = line.splitOnWhitespace()
require(columns.size == 2) { "Expected exactly one occurrence of ' ' on any non-blank line." }

val parent = parseModuleEntry(columns[0])
val parent = parseModuleEntry(columns[0]).apply {
// As of go version 1.21.1 the module graph contains a version constraint for the go version for
// the main project. The edge would be filtered out below by getVendorModules(). However, ignore
// it already here as there is no module info for 'go', so parseModuleEntry() would fail.
if (moduleInfo(name).main && columns[1].startsWith("go@")) return@forEach
}

val child = parseModuleEntry(columns[1])

if (moduleInfo(parent.name).main && moduleInfo(child.name).indirect) {
Expand Down

0 comments on commit 6b39660

Please sign in to comment.