Skip to content

Commit

Permalink
Fix IntellijAspectTest to recognize both "//foo:bar" and "@//foo:bar"…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Googler authored and Copybara-Service committed Jul 20, 2022
1 parent 9d51c3a commit f82fab1
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -65,7 +65,7 @@ protected ImmutableList<TargetIdeInfo> findAllTargetsWithLabel(
? maybeRelativeLabel
: testRelative(maybeRelativeLabel);
return testFixture.getTargetsList().stream()
.filter(t -> t.hasKey() && t.getKey().getLabel().equals(label))
.filter(t -> t.hasKey() && labelsEqual(t.getKey().getLabel(), label))
.collect(toImmutableList());
}

Expand Down Expand Up @@ -125,7 +125,7 @@ private static boolean matchTarget(TargetIdeInfo target, String label) {
return false;
}
TargetKey targetKey = target.getKey();
return targetKey.getLabel().equals(label) && targetKey.getAspectIdsList().isEmpty();
return labelsEqual(targetKey.getLabel(), label) && targetKey.getAspectIdsList().isEmpty();
}

private static boolean matchTarget(
Expand All @@ -135,7 +135,7 @@ private static boolean matchTarget(
}

TargetKey targetKey = target.getKey();
if (!targetKey.getLabel().equals(label)) {
if (!labelsEqual(targetKey.getLabel(), label)) {
return false;
}
return targetHasMatchingAspects(target, fractionalAspectIds);
Expand Down Expand Up @@ -261,6 +261,14 @@ private static String getTargetName(String label) {
return label.substring(colonIx + 1);
}

private static boolean labelsEqual(String a, String b) {
return unambiguousAbsoluteLabel(a).equals(unambiguousAbsoluteLabel(b));
}

private static String unambiguousAbsoluteLabel(String label) {
return label.startsWith("@") ? label : "@" + label;
}

/** Returns the runtime location of a data dependency. */
private static Path runfilesPath(String relativePath) {
return Paths.get(getUserValue("TEST_SRCDIR"), getUserValue("TEST_WORKSPACE"), relativePath);
Expand Down

0 comments on commit f82fab1

Please sign in to comment.