Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cli/src/main/kotlin/com/bazel_diff/bazel/BazelClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ class BazelClient(
// In addition, we must include all source dependencies in this query in order for them to
// show up in
// `configuredRuleInput`. Hence, one must not filter them out with `kind(rule, deps(..))`.
(queryService.query("deps(//...:all-targets)", useCquery = true) +
queryService.query(repoTargetsQuery.joinToString(" + ") { "'$it'" }))
.distinctBy { it.name }
val mainTargets = queryService.query("deps(//...:all-targets)", useCquery = true)
val repoTargets = if (repoTargetsQuery.isNotEmpty()) {
queryService.query(repoTargetsQuery.joinToString(" + ") { "'$it'" })
} else {
emptyList()
}
(mainTargets + repoTargets).distinctBy { it.name }
} else {
val buildTargetsQuery =
listOf("//...:all-targets") +
Expand Down
27 changes: 27 additions & 0 deletions cli/src/test/kotlin/com/bazel_diff/e2e/E2ETest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,33 @@ class E2ETest {
assertThat(actual).isEqualTo(expected)
}

@Test
fun testUseCqueryWithExcludeExternalTargets() {
// This test verifies the fix for the issue where using --excludeExternalTargets with --useCquery
// would cause an empty query string to be passed to Bazel, resulting in exit code 2.
val workingDirectory = extractFixtureProject("/fixture/cquery-test-base.zip")

val bazelPath = "bazel"
val outputDir = temp.newFolder()
val hashesJson = File(outputDir, "hashes.json")

val cli = CommandLine(BazelDiff())

val exitCode = cli.execute(
"generate-hashes",
"-w",
workingDirectory.absolutePath,
"-b",
bazelPath,
"--useCquery",
// Platform is specified only to make the cquery succeed.
"--cqueryCommandOptions",
"--platforms=//:jre",
"--excludeExternalTargets",
hashesJson.absolutePath)
assertThat(exitCode).isEqualTo(0)
}

@Test
fun testTargetDistanceMetrics() {
val workspace = copyTestWorkspace("distance_metrics")
Expand Down
Loading