diff options
author | Ulf Adams <ulfjack@google.com> | 2018-05-16 05:33:44 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-16 05:35:00 -0700 |
commit | cbe76004a2e73bfca7320e8e028ff81622b380cd (patch) | |
tree | 78eea24b7eece7a8a05f103e64df491d8d62ebee /tools | |
parent | 4c6e784c40c90240f0a9e59e76d54b2c9aa673f2 (diff) |
Rewrite lcov path munging to make the paths all relative
This makes coverage work with sandboxing, and gets rid of a previous workaround.
The only downside is that it requires running genhtml in the exec root in order
to be able to resolve relative pahts to source files, like so:
(GENHTML_CMD="genhtml -o $(pwd)/report/ -p "$(readlink -f bazel-project)" $(readlink -f bazel-testlogs)/path/to/coverage.dat" && cd bazel-project && $GENHTML_CMD)
Closes #5043.
PiperOrigin-RevId: 196814568
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/test/collect_coverage.sh | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/tools/test/collect_coverage.sh b/tools/test/collect_coverage.sh index 143696a912..a18edf30c2 100755 --- a/tools/test/collect_coverage.sh +++ b/tools/test/collect_coverage.sh @@ -124,15 +124,6 @@ elif [[ "$COVERAGE_LEGACY_MODE" ]]; then cp "${ROOT}/${path}" "${COVERAGE_DIR}/${path}" done - # Unfortunately, lcov messes up the source file names if it can't find the - # files at their relative paths. Workaround by creating empty source files - # according to the manifest (i.e., only for files that are supposed to be - # instrumented). - cat "${COVERAGE_MANIFEST}" | egrep ".(cc|h)$" | while read path; do - mkdir -p "${COVERAGE_DIR}/$(dirname ${path})" - 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"). @@ -140,20 +131,21 @@ elif [[ "$COVERAGE_LEGACY_MODE" ]]; then 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 + # -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 + # -q - Quiet mode # --gcov-tool "${GCOV}" - Pass the local symlink to be uses as gcov by lcov - # -d "${COVERAGE_DIR}" - Directory to search for .gcda files + # -b /proc/self/cwd - Use this as a prefix for all source files instead of + # the current directory + # -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}" \ + /usr/bin/lcov -c --no-external --ignore-errors graph -q \ + --gcov-tool "${GCOV}" -b /proc/self/cwd \ -d "${COVERAGE_DIR}" -o "${COVERAGE_OUTPUT_FILE}" - # The paths are all wrong, because they point to /tmp. Fix up the paths to - # point to the exec root instead (${ROOT}). - # This does not work with sandboxing, because ${ROOT} points to the sandbox dir. - sed -i -e "s*${COVERAGE_DIR}*${ROOT}*g" "${COVERAGE_OUTPUT_FILE}" + # Fix up the paths to be relative by removing the prefix we specified above. + sed -i -e "s*/proc/self/cwd/**g" "${COVERAGE_OUTPUT_FILE}" exit $TEST_STATUS fi |