-
Notifications
You must be signed in to change notification settings - Fork 4k
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
bazel query: query for effective values of attributes #4388
Comments
This is a weird one, because strictly speaking the value of Bazel then resolves all this with
There's also the But I get something intuitive gets lost in all this. If the workaround described in https://stackoverflow.com/questions/48025329 isn't sufficient, please re-ping here and we'll re-assess. |
Like you have said something intuitive is lost here. The workaround in SO works only partially. |
I forgot about this, but what about the visible query function?
This returns the rules in It's not perfect because a rule could set But I bet this could get you a lot closer to a satisfactory solution, at least for public visibility. |
|
Chris, For what purpose? For example, why not just call If you're looking for more structured operations, you can also play with query's $ bazel query '//foo:bar' --output=build
cc_library(
name = "bar",
srcs = ["//foo:bar.cc"],
) $ bazel query '//foo:bar' --output=xml
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<query version="2">
<rule class="cc_library" location="/usr/local/home/me/bazel/bazel-website/foo/BUILD:1:1" name="//foo:bar">
<string name="name" value="bar"/>
<list name="srcs">
<label value="//foo:bar.cc"/>
</list>
<rule-input name="//foo:bar.cc"/>
<rule-input name="@bazel_tools//tools/cpp:grep-includes"/>
<rule-input name="@bazel_tools//tools/cpp:stl"/>
<rule-input name="@bazel_tools//tools/cpp:toolchain"/>
<rule-input name="@bazel_tools//tools/def_parser:def_parser"/>
</rule>
</query> $ bazel query '//foo:bar' --output=xml --noimplicit_deps
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<query version="2">
<rule class="cc_library" location="/usr/local/home/me/bazel/bazel-website/foo/BUILD:1:1" name="//foo:bar">
<string name="name" value="bar"/>
<list name="srcs">
<label value="//foo:bar.cc"/>
</list>
<rule-input name="//foo:bar.cc"/>
</rule>
</query> You can also use buildozer: $ buildozer 'print srcs' //foo:bar
[bar.cc] |
Can this be reopened? None of the suggested workarounds account for the default visibility of the package. |
What specifically are you trying to figure out (from your query)? |
Same as the OP: the visibility of targets. For context my use case is that I'm implementing a linter for our monorepo to enforce rules like "targets in |
So right now we're prohibiting package groups and default visibilities so that the query can work in a simple way. |
This was the workaround - find targets that inherit default visibility. Can you string a few calls together?
And match accordingly. I realize direct support would be more convenient. But it conceptually complicates the query language. We'd have to be extra cautious about vetting it as a proper feature request. That would require a deeper process than a quick fix. Given that I'd like to evaluate what's possible with workarounds as much as we can. |
All those pieces put together achieve what we need, and I understand the concern about complicating the query language. Thanks for the help! |
Description of the problem / feature request:
Feature request: bazel query operating on the effective values of attributes, e.g. querying the visibility of a target if it uses the package-default visibility.
Example -- the query should return fg1 and fg2, but it only returns fg1:
Feature requests: what underlying problem are you trying to solve with this feature?
https://stackoverflow.com/questions/48025329
What operating system are you running Bazel on?
Windows 10
What's the output of
bazel info release
?0.9.0
What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?Not a git repo.
Have you found anything relevant by searching the web?
No open GitHub issues AFAICT.
The text was updated successfully, but these errors were encountered: