Can you get the apparent repo name from a Label?
#26451
|
We are currently migrating our usage of rules_jvm_external from WORKSPACE to Bzlmod for the We have some code that checks We are relying on the apparent repo name to do this matching. tl;dr is that we have some custom Starlark logic that allows users to pass in a "target pattern"-like syntax like Can we somehow get the apparent repo name back from a Label struct? |
Replies: 1 comment 2 replies
|
You can't get the apparent name back for a given label, but you can transform your patterns to You can use the Since Happy to provide more details if needed. |
You can't get the apparent name back for a given label, but you can transform your patterns to
Labelinstead and then compare canonical names.You can use the
native.package_relative_labelfunction in a macro (or rule initializer, if you assume recent versions of Bazel) to convert any label string to aLabel. You can then apply the pattern matching in the macro, or alternatively stringify theLabels to canonical form viastrand then pass them to a string_list attribute on your rule. The rule can then useLabelto recover the parsed label.Since
@maven//...isn't valid label syntax, you could internally convert it into a representation such as@maven//:__subpackages__to safely roundtrip …