NB
I have the custom targets which run by python scripts. So I couldn't use bazel coverage directly for this one.
1.
- I defined in
.bazelrc
build:coverage --collect_code_coverage
build:coverage --instrumentation_filter="^//src[/:]"
coverage --instrumentation_filter="^//src[/:]"
- In the root BUILD
config_setting(
name = "Coverage",
flag_values = {
":coverage": "true",
},
)
bool_flag(
name = "coverage",
build_setting_default = False,
)
- In the
cc_binarywrapper I use
+ select({"//:Coverage": coverageCopts, "//conditions:default": [], }),
// and
select({"//:Coverage": coverageLopts, "//conditions:default": [], }),
where
coverageCopts = ["--coverage", "-fprofile-abs-path", "-fprofile-arcs", "-ftest-coverage"]
coverageLopts = ["--coverage", "-lgcov"]
- and run this python script (from bazel) like this:
bazel run --subcommands --//\:coverage=true script:runner
But for some mystical reasons I have a lack of
gcnofiles.although there are these
gcno's for neighboring files from the same library.Grepping for
bazel --subcommandsindicates the presences of--coverageflag for this cpp file.I did
bazel clean --expunge- same result.
--coveragecompile and link flags should be enough - you likely do not ned the other-f...options. If you can find the subcommand used on a particular target: which directory did it run in, was the .o generated as you expected (is it instrumented?), and what happens if you run that command in your sandbox?--coverageflag. Toolchain is gcc. I found objcets file in the expected places. Not clearly understand about sandbox (is itbazel --sandbox_debugflag).