0

If I have

cc_binary(
    name = "stooges",
    srcs = [ "larry.cc", "curly.cc", "moe.cc" ],
)

Is there a Bazel query which will return "larry.cc", "curly.cc", "moe.cc" ?

At the moment the only thing I can think of is

$ bazel query --output=build //:stooges | perl -nwle 'print $1 if /srcs\s*=\s*\[([^]]*)\]/'
Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Bulletmagnet
  • 5,665
  • 2
  • 26
  • 56

1 Answers1

3

Get all labels listed in the srcs attribute:

bazel query 'labels(srcs,//your_package:your_target)'

In your case bazel query 'labels(srcs,//:stooges)'.

Should return:

//:larry.cc 
//:curly.cc
//:moe.cc

If you want to have all hdrs and srcs labels:

bazel query 'labels(srcs,//your_package:your_target) union labels(hdrs,//your_package:your_target)'

You can also make use of Bazel Aspects to query for source files. More details here.

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90