Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions cc/common/cc_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,6 @@ def _is_compilation_outputs_empty(compilation_outputs):
return (len(compilation_outputs.pic_objects) == 0 and
len(compilation_outputs.objects) == 0)

def _is_code_coverage_enabled(ctx):
if ctx.coverage_instrumented():
return True
if hasattr(ctx.attr, "deps"):
for dep in ctx.attr.deps:
if CcInfo in dep:
if ctx.coverage_instrumented(dep):
return True
return False

def _build_precompiled_files(ctx):
objects = []
pic_objects = []
Expand Down Expand Up @@ -1140,7 +1130,6 @@ cc_helper = struct(
get_cpp_module_interfaces = _get_cpp_module_interfaces,
get_private_hdrs = _get_private_hdrs,
get_public_hdrs = _get_public_hdrs,
is_code_coverage_enabled = _is_code_coverage_enabled,
is_compilation_outputs_empty = _is_compilation_outputs_empty,
get_linking_contexts_from_deps = _get_linking_contexts_from_deps,
dll_hash_suffix = _dll_hash_suffix,
Expand Down
5 changes: 4 additions & 1 deletion cc/common/cc_helper_internal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ def get_linkstamp_stamps(
)
stamps = {
"GPLATFORM": cc_toolchain.toolchain_id,
"BUILD_COVERAGE_ENABLED": "1" if feature_configuration.is_enabled("coverage") else "0",
# Requested by cc_common.configure_features if coverage is generally enabled. This is
# checked instead of the feature being enabled so that the define is also correct for
# toolchains that don't define the feature.
"BUILD_COVERAGE_ENABLED": "1" if feature_configuration.is_requested("coverage_enabled") else "0",
# G3_TARGET_NAME is a C string literal that normally contain the label of the target
# being linked. However, they are set differently when using shared native deps. In
# that case, a single .so file is shared by multiple targets, and its contents cannot
Expand Down
5 changes: 0 additions & 5 deletions cc/private/cc_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ def _compile(
additional_module_maps = _UNBOUND,
propagate_module_map_to_compile_action = _UNBOUND,
do_not_generate_module_map = _UNBOUND,
code_coverage_enabled = _UNBOUND,
hdrs_checking_mode = _UNBOUND,
variables_extension = {},
language = None,
Expand All @@ -499,7 +498,6 @@ def _compile(
additional_exported_hdrs != _UNBOUND or \
propagate_module_map_to_compile_action != _UNBOUND or \
do_not_generate_module_map != _UNBOUND or \
code_coverage_enabled != _UNBOUND or \
purpose != _UNBOUND or \
hdrs_checking_mode != _UNBOUND or \
implementation_compilation_contexts != _UNBOUND or \
Expand All @@ -516,8 +514,6 @@ def _compile(
additional_exported_hdrs = []
if do_not_generate_module_map == _UNBOUND:
do_not_generate_module_map = False
if code_coverage_enabled == _UNBOUND:
code_coverage_enabled = False
if purpose == _UNBOUND:
purpose = None
if hdrs_checking_mode == _UNBOUND:
Expand Down Expand Up @@ -567,7 +563,6 @@ def _compile(
module_map = module_map,
additional_module_maps = additional_module_maps,
do_not_generate_module_map = do_not_generate_module_map,
code_coverage_enabled = code_coverage_enabled,
hdrs_checking_mode = hdrs_checking_mode,
variables_extension = variables_extension,
language = language,
Expand Down
52 changes: 15 additions & 37 deletions cc/private/compile/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def compile(
module_map = None,
additional_module_maps = [],
do_not_generate_module_map = False,
code_coverage_enabled = False,
# TODO(b/396122076): seems unused; double-check and remove
hdrs_checking_mode = None, # buildifier: disable=unused-variable
variables_extension = None,
Expand Down Expand Up @@ -199,7 +198,6 @@ def compile(
module_map: undocumented
additional_module_maps: undocumented
do_not_generate_module_map: undocumented
code_coverage_enabled: undocumented
hdrs_checking_mode: undocumented
variables_extension: undocumented
language: undocumented
Expand Down Expand Up @@ -377,7 +375,6 @@ def compile(
feature_configuration = feature_configuration,
generate_no_pic_action = generate_no_pic_action,
generate_pic_action = generate_pic_action,
is_code_coverage_enabled = code_coverage_enabled,
label = label,
private_headers = private_hdrs_artifacts,
public_headers = public_hdrs_artifacts,
Expand Down Expand Up @@ -657,7 +654,6 @@ def _create_cc_compile_actions_with_cpp20_module_helper(
cxxopts,
fdo_context,
feature_configuration,
is_code_coverage_enabled,
label,
private_headers, # buildifier: disable=unused-variable
public_headers, # buildifier: disable=unused-variable
Expand Down Expand Up @@ -848,7 +844,6 @@ def _create_cc_compile_actions_with_cpp20_module_helper(
fdo_build_variables = fdo_build_variables,
output_category = artifact_category.CLIF_OUTPUT_PROTO if cpp_source.type == CPP_SOURCE_TYPE_CLIF_INPUT_PROTO else artifact_category.OBJECT_FILE,
add_object = True,
enable_coverage = is_code_coverage_enabled,
generate_dwo = should_create_per_object_debug_info(feature_configuration, cpp_configuration),
bitcode_output = bitcode_output,
fdo_context = fdo_context,
Expand Down Expand Up @@ -995,7 +990,6 @@ def _create_cc_compile_actions_with_cpp20_module_helper(
fdo_build_variables = fdo_build_variables,
output_category = artifact_category.CLIF_OUTPUT_PROTO if cpp_source.type == CPP_SOURCE_TYPE_CLIF_INPUT_PROTO else artifact_category.OBJECT_FILE,
add_object = True,
enable_coverage = is_code_coverage_enabled,
generate_dwo = should_create_per_object_debug_info(feature_configuration, cpp_configuration),
bitcode_output = bitcode_output,
fdo_context = fdo_context,
Expand Down Expand Up @@ -1030,7 +1024,6 @@ def _create_cc_compile_actions_with_cpp20_module(
feature_configuration,
generate_no_pic_action,
generate_pic_action,
is_code_coverage_enabled,
label,
private_headers,
public_headers,
Expand Down Expand Up @@ -1068,7 +1061,6 @@ def _create_cc_compile_actions_with_cpp20_module(
cxxopts = cxxopts,
fdo_context = fdo_context,
feature_configuration = feature_configuration,
is_code_coverage_enabled = is_code_coverage_enabled,
label = label,
private_headers = private_headers,
public_headers = public_headers,
Expand Down Expand Up @@ -1103,7 +1095,6 @@ def _create_cc_compile_actions(
feature_configuration,
generate_no_pic_action,
generate_pic_action,
is_code_coverage_enabled,
label,
private_headers,
public_headers,
Expand Down Expand Up @@ -1147,7 +1138,6 @@ def _create_cc_compile_actions(
feature_configuration = feature_configuration,
generate_no_pic_action = generate_no_pic_action,
generate_pic_action = generate_pic_action,
is_code_coverage_enabled = is_code_coverage_enabled,
label = label,
private_headers = private_headers,
public_headers = public_headers,
Expand Down Expand Up @@ -1231,7 +1221,6 @@ def _create_cc_compile_actions(
fdo_context = fdo_context,
auxiliary_fdo_inputs = auxiliary_fdo_inputs,
feature_configuration = feature_configuration,
is_code_coverage_enabled = is_code_coverage_enabled,
label = label,
common_toolchain_variables = common_compile_build_variables,
fdo_build_variables = fdo_build_variables,
Expand Down Expand Up @@ -1278,7 +1267,6 @@ def _create_cc_compile_actions(
fdo_build_variables = fdo_build_variables,
output_category = (artifact_category.CLIF_OUTPUT_PROTO if source_type == CPP_SOURCE_TYPE_CLIF_INPUT_PROTO else artifact_category.OBJECT_FILE),
add_object = True,
enable_coverage = is_code_coverage_enabled,
generate_dwo = should_create_per_object_debug_info(feature_configuration, cpp_configuration),
bitcode_output = bitcode_output,
fdo_context = fdo_context,
Expand Down Expand Up @@ -1426,7 +1414,6 @@ def _create_pic_nopic_compile_source_actions(
fdo_build_variables,
output_category,
add_object,
enable_coverage,
generate_dwo,
bitcode_output,
fdo_context,
Expand Down Expand Up @@ -1461,7 +1448,6 @@ def _create_pic_nopic_compile_source_actions(
output_category = output_category,
module_name = module_name,
add_object = add_object,
enable_coverage = enable_coverage,
generate_dwo = generate_dwo,
bitcode_output = bitcode_output,
fdo_context = fdo_context,
Expand Down Expand Up @@ -1498,7 +1484,6 @@ def _create_pic_nopic_compile_source_actions(
output_category = output_category,
module_name = module_name,
add_object = add_object,
enable_coverage = enable_coverage,
generate_dwo = generate_dwo,
bitcode_output = bitcode_output,
fdo_context = fdo_context,
Expand Down Expand Up @@ -1535,7 +1520,6 @@ def _create_compile_source_action(
fdo_build_variables,
output_category,
add_object,
enable_coverage,
generate_dwo,
bitcode_output,
fdo_context,
Expand Down Expand Up @@ -1598,7 +1582,7 @@ def _create_compile_source_action(
cc_toolchain = cc_toolchain,
cpp_configuration = cpp_configuration,
configuration = configuration,
enable_coverage = enable_coverage,
feature_configuration = feature_configuration,
)

# Assembly files do not support -ftime-trace; skip trace output
Expand Down Expand Up @@ -1646,7 +1630,7 @@ def _create_compile_source_action(
compile_variables = get_specific_compile_build_variables(
source_file = source_artifact,
output_file = object_file,
code_coverage_enabled = enable_coverage,
code_coverage_enabled = feature_configuration.is_requested("coverage_instrumented"),
gcno_file = gcno_file,
dwo_file = dwo_file,
using_fission = generate_dwo,
Expand Down Expand Up @@ -1868,7 +1852,6 @@ def _create_temps_action(
preprocess_compile_variables = get_specific_compile_build_variables(
source_file = source_artifact,
output_file = preprocess_object_file,
code_coverage_enabled = False,
gcno_file = None,
dwo_file = None,
using_fission = False,
Expand All @@ -1884,7 +1867,6 @@ def _create_temps_action(
assembly_compile_variables = get_specific_compile_build_variables(
source_file = source_artifact,
output_file = assembly_object_file,
code_coverage_enabled = False,
gcno_file = None,
dwo_file = None,
using_fission = False,
Expand Down Expand Up @@ -1954,7 +1936,6 @@ def _create_module_codegen_action(
fdo_context,
auxiliary_fdo_inputs,
feature_configuration,
is_code_coverage_enabled,
label,
common_toolchain_variables,
fdo_build_variables,
Expand All @@ -1966,18 +1947,15 @@ def _create_module_codegen_action(
use_pic = ".pic" in module.basename
output_name = paths.basename(module.basename)

gcno_file = None
if is_code_coverage_enabled and not cpp_configuration.use_llvm_coverage_map_format():
gcno_file = _get_compile_output_file(
ctx = action_construction_context,
label = label,
configuration = configuration,
output_name = _cc_internal.get_artifact_name_for_category(
cc_toolchain = cc_toolchain,
category = artifact_category.COVERAGE_DATA_FILE,
output_name = output_name,
),
)
gcno_file = _maybe_declare_gcno_file(
ctx = action_construction_context,
label = label,
output_name = output_name,
cc_toolchain = cc_toolchain,
cpp_configuration = cpp_configuration,
configuration = configuration,
feature_configuration = feature_configuration,
)

bitcode_output = (feature_configuration.is_enabled("thin_lto") and
paths.split_extension(module.basename)[-1] in LTO_SOURCE_EXTENSIONS)
Expand Down Expand Up @@ -2046,7 +2024,7 @@ def _create_module_codegen_action(
specific_compile_build_variables = get_specific_compile_build_variables(
source_file = module,
output_file = object_file,
code_coverage_enabled = is_code_coverage_enabled,
code_coverage_enabled = feature_configuration.is_requested("coverage_instrumented"),
gcno_file = gcno_file,
dwo_file = dwo_file,
using_fission = generate_dwo,
Expand Down Expand Up @@ -2153,7 +2131,6 @@ def _create_module_action(
output_category = artifact_category.CPP_MODULE,
module_name = module_name,
add_object = False,
enable_coverage = False,
generate_dwo = False,
bitcode_output = False,
additional_compilation_inputs = additional_compilation_inputs,
Expand Down Expand Up @@ -2307,9 +2284,10 @@ def _maybe_declare_gcno_file(
cc_toolchain,
cpp_configuration,
configuration,
enable_coverage):
feature_configuration):
gcno_file = None
if enable_coverage and not cpp_configuration.use_llvm_coverage_map_format():
if (feature_configuration.is_requested("coverage_instrumented") and
not cpp_configuration.use_llvm_coverage_map_format()):
gcno_file = _get_compile_output_file(
ctx = ctx,
label = label,
Expand Down
4 changes: 2 additions & 2 deletions cc/private/compile/compile_build_variables.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ def get_specific_compile_build_variables(
if gcno_file:
result[_VARS.GCOV_GCNO_FILE] = gcno_file
elif code_coverage_enabled:
Comment thread
fmeum marked this conversation as resolved.
Outdated
# TODO: Blaze currently uses `gcov_gcno_file` to detect if code coverage
# is enabled. It should use a different signal.
# TODO: Blaze currently uses `gcov_gcno_file` to detect if the current target is
# instrumented for coverage. It should use the `coverage_instrumented` feature instead.
result[_VARS.GCOV_GCNO_FILE] = ""
if dwo_file:
result[_VARS.PER_OBJECT_DEBUG_INFO_FILE] = dwo_file
Expand Down
1 change: 0 additions & 1 deletion cc/private/rules_impl/cc_binary_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ def cc_binary_impl(ctx, additional_linkopts, force_linkstatic = False):
srcs = cc_helper.get_srcs(ctx),
module_interfaces = cc_helper.get_cpp_module_interfaces(ctx),
compilation_contexts = compilation_context_deps,
code_coverage_enabled = cc_helper.is_code_coverage_enabled(ctx = ctx),
additional_inputs = ctx.files.additional_compiler_inputs,
)
precompiled_file_objects = cc_common.create_compilation_outputs(
Expand Down
1 change: 0 additions & 1 deletion cc/private/rules_impl/cc_library_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def _cc_library_impl(ctx):
module_interfaces = cc_helper.get_cpp_module_interfaces(ctx),
private_hdrs = cc_helper.get_private_hdrs(ctx),
public_hdrs = cc_helper.get_public_hdrs(ctx),
code_coverage_enabled = cc_helper.is_code_coverage_enabled(ctx),
compilation_contexts = compilation_contexts,
implementation_compilation_contexts = implementation_compilation_contexts,
textual_hdrs = ctx.files.textual_hdrs,
Expand Down
1 change: 0 additions & 1 deletion cc/private/rules_impl/objc_compilation_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ def _compile(
module_map = module_map,
variables_extension = extension,
language = "objc",
code_coverage_enabled = cc_helper.is_code_coverage_enabled(ctx = common_variables.ctx),
hdrs_checking_mode = "strict",
do_not_generate_module_map = not generate_module_map or (module_map.file.is_source if type(module_map.file) == "File" else module_map.file().is_source),
purpose = purpose,
Expand Down
1 change: 1 addition & 0 deletions cc/private/toolchain_config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bzl_library(
"//cc:action_names_bzl",
"//cc:cc_toolchain_config_lib_bzl",
"//cc/common:semantics_bzl",
"//cc/private:cc_info_bzl",
"//cc/private:cc_internal_bzl",
"@bazel_skylib//lib:paths",
],
Expand Down
Loading