bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.77k stars 3.99k forks source link

Make coverage possible with use of cc_common.compile #15974

Open a9zerwer opened 1 year ago

a9zerwer commented 1 year ago

Description of the feature request:

For custom C/C++ rules that compile using cc_common.compile it is impossible to generate coverage since there is no way to get the generated gcno files. If gcno files are exposed in CcCompilationOutputs then it makes generating coverage for these rules possible. Currently I am using a forked version of Bazel with the changes found in this PR and this allows us to successfully generate coverage reports for code compiled with cc_common.compile and remote execution enabled.

What underlying problem are you trying to solve with this feature?

In some cases where rules need to compile with cc_common.compile we still want to be able to collect code coverage. Without this we would have to search through the bazel-out after the bazel coverage ... command runs which also would not work with remote execution.

Have you found anything relevant by searching the web?

https://github.com/bazelbuild/bazel/pull/12129

github-actions[bot] commented 6 months ago

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

phst commented 6 months ago

Still happening. https://github.com/bazelbuild/bazel/pull/12129 would fix this for GCOV, but appears to be stalled.

phst commented 5 months ago

As a workaround (for llvm-cov, not gcov), you can create a special text file ending in runtime_objects_list.txt that contains the execution path for binaries/shared libraries and pass that to coverage_common.instrumented_files_info in its metadata_files argument (available with Bazel 7). Then collect_cc_coverage.sh will parse the file and call llvm-cov with the right arguments (assuming you also apply the workaround in https://github.com/bazelbuild/bazel/issues/14970#issuecomment-1894565761, at least on macOS). See https://github.com/phst/rules_elisp/blob/1fbdfd49e7687edff710e72177c62e2ccf503391/elisp/defs.bzl#L463-L477 for an example.

phst commented 5 months ago

Random suggestion: Create a function cc_common.instrumented_files_info that takes toolchain, feature config, compilation and linking outputs, etc. as arguments and creates an InstrumentedFilesInfo provider with the right metadata files.