From 95f1859e25692fc54a7d0d7122aa28106cc936fb Mon Sep 17 00:00:00 2001 From: Julio Merino Date: Tue, 15 Jul 2025 06:32:42 -0700 Subject: [PATCH] Exclude no-ide targets from the initial sync query This prevents targets that are not picked up by the aspect to influence the decision of sharding the sync based on an inaccurate target count. This is the same as the query sync feature already does. Fixes #7799. --- .../dependencies/BlazeQueryDirectoryToTargetProvider.java | 8 +++++--- .../blaze/base/sync/sharding/WildcardTargetExpander.java | 5 +++-- .../BlazeQueryDirectoryToTargetProviderTest.java | 6 +++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/base/src/com/google/idea/blaze/base/dependencies/BlazeQueryDirectoryToTargetProvider.java b/base/src/com/google/idea/blaze/base/dependencies/BlazeQueryDirectoryToTargetProvider.java index da850dc3123..e1d93ad6db6 100644 --- a/base/src/com/google/idea/blaze/base/dependencies/BlazeQueryDirectoryToTargetProvider.java +++ b/base/src/com/google/idea/blaze/base/dependencies/BlazeQueryDirectoryToTargetProvider.java @@ -75,17 +75,19 @@ public static String getQueryString(ImportRoots directories, boolean allowManual } } + String query = String.format("attr('tags', '^((?!no-ide).)*$', %s)", targets); + if (allowManualTargetsSync) { - return targets.toString(); + return query; } // exclude 'manual' targets, which shouldn't be built when expanding wildcard target patterns if (SystemInfo.isWindows) { // TODO(b/201974254): Windows support for Bazel sync (see // https://github.com/bazelbuild/intellij/issues/113). - return String.format("attr('tags', '^((?!manual).)*$', %s)", targets); + return String.format("attr('tags', '^((?!manual).)*$', %s)", query); } - return String.format("attr(\"tags\", \"^((?!manual).)*$\", %s)", targets); + return String.format("attr(\"tags\", \"^((?!manual).)*$\", %s)", query); } /** diff --git a/base/src/com/google/idea/blaze/base/sync/sharding/WildcardTargetExpander.java b/base/src/com/google/idea/blaze/base/sync/sharding/WildcardTargetExpander.java index d9b74214996..b3a7b768694 100644 --- a/base/src/com/google/idea/blaze/base/sync/sharding/WildcardTargetExpander.java +++ b/base/src/com/google/idea/blaze/base/sync/sharding/WildcardTargetExpander.java @@ -270,8 +270,9 @@ private static String queryString(List targets, boolean exclud if (targetList.isEmpty()) { return targetList; } + String query = String.format("attr('tags', '^((?!no-ide).)*$', %s)", targetList); return excludeManualTargets - ? String.format("attr('tags', '%s', %s)", MANUAL_EXCLUDE_TAG, targetList) - : targetList; + ? String.format("attr('tags', '%s', %s)", MANUAL_EXCLUDE_TAG, query) + : query; } } diff --git a/java/tests/integrationtests/com/google/idea/blaze/java/base/dependencies/BlazeQueryDirectoryToTargetProviderTest.java b/java/tests/integrationtests/com/google/idea/blaze/java/base/dependencies/BlazeQueryDirectoryToTargetProviderTest.java index 6db5a8d8d00..b618255180f 100644 --- a/java/tests/integrationtests/com/google/idea/blaze/java/base/dependencies/BlazeQueryDirectoryToTargetProviderTest.java +++ b/java/tests/integrationtests/com/google/idea/blaze/java/base/dependencies/BlazeQueryDirectoryToTargetProviderTest.java @@ -54,7 +54,11 @@ public void test() { true, workspacePathResolver); + String expQueryString = String.format( + "attr('tags', '^((?!no-ide).)*$', %s - %s)", + TargetExpression.allFromPackageRecursive(included), + TargetExpression.allFromPackageRecursive(excluded)); - assertThat(queryString).isEqualTo(TargetExpression.allFromPackageRecursive(included) + " - " + TargetExpression.allFromPackageRecursive(excluded)); + assertThat(queryString).isEqualTo(expQueryString); } }