File tree Expand file tree Collapse file tree
main/kotlin/com/bazel_diff/bazel
test/kotlin/com/bazel_diff/e2e Expand file tree Collapse file tree 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,31 @@ 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 project = extractFixtureProject(" /fixture/integration-test-1.zip" )
595+
596+ val workingDirectory = File (project, " integration" )
597+ val bazelPath = " bazel"
598+ val outputDir = temp.newFolder()
599+ val hashesJson = File (outputDir, " hashes.json" )
600+
601+ val cli = CommandLine (BazelDiff ())
602+
603+ val exitCodeFrom = cli.execute(
604+ " generate-hashes" ,
605+ " -w" ,
606+ workingDirectory.absolutePath,
607+ " -b" ,
608+ bazelPath,
609+ " --useCquery" ,
610+ " --excludeExternalTargets" ,
611+ hashesJson.absolutePath)
612+ assertThat(exitCodeFrom).isEqualTo(0 )
613+ }
614+
590615 @Test
591616 fun testTargetDistanceMetrics () {
592617 val workspace = copyTestWorkspace(" distance_metrics" )
You can’t perform that action at this time.
0 commit comments