xref: /aosp_15_r20/external/bazelbuild-rules_rust/tools/tool_utils.bzl (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1*d4726bddSHONG Yifan"""A helper module for the various targets in the `@rules_rust//tools` package"""
2*d4726bddSHONG Yifan
3*d4726bddSHONG Yifandef aspect_repository():
4*d4726bddSHONG Yifan    """Determines the repository name to use in Bazel commands that use aspects.
5*d4726bddSHONG Yifan
6*d4726bddSHONG Yifan    Some tools (`//tools/rustfmt` `//tools/rust_analyzer`) make calls to Bazel
7*d4726bddSHONG Yifan    and pass the `--aspects` flag. This macro allows those tools to work around
8*d4726bddSHONG Yifan    the following issue: https://github.com/bazelbuild/bazel/issues/11734
9*d4726bddSHONG Yifan
10*d4726bddSHONG Yifan    Returns:
11*d4726bddSHONG Yifan        str: The string to use for the `--aspects` repository labels
12*d4726bddSHONG Yifan    """
13*d4726bddSHONG Yifan    if native.repository_name() == "@":
14*d4726bddSHONG Yifan        return ""
15*d4726bddSHONG Yifan    return "@" + native.repository_name()
16