0

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_binary wrapper 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
  1. But for some mystical reasons I have a lack of gcno files.

  2. although there are these gcno's for neighboring files from the same library.

  3. Grepping for bazel --subcommands indicates the presences of --coverage flag for this cpp file.

  4. I did bazel clean --expunge - same result.

3
  • Which compiler/toolchain? Note that the --coverage compile 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? Commented Aug 6 at 15:05
  • Yep, I started from simple --coverage flag. Toolchain is gcc. I found objcets file in the expected places. Not clearly understand about sandbox (is it bazel --sandbox_debug flag). Commented Aug 7 at 18:58
  • Sorry for the confusion. Merely asking what happens if you run the same compilation line with all the same environment variable settings - from your shell. Do you see an indentical .o, as you got from bzel, and is your .gcno generated? If so - then there is something unexpected in your bazel build flow. If not: then we can debug the compilation command line to figure out what is wrong. Commented Aug 11 at 14:21

1 Answer 1

0

Bazel option --collect_code_coverage solved this problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Perhaps improve this by incorporating this into the code presented as part of the answer to make this an even better answer here. Then accept the answer by clicking the check mark which self answering it perfectly acceptable to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.