Skip to content

Commit

Permalink
Expect double-@-prefixed labels in Bazel output
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 581018613
(cherry picked from commit a844598)
  • Loading branch information
Googler authored and mai93 committed Nov 14, 2023
1 parent 2397056 commit 73cde7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions shared/java/com/google/idea/blaze/common/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public Label(String label) {
Preconditions.checkArgument(doubleSlash > 0, label);
int colon = label.indexOf(":");
Preconditions.checkArgument(colon > doubleSlash, label);
if (!label.startsWith("@@")) {
// Normalize `label` to either start with double-at or start with double-slash.
label = '@' + label;
}
} else {
Preconditions.checkArgument(label.startsWith("//"), label);
Preconditions.checkArgument(label.contains(":"), label);
Expand All @@ -78,10 +82,10 @@ public Path getName() {
}

public String getWorkspaceName() {
if (!label.startsWith("@")) {
return "";
if (label.startsWith("@@")) {
return label.substring(2, label.indexOf("//"));
} else {
return label.substring(1, label.indexOf("//"));
return "";
}
}

Expand Down
10 changes: 10 additions & 0 deletions shared/javatests/com/google/idea/blaze/common/LabelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,18 @@ public void testGetWorkspace_nonEmpty() {
assertThat(new Label("@myworkspace//package:rule").getWorkspaceName()).isEqualTo("myworkspace");
}

@Test
public void testGetWorkspace_doubleAt() {
assertThat(new Label("@@myws//package:rule").getWorkspaceName()).isEqualTo("myws");
}

@Test
public void testNew_badWorkspace() {
assertThrows(IllegalArgumentException.class, () -> new Label("@work:space//package/path"));
}

@Test
public void doubleAtNormalization() {
assertThat(new Label("@abc//:def")).isEqualTo(new Label("@@abc//:def"));
}
}

0 comments on commit 73cde7e

Please sign in to comment.