bazel query question: Is there a way to print out all tags defined for a test?

763 views
Skip to first unread message

Deron Johnson

unread,
Apr 18, 2023, 12:25:34 PM4/18/23
to bazel-discuss
I need to figure out how to determine the tags of a test from the command line.

Jeff Smelser

unread,
Apr 19, 2023, 1:25:42 AM4/19/23
to Deron Johnson, bazel-discuss
I use: bazel  query 'tests(//...)'

On Tue, Apr 18, 2023 at 10:25 AM Deron Johnson <berserk...@gmail.com> wrote:
I need to figure out how to determine the tags of a test from the command line.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/f0f94eb1-307d-4518-8049-825e2910dde9n%40googlegroups.com.

Jared Neil

unread,
Apr 19, 2023, 7:30:32 PM4/19/23
to bazel-discuss
buildozer can print the tags listed directly in the BUILD file, but doesn't expand macros: `buildozer 'print tags' //some/target`

If you're okay parsing XML, `bazel query --output=xml //some/target` will list the tags after macro expansion.
--output=proto and --output=streamed_proto are also options, if that's easier.

Finally, my personal favorite hack: use Python's eval to parse the output of `bazel query --output=build`

```
bazel query --output=build 'kind(sh_test, //some/targets/...)' | python -c '
import sys
def sh_test(tags, **kwargs):
  print(tags)

eval(sys.stdin.read())
'
```
Reply all
Reply to author
Forward
0 new messages