-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Quote labels in missing toolchains debug advice #27104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quote labels in missing toolchains debug advice #27104
Conversation
|
I'll respond properly to this PR when I get a moment later today. But I just want to express I'm strongly in favor of optimizing the UX. This flag spits out a ton of information that's both a) extremely useful when you need it and b) extremely dense and hard to follow. Ideally anyone should be able to use it to diagnose their toolchain registration setup. This flag is still very much the realm of power users now. But the info it provides is broadly useful to everyone. |
I'll plead ignorance but why is this?
Are you saying the suggestion message will always add
Is that referencing my above question? |
For the benefit of all potential readers I'll include some background. Bzlmod (opt-in since Bazel 6, default in Bazel 7) introduced the concept of "canonical" and "apparent" repository names in order to collisions across module boundaries. e.g.
Other repositories with a dependency on the latter can reference the latter using the apparent repository name In the context of this PR, most toolchains users will be exposed to such labels via third party modules. e.g.
That is why
For (1) yes, even for simple labels. For (2), yes it does reference your above question. From a quick look at https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/regex/Pattern.html checking for the presence of the following characters should suffice for an "is this necessary" check. |
Oh, I see. Extensions add the Repos that aren't generated from extensions wouldn't generally have Not trying to be nitpicky. I just want to make sure I understand the space right.
I support adding this check, and only suggesting that wrapping when needed. IMO that offers a gentler interface to this flag for simple cases. |
They do. https://bazel.build/external/module#repository_names_and_strict_deps |
132edc7
to
309ad8e
Compare
309ad8e
to
4cf7f09
Compare
Conditional regex logic has been added, along with a test case that specifically targets the exception (existing test cases focus on resolution, overkill for this change). |
The flag
toolchain_resolution_debug
accepts regex (technically a superset supporting-
,+
and,
in specific contexts) which the missing toolchains message does not handle.This is a problem for toolchain types with labels like
@@rules_shell+//shell:toolchain_type
as+
(match 1 or more of the proceeding token) cannot be used directly, and such labels are highly likely to be encountered as+
is in just about every canonical repository name.To solve this problem each label string is run through
Pattern::quote
, wrapping values with\Q
and\E
to denote a literal sequence (in PCRE compliant regex engines like the Java standard library uses).e.g.
Note that
Pattern::quote
always wraps the input, even if the input entirely consists of literal characters (fun fact:\
is a valid literal except in JS and PHP regex flavors). To avoid unnecessary quoting a naive check for\{[(^$.?+*|
characters is done to determine if quoting is necessary.