-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix query command suggestion in error message with repo mappings #16482
Conversation
f387d43
to
95bda29
Compare
@meteorcloudy @Wyverald Could you review this? I noticed that the output of query consists of non-canonical label literals with canonical repo names. Those can't really be used anywhere with Bzlmod enabled. Should query emit canonical label literals instead, at least with Bzlmod? Edit: I looked into how this could be improved. It doesn't seem that difficult to get query output to use this output format instead: |
I think to begin with, outputting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, Yun just pointed out to me that this would break Google, where we don't use external repos at all and @
-prefixed labels are forbidden.
Could you instead only turn on this behavior when Bzlmod is enabled?
95bda29
to
e60df6b
Compare
Instead of depending on the Bzlmod bit explicitly, I backported the "one label stringification function to rule them all" I came up with for #16483, which decanonicalizes query output as far as possible, to the current PR. I moved the tests over since the current PR doesn't exercise all its functionality yet. It is slightly weird that the new function takes in a repo mapping of either the main or any other repository, but I found that to be the simplest pattern to gradually improve the existing cases of label formatting. Checking for strict visibility specifically seemed cleaner than testing for Bzlmod specifically, even though the should be (mostly?) equivalent. Looking forward to hearing your thoughts on this! |
src/main/java/com/google/devtools/build/lib/cmdline/RepositoryMapping.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/cmdline/PackageIdentifier.java
Outdated
Show resolved
Hide resolved
d93a9b2
to
a2342e8
Compare
a2342e8
to
ba5ff3c
Compare
The package label in the query command suggested when a specified target isn't found in a package looked like `@rules_cc~1.0.0//pkg`, which doesn't work with Bzlmod as the repo name is canonical, but the label isn't. This is fixed by introducing a new function `getDisplayForm` on `PackageIdentifier` that prints the most readable label representation of a package from the context of the main repository given a repository mapping (ideally that of the main repository). This function will be used in a follow-up PR to decanonicalize labels in {a,c,}query output when possible.
ba5ff3c
to
eaa63e5
Compare
The package label in the query command suggested when a specified target isn't found in a package looked like
@rules_cc~1.0.0//pkg
, which doesn't work as the repo name is canonical, but the label isn't.This is fixed by reusing the logic from
Label#getUnambiguousCanonicalForm
.