Skip to content

Commit

Permalink
Exclude no-ide targets from ProjectSourceToTargetFinder.
Browse files Browse the repository at this point in the history
This is an old class built for legacy sync, which therefore assumes that `no-ide` targets are excluded from the list of targets. Exclude them explicitly for query sync to ensure that it behaves as expected, and does not change its behaviour when enabling query sync.

Also add the target tags to `ProjectTarget` to enable this, and a simple test case for this.

(cherry picked from commit 852f812)
  • Loading branch information
Googler authored and mai93 committed Dec 5, 2023
1 parent f68b410 commit e4e82db
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.idea.blaze.base.run.testmap;

import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.util.function.Predicate.not;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -62,6 +63,7 @@ public Future<Collection<TargetInfo>> targetsForSourceFiles(
.map(file -> projectData.getWorkspacePathResolver().getWorkspacePath(file))
.filter(Objects::nonNull)
.flatMap(path -> projectData.getReverseDeps(path.asPath()).stream())
.filter(not(target -> target.tags().contains("no-ide")))
.filter(
buildTarget -> {
if (ruleType.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public BuildGraphData parse() {
if (alwaysBuildRuleKinds.contains(ruleClass)) {
projectTargetsToBuild.add(ruleEntry.getKey());
}
targetBuilder.tags(ruleEntry.getValue().getTagsList());
ProjectTarget target = targetBuilder.build();

for (Label thisSource : target.sourceLabels().values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public static SourceType[] all() {

public abstract ImmutableSet<QuerySyncLanguage> languages();

public abstract ImmutableList<String> tags();

public static Builder builder() {
return new AutoValue_ProjectTarget.Builder();
}
Expand Down Expand Up @@ -100,6 +102,8 @@ public abstract static class Builder {

public abstract ImmutableSet.Builder<QuerySyncLanguage> languagesBuilder();

public abstract Builder tags(Iterable<String> tags);

public abstract ProjectTarget build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,11 @@ public void testGetSameLanguageTargetsDependingOn_returnsTargetAndDirectDependen
Label.of("//" + TestData.ROOT.resolve("transitiveinternaldep:transitiveinternaldep")));
}

@Test
public void testTags() throws Exception {
BuildGraphData graph = BuildGraphs.forTestProject(TestData.TAGS_QUERY);
ProjectTarget testTarget = graph.targetMap().get(TestData.TAGS_QUERY.getAssumedOnlyLabel());
assertThat(testTarget.tags()).containsExactly("mytag");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ genquery(
],
)

genquery(
name = "tags_query",
expression = "//querysync/javatests/com/google/idea/blaze/qsync/testdata/tags:*",
opts = ["--output=streamed_proto"],
scope = scopeForJavaPackage("//querysync/javatests/com/google/idea/blaze/qsync/testdata/tags"),
)

java_library(
name = "testdata",
srcs = ["TestData.java"],
Expand All @@ -193,6 +200,7 @@ java_library(
":java_library_transitive_internal_dep_query",
":nested_proto_query",
":proto_only_query",
":tags_query",
],
deps = [
"//shared",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public enum TestData {
CC_EXTERNAL_DEP_QUERY("cc_externaldep"),
CC_MULTISRC_QUERY("cc_multisrc"),
PROTO_ONLY_QUERY("protoonly"),
NESTED_PROTO_QUERY("nestedproto");
NESTED_PROTO_QUERY("nestedproto"),
TAGS_QUERY("tags");

public final ImmutableList<Path> srcPaths;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
java_library(
name = "tags",
srcs = ["TestClass.java"],
tags = ["mytag"],
visibility = ["//querysync/javatests/com/google/idea/blaze/qsync/testdata:__subpackages__"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2022 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.idea.blaze.qsync.testdata.tags;

public class TestClass {

private TestClass() {}
}

0 comments on commit e4e82db

Please sign in to comment.