Skip to content

Commit

Permalink
Future-proof intellij_info creation by stripping leading '@'s from ma…
Browse files Browse the repository at this point in the history
…in-repo labels (bazelbuild#3913)

Both "@//foo:bar" and "//foo:bar" mean the same thing in the main repo, but the latter can be ambiguous in a non-main repo, so Bazel 6.0 is going to flip bazelbuild/bazel#16196 (i.e. produce "@//foo:bar" instead of "//foo:bar" when `str(label)` is called). This means that for certain intellij tests (such as those deriving from IntellijAspectTest) to keep working, we need to strip the leading '@'s from any such labels.
  • Loading branch information
Wyverald authored and cpsauer committed Sep 9, 2022
1 parent 8fa8e38 commit 3f424bc
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,22 @@ def _is_language_specific_proto_library(ctx, target):
return True
return False

def _stringify_label(label):
s = str(label)

# If the label is in the main repo, make sure any leading '@'s are stripped so that tests are
# okay with the fixture setups.
if s.startswith("@@//"):
return s[2:]
if s.startswith("@//"):
return s[1:]
return s

def make_target_key(label, aspect_ids):
"""Returns a TargetKey proto struct from a target."""
return struct_omit_none(
aspect_ids = tuple(aspect_ids) if aspect_ids else None,
label = str(label),
label = _stringify_label(label),
)

def make_dep(dep, dependency_type):
Expand All @@ -255,7 +266,7 @@ def make_dep_from_label(label, dependency_type):
"""Returns a Dependency proto struct from a label."""
return struct(
dependency_type = dependency_type,
target = struct(label = str(label)),
target = struct(label = _stringify_label(label)),
)

def update_sync_output_groups(groups_dict, key, new_set):
Expand Down

0 comments on commit 3f424bc

Please sign in to comment.