@@ -19,6 +19,7 @@ load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
1919 "env_entry",
2020 "env_set",
2121 "feature",
22+ "feature_set",
2223 "flag_group",
2324 "flag_set",
2425 "tool",
@@ -424,6 +425,31 @@ def _impl(ctx):
424425 ],
425426 )
426427
428+ coverage_feature = feature(name = "coverage")
429+ gcc_coverage_map_format_feature = feature(
430+ name = "gcc_coverage_map_format",
431+ provides = ["profile"],
432+ flag_sets = [
433+ flag_set(
434+ actions = [
435+ ACTION_NAMES.c_compile,
436+ ACTION_NAMES.cpp_compile,
437+ ACTION_NAMES.cpp_module_compile,
438+ ACTION_NAMES.preprocess_assemble,
439+ ],
440+ flag_groups = [flag_group(
441+ expand_if_available = "gcov_gcno_file",
442+ flags = ["-fprofile-arcs", "-ftest-coverage"],
443+ )],
444+ ),
445+ flag_set(
446+ actions = all_link_actions,
447+ flag_groups = [flag_group(flags = ["-lgcov"])],
448+ ),
449+ ],
450+ requires = [feature_set(features = ["coverage"])],
451+ )
452+
427453 # The order of the features is relevant, they are applied in this specific order.
428454 # A command line parameter from a feature at the end of the list will appear
429455 # after a command line parameter from a feature at the beginning of the list.
@@ -447,13 +473,18 @@ def _impl(ctx):
447473 supports_dynamic_linker_feature,
448474 supports_pic_feature,
449475 runtime_library_search_directories_feature,
476+ coverage_feature,
477+ gcc_coverage_map_format_feature,
450478 ]
451479
452480 cxx_builtin_include_directories = [
453481 "/proc/self/cwd/{}".format(include_directory.path)
454482 for include_directory in ctx.files.cxx_builtin_include_directories
455483 ]
456484
485+ # TODO: Once https://github.com/bazelbuild/rules_cc/issues/351 is fixed remove this.
486+ tool_paths = [tool_path(name = "gcov", path = "gcov_wrapper")]
487+
457488 return cc_common.create_cc_toolchain_config_info(
458489 ctx = ctx,
459490 abi_version = "%{tc_cpu}-qnx%{sdp_version}",
@@ -467,6 +498,7 @@ def _impl(ctx):
467498 target_cpu = "%{tc_cpu}",
468499 target_libc = "unknown",
469500 toolchain_identifier = "%{tc_cpu}-qnx%{sdp_version}",
501+ tool_paths = tool_paths,
470502 )
471503
472504cc_toolchain_config = rule(
@@ -476,6 +508,7 @@ cc_toolchain_config = rule(
476508 "ar_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True),
477509 "cc_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True),
478510 "cxx_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True),
511+ "gcov_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True),
479512 "strip_binary": attr.label(allow_single_file = True, executable = True, cfg = "exec", mandatory = True),
480513 "host_dir": attr.label(allow_single_file = True, mandatory = True),
481514 "target_dir": attr.label(allow_single_file = True, mandatory = True),
0 commit comments