Starlarkify and split coverage features - #26355
Conversation
05b850b to
e55e136
Compare
|
There are two cases (that I can immediately think if) where a C++ rule needs to consider coverage when it doesn't match the instrumentation filter.
So I think the split of the feature is correct, although I might quibble with the naming; we require coverage flags in the link not because coverage is enabled generally, but because a transitive dependency requires it (although we don't actually check for that at the moment, but we could). |
It's true that we require coverage flags in the link for a different reason that is only approximated by coverage being enabled globally. But I don't think that makes it an issue with naming: the We could avoid introducing the |
d5735bc to
12bf932
Compare
|
@pzembrod I resolved the conflict. |
12bf932 to
278d82b
Compare
# Conflicts: # site/en/docs/cc-toolchain-config-reference.md
278d82b to
2849f21
Compare
|
@c-mita Friendly ping |
|
Moved to bazelbuild/rules_cc#842 |
…ented` `cc_common.configure_features` only requested a single `coverage` feature when building with coverage, which doesn't allow toolchains to distinguish between targets that are instrumented for coverage and those that aren't. The default toolchains thus end up instrumenting everything even with a narrow `--instrumentation_filter`, which is wasteful. `coverage_enabled` is now requested whenever coverage is generally enabled (matching `coverage`), whereas `coverage_instrumented` is only requested if the current target is instrumented. This gives toolchains a clean way to only instrument the targets that require it, see bazelbuild#424 for an example. Along the way, `implementation_deps` is added to the check for an instrumented dependency, which apparently wasn't updated when this attribute was added. This is a port of bazelbuild/bazel#26355, with the coverage feature computation kept in `configure_features` instead of moved into the individual rules: unlike Bazel's Java implementation, the Starlark one has access to `ctx`, so every rule calling `cc_common.configure_features` benefits without losing the existing `coverage` and `*_coverage_map_format` features.
…ented` `cc_common.configure_features` only requested a single `coverage` feature when building with coverage, which doesn't allow toolchains to distinguish between targets that are instrumented for coverage and those that aren't. The default toolchains thus end up instrumenting everything even with a narrow `--instrumentation_filter`, which is wasteful. `coverage_enabled` is now requested whenever coverage is generally enabled (matching `coverage`), whereas `coverage_instrumented` is only requested if the current target is instrumented. This gives toolchains a clean way to only instrument the targets that require it, see bazelbuild#424 for an example. Along the way, `implementation_deps` is added to the check for an instrumented dependency, which apparently wasn't updated when this attribute was added. This is a port of bazelbuild/bazel#26355, with the coverage feature computation kept in `configure_features` instead of moved into the individual rules: unlike Bazel's Java implementation, the Starlark one has access to `ctx`, so every rule calling `cc_common.configure_features` benefits without losing the existing `coverage` and `*_coverage_map_format` features.
Before this change, Bazel only enabled a single
coveragefeature when building with coverage, which doesn't directly allow toolchains to distinguish between targets that are instrumented for coverage and those which are not. Bazel's default toolchains thus end up instrumenting everything even with a narrow--instrumentation_filter, which is wasteful. Blaze relies on the presence of thegcov_gcno_filevariable to avoid this, but that's pretty hacky and undocumented (and also undocumentable).This change lets Bazel request two new coverage-related features:
coverage_enabledis requested whenever coverage is generally enabled (matchingcoverage), whereascoverage_instrumentedis only requested when the current target is instrumented. This provides a clean way for toolchains to instrument only those targets that require it (see bazelbuild/rules_cc#424 for an example of such a toolchain).To make this change possible, coverage feature computation is moved from Java to Starlark. Along the way,
implementation_depsis added to the check for an instrumented dependency, which apparently wasn't updated when this attribute was added.Work towards #15627
Fixes #21911
Fixes #22132 (comment)