aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkiwiwarmnfuzzy <lujin@google.com>2024-02-07 17:50:20 +0100
committerGitHub <noreply@github.com>2024-02-07 17:50:20 +0100
commit8cd501f496171645c6a573dc1076889d1eca3312 (patch)
tree1982123be6a31b38b0f28882803f098f8dc4cb76
parent2d0f66ca93f7a137d84e3ec0318780b9b0fbd225 (diff)
downloadbazelbuild-rules_rust-8cd501f496171645c6a573dc1076889d1eca3312.tar.gz
Add argument `include_coverage` to toggle if `InstrumentedFilesInfo` is created (#2457)
If `rustc_compile_action` is invoked within an aspect of a rule, without this change, an `InstrumentedFilesInfo` would be created, which conflicts with the `InstrumentedFilesInfo` with the underlying target, causing a bazel action conflict. Thus, we add an option (default to `True`) so that aspect can specify this option when invoking `rustc_compile_action`, to avoid creating `InstrumentedFilesInfo`.
-rw-r--r--rust/private/rustc.bzl20
1 files changed, 15 insertions, 5 deletions
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
index ad682f35..b4f03b89 100644
--- a/rust/private/rustc.bzl
+++ b/rust/private/rustc.bzl
@@ -1111,7 +1111,8 @@ def rustc_compile_action(
output_hash = None,
force_all_deps_direct = False,
crate_info_dict = None,
- skip_expanding_rustc_env = False):
+ skip_expanding_rustc_env = False,
+ include_coverage = True):
"""Create and run a rustc compile action based on the current rule's attributes
Args:
@@ -1124,6 +1125,7 @@ def rustc_compile_action(
to the commandline as opposed to -L.
crate_info_dict: A mutable dict used to create CrateInfo provider
skip_expanding_rustc_env (bool, optional): Whether to expand CrateInfo.rustc_env
+ include_coverage (bool, optional): Whether to generate coverage information or not.
Returns:
list: A list of the following providers:
@@ -1456,12 +1458,20 @@ def rustc_compile_action(
runfiles = runfiles,
executable = executable,
),
- coverage_common.instrumented_files_info(
- ctx,
- **instrumented_files_kwargs
- ),
]
+ # When invoked by aspects (and when running `bazel coverage`), the
+ # baseline_coverage.dat created here will conflict with the baseline_coverage.dat of the
+ # underlying target, which is a build failure. So we add an option to disable it so that this
+ # function can be invoked from aspects for rules that have its own InstrumentedFilesInfo.
+ if include_coverage:
+ providers.append(
+ coverage_common.instrumented_files_info(
+ ctx,
+ **instrumented_files_kwargs
+ ),
+ )
+
if crate_info_dict != None:
crate_info_dict.update({
"rustc_env": env,