From 71c72c1515eb92730c28bebf65c925eadbe7b5a9 Mon Sep 17 00:00:00 2001 From: Marcel Hlopko Date: Thu, 23 Feb 2017 14:10:31 +0000 Subject: [PATCH] Fix autodetection of c++ coverage on osx Fixes #2275. The logic that adds 'coverage' feature to the toolchain if not present in CppConfiguration only works for linux targets. This cl teaches cc_configure.bzl about this feature so it can be autodetected on osx correctly (although the autodetection logic in this cl is rather naive). -- PiperOrigin-RevId: 148336592 MOS_MIGRATED_REVID=148336592 --- tools/cpp/CROSSTOOL.tpl | 2 ++ tools/cpp/cc_configure.bzl | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tools/cpp/CROSSTOOL.tpl b/tools/cpp/CROSSTOOL.tpl index 866271fd640942..ae1718a1980667 100644 --- a/tools/cpp/CROSSTOOL.tpl +++ b/tools/cpp/CROSSTOOL.tpl @@ -105,6 +105,8 @@ toolchain { %{opt_content} } linking_mode_flags { mode: DYNAMIC } + +%{coverage} } toolchain { diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl index 2a82763fb01a9d..3832eb79b213ce 100644 --- a/tools/cpp/cc_configure.bzl +++ b/tools/cpp/cc_configure.bzl @@ -617,6 +617,45 @@ def _get_env(repository_ctx): else: return "" +def _coverage_feature(darwin): + if darwin: + compile_flags = """flag_group { + flag: '-fprofile-instr-generate' + flag: '-fcoverage-mapping' + }""" + link_flags = """flag_group { + flag: '-fprofile-instr-generate' + }""" + else: + compile_flags = """flag_group { + flag: '-fprofile-arcs' + flag: '-ftest-coverage' + }""" + link_flags = """flag_group { + flag: '-lgcov' + }""" + return """ + feature { + name: 'coverage' + provides: 'profile' + flag_set { + action: 'preprocess-assemble' + action: 'c-compile' + action: 'c++-compile' + action: 'c++-header-parsing' + action: 'c++-header-preprocessing' + action: 'c++-module-compile' + """ + compile_flags + """ + } + flag_set { + action: 'c++-link-interface-dynamic-library' + action: 'c++-link-dynamic-library' + action: 'c++-link-executable' + """ + link_flags + """ + } + } + """ + def _impl(repository_ctx): repository_ctx.file("tools/cpp/empty.cc", "int main() {}") cpu_value = _get_cpu_value(repository_ctx) @@ -703,6 +742,7 @@ def _impl(repository_ctx): "%{opt_content}": _build_crosstool(opt_content, " "), "%{dbg_content}": _build_crosstool(dbg_content, " "), "%{cxx_builtin_include_directory}": "", + "%{coverage}": _coverage_feature(darwin), })