Skip to content

Commit f82fab1

Browse files
Googlercopybara-github
Googler
authored andcommitted
Fix IntellijAspectTest to recognize both "//foo:bar" and "@//foo:bar" labels
Both mean the same thing in a monorepo, but only the latter is unambiguous, since the former could mean different things from different repos. Bazel will generate the latter for absolute labels in the main repo in a future release, and this change is forwards-compatible with that. See bazelbuild/bazel#15916 for more information. PiperOrigin-RevId: 462117644
1 parent 9d51c3a commit f82fab1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

aspect/testing/rules/src/com/google/idea/blaze/aspect/IntellijAspectTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected ImmutableList<TargetIdeInfo> findAllTargetsWithLabel(
6565
? maybeRelativeLabel
6666
: testRelative(maybeRelativeLabel);
6767
return testFixture.getTargetsList().stream()
68-
.filter(t -> t.hasKey() && t.getKey().getLabel().equals(label))
68+
.filter(t -> t.hasKey() && labelsEqual(t.getKey().getLabel(), label))
6969
.collect(toImmutableList());
7070
}
7171

@@ -125,7 +125,7 @@ private static boolean matchTarget(TargetIdeInfo target, String label) {
125125
return false;
126126
}
127127
TargetKey targetKey = target.getKey();
128-
return targetKey.getLabel().equals(label) && targetKey.getAspectIdsList().isEmpty();
128+
return labelsEqual(targetKey.getLabel(), label) && targetKey.getAspectIdsList().isEmpty();
129129
}
130130

131131
private static boolean matchTarget(
@@ -135,7 +135,7 @@ private static boolean matchTarget(
135135
}
136136

137137
TargetKey targetKey = target.getKey();
138-
if (!targetKey.getLabel().equals(label)) {
138+
if (!labelsEqual(targetKey.getLabel(), label)) {
139139
return false;
140140
}
141141
return targetHasMatchingAspects(target, fractionalAspectIds);
@@ -261,6 +261,14 @@ private static String getTargetName(String label) {
261261
return label.substring(colonIx + 1);
262262
}
263263

264+
private static boolean labelsEqual(String a, String b) {
265+
return unambiguousAbsoluteLabel(a).equals(unambiguousAbsoluteLabel(b));
266+
}
267+
268+
private static String unambiguousAbsoluteLabel(String label) {
269+
return label.startsWith("@") ? label : "@" + label;
270+
}
271+
264272
/** Returns the runtime location of a data dependency. */
265273
private static Path runfilesPath(String relativePath) {
266274
return Paths.get(getUserValue("TEST_SRCDIR"), getUserValue("TEST_WORKSPACE"), relativePath);

0 commit comments

Comments
 (0)