Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all publicly visible targets in a Bazel workspace

Tags:

bazel

I am trying to query the list of Bazel targets having public visibility. Some of our Bazel targets have visibility specified explicitly, e.g.:

cc_library(
    name = "xxx_util",
    visibility = ["//visibility:public",],
    ...
)

while most targets are implicitly public, as their BUILD files have default public visibility specified, e.g.

package(default_visibility = ["//visibility:public"])

I need a list of all such targets, so that I can copy their output to a certain location automatically after my Bazel workspace is built.

I am new to Bazel and can't figure out the query...

like image 989
Curious Avatar asked Dec 29 '17 16:12

Curious


People also ask

What is visibility in Bazel?

Visibility controls whether a target can be used (depended on) by targets in other packages. This helps other people distinguish between your library's public API and its implementation details, and is an important tool to help enforce structure as your workspace grows.

What is Bazel target?

Targets. A package is a container. The elements of a package are called targets.

Where is Bazelrc?

On Linux/macOS/Unixes: /etc/bazel. bazelrc. On Windows: %ProgramData%\bazel.


1 Answers

I think the previous answer does cover the attribute query for visibility attribute restricted results. For posterity, I would add that if you simply want to find all targets from current directory, you could do:

bazel query ...
like image 152
Rubin Simons Avatar answered Oct 11 '22 02:10

Rubin Simons