diff --git a/cxx/compile.bzl b/cxx/compile.bzl index 8951749a7..e6089e435 100644 --- a/cxx/compile.bzl +++ b/cxx/compile.bzl @@ -270,7 +270,8 @@ def create_compile_cmds( ctx: AnalysisContext, impl_params: CxxRuleConstructorParams, own_preprocessors: list[CPreprocessor], - inherited_preprocessor_infos: list[CPreprocessorInfo]) -> CxxCompileCommandOutput: + inherited_preprocessor_infos: list[CPreprocessorInfo], + add_coverage_instrumentation_compiler_flags: bool) -> CxxCompileCommandOutput: """ Forms the CxxSrcCompileCommand to use for each source file based on it's extension and optional source file flags. Returns CxxCompileCommandOutput containing an array @@ -335,6 +336,8 @@ def create_compile_cmds( for src in srcs_with_flags: src_args = [] src_args.extend(src.flags) + if add_coverage_instrumentation_compiler_flags: + src_args.extend(ctx.attrs.coverage_instrumentation_compiler_flags) ext = get_source_extension(src, extension_for_plain_headers) diff --git a/cxx/cxx_executable.bzl b/cxx/cxx_executable.bzl index bae20782f..70a52c33a 100644 --- a/cxx/cxx_executable.bzl +++ b/cxx/cxx_executable.bzl @@ -100,6 +100,10 @@ load( "cxx_objects_sub_targets", ) load(":cxx_context.bzl", "get_cxx_platform_info", "get_cxx_toolchain_info") +load( + ":cxx_instrumentation.bzl", + "is_coverage_enabled_by_any_dep", +) load( ":cxx_library_utility.bzl", "OBJECTS_SUBTARGET", @@ -216,6 +220,7 @@ def cxx_executable(ctx: AnalysisContext, impl_params: CxxRuleConstructorParams, impl_params, [own_preprocessor_info] + test_preprocessor_infos, inherited_preprocessor_infos, + is_coverage_enabled_by_any_dep(ctx, preprocessor_deps), ) cxx_outs = compile_cxx(ctx, compile_cmd_output.src_compile_cmds, pic = link_strategy != LinkStrategy("static")) diff --git a/cxx/cxx_library.bzl b/cxx/cxx_library.bzl index 1c8bc94f6..9dec91ffd 100644 --- a/cxx/cxx_library.bzl +++ b/cxx/cxx_library.bzl @@ -128,6 +128,11 @@ load( "cxx_objects_sub_targets", ) load(":cxx_context.bzl", "get_cxx_platform_info", "get_cxx_toolchain_info") +load( + ":cxx_instrumentation.bzl", + "build_exported_needs_coverage", + "needs_coverage", +) load( ":cxx_library_utility.bzl", "OBJECTS_SUBTARGET", @@ -370,6 +375,7 @@ def cxx_library_parameterized(ctx: AnalysisContext, impl_params: CxxRuleConstruc preferred_linkage = cxx_attr_preferred_linkage(ctx) + exported_needs_coverage = build_exported_needs_coverage(ctx, exported_deps + non_exported_deps) compiled_srcs = cxx_compile_srcs( ctx = ctx, impl_params = impl_params, @@ -377,11 +383,14 @@ def cxx_library_parameterized(ctx: AnalysisContext, impl_params: CxxRuleConstruc inherited_non_exported_preprocessor_infos = inherited_non_exported_preprocessor_infos, inherited_exported_preprocessor_infos = inherited_exported_preprocessor_infos, preferred_linkage = preferred_linkage, + add_coverage_instrumentation_compiler_flags = needs_coverage(exported_needs_coverage), ) sub_targets = {} providers = [] + providers.append(exported_needs_coverage) + if len(ctx.attrs.tests) > 0 and impl_params.generate_providers.preprocessor_for_tests: providers.append( CPreprocessorForTestsInfo( @@ -931,7 +940,8 @@ def cxx_compile_srcs( own_preprocessors: list[CPreprocessor], inherited_non_exported_preprocessor_infos: list[CPreprocessorInfo], inherited_exported_preprocessor_infos: list[CPreprocessorInfo], - preferred_linkage: Linkage) -> _CxxCompiledSourcesOutput: + preferred_linkage: Linkage, + add_coverage_instrumentation_compiler_flags: bool) -> _CxxCompiledSourcesOutput: """ Compile objects we'll need for archives and shared libraries. """ @@ -942,6 +952,7 @@ def cxx_compile_srcs( impl_params = impl_params, own_preprocessors = own_preprocessors, inherited_preprocessor_infos = inherited_non_exported_preprocessor_infos + inherited_exported_preprocessor_infos, + add_coverage_instrumentation_compiler_flags = add_coverage_instrumentation_compiler_flags, ) # Define object files. diff --git a/go/cgo_builder.bzl b/go/cgo_builder.bzl index 0ae78f8cc..766df6d69 100644 --- a/go/cgo_builder.bzl +++ b/go/cgo_builder.bzl @@ -170,6 +170,7 @@ def build_cgo(ctx: AnalysisContext, cgo_files: list[Artifact], h_files: list[Art inherited_pre, [], linkage, + False, # add_coverage_instrumentation_compiler_flags ) compiled_objects = c_compile_cmds.pic.objects