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); } }