diff options
author | Ulf Adams <ulfjack@google.com> | 2018-04-19 02:55:15 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-04-19 02:56:57 -0700 |
commit | 9566f677a1093e3a3c0ddaed3f9ab34dd98e5e26 (patch) | |
tree | 375788e3c03417e2585619c840bb01456e1d0956 /tools/test | |
parent | 75b75c89fc3b0f5e0c68c0c4a7ca188e9d2ee205 (diff) |
Add a workaround for gcov-based coverage with clang
- Allow overriding the gcov tool with the GCOV env variable in cc_configure
- Symlink the GCOV tool in collect-coverage.sh to a temporary location with
the name "gcov"
This allows the user to specify GCOV=llvm-cov in the environment of a bazel
build, which then leads to cc_configure picking up llvm-cov in the crosstool,
which the collect-coverage.sh script then uses as "gcov".
On linux distributions, the gcov tool does not generally work with clang
coverage output, so this provides at least a workaround for running coverage
with clang (by setting the GCOV env variable).
Closes #5040.
PiperOrigin-RevId: 193487773
Diffstat (limited to 'tools/test')
-rwxr-xr-x | tools/test/collect_coverage.sh | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/test/collect_coverage.sh b/tools/test/collect_coverage.sh index aba56c0ee1..b9579cac99 100755 --- a/tools/test/collect_coverage.sh +++ b/tools/test/collect_coverage.sh @@ -126,13 +126,21 @@ if [[ "$COVERAGE_LEGACY_MODE" ]]; then touch "${COVERAGE_DIR}/${path}" done + # Symlink the gcov tool such with a link called gcov. Clang comes with a tool + # called llvm-cov, which behaves like gcov if symlinked in this way (otherwise + # we would need to invoke it with "llvm-cov gcov"). + GCOV="${COVERAGE_DIR}/gcov" + ln -s "${COVERAGE_GCOV_PATH}" "${GCOV}" + # Run lcov over the .gcno and .gcda files to generate the lcov tracefile. # -c - Collect coverage data # --no-external - Do not collect coverage data for system files # --ignore-errors graph - Ignore missing .gcno files; Bazel only instruments some files + # --gcov-tool "${GCOV}" - Pass the local symlink to be uses as gcov by lcov # -d "${COVERAGE_DIR}" - Directory to search for .gcda files # -o "${COVERAGE_OUTPUT_FILE}" - Output file /usr/bin/lcov -c --no-external --ignore-errors graph \ + --gcov-tool "${GCOV}" \ -d "${COVERAGE_DIR}" -o "${COVERAGE_OUTPUT_FILE}" # The paths are all wrong, because they point to /tmp. Fix up the paths to |