BAZEL: Query all targets in bazel rule

1.2k views Asked by At

Here is code structure

|   //base_folder
├── file0.txt
├── BUILD
├── folder1
|   ├── BUILD
|   ├── file1
├── folder2
|   ├── BUILD
|   ├── file2

I'd like to know all the files or target information to do a further process.

I can use bazel query command but I cannot get them in the BAZEL rule implement.

bazel query 'kind(cc_library, //...)'

I tried genrule to run command. But "bazel query" cannot be used in the bazel-bin folder.

I tried genquery, but "//..." is not allowed in genquery.

Is there way I can get the target information in BAZEL rule?

1

There are 1 answers

0
SG_Bazel On

bazel query is used to discover targets within a bazel workspace.

You can try:

If only interested in rules, then:

bazel query 'kind(.rule, //some/package:)'

//some/package:* could be substituted for any valid label expression, eg including all descending packages, //some/package/...

Reference : bazel query