File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed
main/kotlin/com/bazel_diff/bazel
test/kotlin/com/bazel_diff/e2e Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -35,9 +35,13 @@ class BazelClient(
3535 // In addition, we must include all source dependencies in this query in order for them to
3636 // show up in
3737 // `configuredRuleInput`. Hence, one must not filter them out with `kind(rule, deps(..))`.
38- (queryService.query(" deps(//...:all-targets)" , useCquery = true ) +
39- queryService.query(repoTargetsQuery.joinToString(" + " ) { " '$it '" }))
40- .distinctBy { it.name }
38+ val mainTargets = queryService.query(" deps(//...:all-targets)" , useCquery = true )
39+ val repoTargets = if (repoTargetsQuery.isNotEmpty()) {
40+ queryService.query(repoTargetsQuery.joinToString(" + " ) { " '$it '" })
41+ } else {
42+ emptyList()
43+ }
44+ (mainTargets + repoTargets).distinctBy { it.name }
4145 } else {
4246 val buildTargetsQuery =
4347 listOf (" //...:all-targets" ) +
Original file line number Diff line number Diff line change @@ -587,6 +587,33 @@ class E2ETest {
587587 assertThat(actual).isEqualTo(expected)
588588 }
589589
590+ @Test
591+ fun testUseCqueryWithExcludeExternalTargets () {
592+ // This test verifies the fix for the issue where using --excludeExternalTargets with --useCquery
593+ // would cause an empty query string to be passed to Bazel, resulting in exit code 2.
594+ val workingDirectory = extractFixtureProject(" /fixture/cquery-test-base.zip" )
595+
596+ val bazelPath = " bazel"
597+ val outputDir = temp.newFolder()
598+ val hashesJson = File (outputDir, " hashes.json" )
599+
600+ val cli = CommandLine (BazelDiff ())
601+
602+ val exitCode = cli.execute(
603+ " generate-hashes" ,
604+ " -w" ,
605+ workingDirectory.absolutePath,
606+ " -b" ,
607+ bazelPath,
608+ " --useCquery" ,
609+ // Platform is specified only to make the cquery succeed.
610+ " --cqueryCommandOptions" ,
611+ " --platforms=//:jre" ,
612+ " --excludeExternalTargets" ,
613+ hashesJson.absolutePath)
614+ assertThat(exitCode).isEqualTo(0 )
615+ }
616+
590617 @Test
591618 fun testTargetDistanceMetrics () {
592619 val workspace = copyTestWorkspace(" distance_metrics" )
You can’t perform that action at this time.
0 commit comments