Skip to content
Discussion options

You must be logged in to vote

You can't get the apparent name back for a given label, but you can transform your patterns to Label instead and then compare canonical names.

You can use the native.package_relative_label function in a macro (or rule initializer, if you assume recent versions of Bazel) to convert any label string to a Label. You can then apply the pattern matching in the macro, or alternatively stringify the Labels to canonical form via str and then pass them to a string_list attribute on your rule. The rule can then use Label to 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 …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@JohnnyMorganz
Comment options

@fmeum
Comment options

fmeum Jul 3, 2025
Collaborator

Answer selected by JohnnyMorganz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants