Skip to content

Commit

Permalink
Fix autodetection of c++ coverage on osx
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hlopko authored and iirina committed Feb 24, 2017
1 parent 6b3b8d0 commit 71c72c1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tools/cpp/CROSSTOOL.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ toolchain {
%{opt_content}
}
linking_mode_flags { mode: DYNAMIC }

%{coverage}

This comment has been minimized.

Copy link
@laszlocsomor

laszlocsomor Feb 24, 2017

Contributor

This breaks Bazel on Windows:

$ C:/tmp/Oh5NykPf/execroot/bazel2/bazel-out/local-fastbuild/bin/src/bazel.exe --output_user_root=/c/tmp5 build src:bazel --nobuild
Extracting Bazel installation...
Cannot terminate server process with PID 8428
.
ERROR: java.io.IOException: Could not read the crosstool configuration file 'CROSSTOOL file C:/tmp5/o6hbs7n0/external/local_config_cc/CROSSTOOL', because of a parser error (134:1: Expected identifier. Found '%').
INFO: Elapsed time: 14.815s

Apparently there's a placeholder left in the CROSSTOOL:

$ cat C:/tmp5/o6hbs7n0/external/local_config_cc/CROSSTOOL | grep -C3 coverage
  }
  linking_mode_flags { mode: DYNAMIC }

%{coverage}
}

toolchain {

This comment has been minimized.

Copy link
@hlopko

hlopko Feb 24, 2017

Author Member

Fix flying in in 1 minute :)

This comment has been minimized.

Copy link
@laszlocsomor

laszlocsomor Feb 24, 2017

Contributor

Thanks :) verifying and filing bug as we speak.

This comment has been minimized.

Copy link
@laszlocsomor

laszlocsomor Feb 24, 2017

Contributor
}

toolchain {
Expand Down
40 changes: 40 additions & 0 deletions tools/cpp/cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
})


Expand Down

0 comments on commit 71c72c1

Please sign in to comment.