Search code examples
bazelbazel-query

Bazel query that doesn't follow all select branches


I have a configurable bazel build (ie, one with select statements) and I want a list of the used dependencies, not all of the dependencies.

For example, with the following for my BUILD:

config_setting(
   name = "arm",
   define_values = {
       "arm": "True",
   },
)
cc_binary(
    name = "main",
    srcs = ["main.C"] + select({
             "//:arm": ["ARM.C"],
             "//conditions:default": ["X86.C"],
}),

)

bazel query --noimplicit_deps deps(//:main) produces:

//:main
//:main.C
//:arm  
//:X86.C
//:ARM.C

What kind of query do I need to construct so that ARM.C is missing?


Solution

  • Have you tried cquery? It's fairly new, and I think it would be able to accomplish what you're looking for :)

    https://docs.bazel.build/versions/master/cquery.html