Skip to content

Commit

Permalink
refactor(bazel): Turn parseModuleGraph() into an expression function
Browse files Browse the repository at this point in the history
Make the name more speaking and the code a tad more compact.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Jul 1, 2024
1 parent 0035d76 commit 55ee953
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions plugins/package-managers/bazel/src/main/kotlin/Bazel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,28 @@ class Bazel(
return setOf(
Scope(
name = "main",
dependencies = mainDeps.map { parseModuleGraphNode(it) }.toSet()
dependencies = mainDeps.map { it.toPackageReference() }.toSet()
),
Scope(
name = "dev",
dependencies = devDeps.map { parseModuleGraphNode(it) }.toSet()
dependencies = devDeps.map { it.toPackageReference() }.toSet()
)
)
}

private fun parseModuleGraphNode(node: BazelModule): PackageReference =
private fun BazelModule.toPackageReference(): PackageReference =
PackageReference(
id = Identifier(
type = managerName,
namespace = "",
name = node.name ?: node.key.substringBefore("@", ""),
version = node.version ?: node.key.substringAfter("@", "")
name = name ?: key.substringBefore("@", ""),
version = version ?: key.substringAfter("@", "")
),
// Static linking is the default for cc_binary targets. According to the documentation, it is off for
// cc_test, but according to experiments, it is on.
// See https://bazel.build/reference/be/c-cpp#cc_binary.linkstatic
linkage = PackageLinkage.STATIC,
dependencies = node.dependencies.map { parseModuleGraphNode(it) }.toSet()
dependencies = dependencies.map { it.toPackageReference() }.toSet()
)
}

Expand Down

0 comments on commit 55ee953

Please sign in to comment.