aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar lberki <lberki@google.com>2017-05-23 17:48:14 +0200
committerGravatar Irina Iancu <elenairina@google.com>2017-05-23 20:12:04 +0200
commit8a5752dcaa30fe7cd754c88d5b0230e75aed0c70 (patch)
tree97bd82af8773ccf2efd0d59e1ca324c237ef8af5 /tools
parentf6c4d6d66118410b1139a84fe34ba8134661bfa2 (diff)
Add functionality from the old shell-based coverage runner script to the new one.
This isn't a principled solution, but since it depends on /usr/bin/lcov, it should never be relied on at all. It's mostly a courtesy to people who came to use C++ coverage in Bazel before we removed it. Fixes #2685. Progress on #1118. RELNOTES: None. PiperOrigin-RevId: 156866370
Diffstat (limited to 'tools')
-rwxr-xr-xtools/coverage/collect-coverage.sh58
-rwxr-xr-xtools/test/collect_coverage.sh52
2 files changed, 46 insertions, 64 deletions
diff --git a/tools/coverage/collect-coverage.sh b/tools/coverage/collect-coverage.sh
index 85875c08a2..f54b622362 100755
--- a/tools/coverage/collect-coverage.sh
+++ b/tools/coverage/collect-coverage.sh
@@ -1,5 +1,4 @@
#!/bin/bash
-
# Copyright 2016 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,59 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-ROOT="$PWD"
-if [[ $COVERAGE_OUTPUT_FILE != /* ]]; then
- COVERAGE_OUTPUT_FILE="${ROOT}/${COVERAGE_OUTPUT_FILE}"
-fi
-if [[ "$COVERAGE_MANIFEST" != /* ]]; then
- export COVERAGE_MANIFEST="${ROOT}/${COVERAGE_MANIFEST}"
-fi
-
-export COVERAGE_DIR="$(mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX)"
-trap "{ rm -rf ${COVERAGE_DIR} }" EXIT
-
-# C++ env variables
-export GCOV_PREFIX_STRIP=3
-export GCOV_PREFIX="${COVERAGE_DIR}"
-
-touch "${COVERAGE_OUTPUT_FILE}"
-
-DIR="$TEST_SRCDIR"
-if [ ! -z "$TEST_WORKSPACE" ]; then
- DIR="$DIR"/"$TEST_WORKSPACE"
-fi
-cd "$DIR" || { echo "Could not chdir $DIR"; exit 1; }
-"$@"
-TEST_STATUS=$?
-
-if [[ ${TEST_STATUS} -ne 0 ]]; then
- echo "--"
- echo "Coverage runner: Not collecting coverage for failed test."
- echo "The following commands failed with status ${TEST_STATUS}:"
- echo "$@"
- exit ${TEST_STATUS}
-fi
-
-echo "--"
-echo "Post-processing coverage results:"
-
-cat "${COVERAGE_MANIFEST}" | grep ".gcno$" | while read path; do
- mkdir -p "${COVERAGE_DIR}/$(dirname ${path})"
- 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
-
-# Run lcov over the .gcno and .gcda files to generate the lcov tracefile.
-/usr/bin/lcov -c --no-external -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}).
-sed -i -e "s*${COVERAGE_DIR}*${ROOT}*g" "${COVERAGE_OUTPUT_FILE}"
+# This file should be removed.
+exit 1
diff --git a/tools/test/collect_coverage.sh b/tools/test/collect_coverage.sh
index 33aa2e373c..b8e1dc7ddb 100755
--- a/tools/test/collect_coverage.sh
+++ b/tools/test/collect_coverage.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -x
# Copyright 2016 The Bazel Authors. All rights reserved.
#
@@ -25,6 +25,15 @@
# Script expects that it will be started in the execution root directory and
# not in the test's runfiles directory.
+if [[ -z "$LCOV_MERGER" ]]; then
+ echo --
+ echo "Coverage collection running in legacy mode."
+ echo "Legacy mode only supports C++ and even then, it's very brittle."
+ COVERAGE_LEGACY_MODE=1
+else
+ COVERAGE_LEGACY_MODE=
+fi
+
if [[ -z "$COVERAGE_MANIFEST" ]]; then
echo --
echo Coverage runner: \$COVERAGE_MANIFEST is not set
@@ -66,7 +75,7 @@ export BULK_COVERAGE_RUN=1
# Only check if file exists when LCOV_MERGER is set
-if [[ ! -z "$LCOV_MERGER" ]]; then
+if [[ ! "$COVERAGE_LEGACY_MODE" ]]; then
for name in "$LCOV_MERGER"; do
if [[ ! -e $name ]]; then
echo --
@@ -76,17 +85,15 @@ if [[ ! -z "$LCOV_MERGER" ]]; then
done
fi
+if [[ "$COVERAGE_LEGACY_MODE" ]]; then
+ export GCOV_PREFIX_STRIP=3
+ export GCOV_PREFIX="${COVERAGE_DIR}"
+fi
cd "$TEST_SRCDIR"
"$@"
TEST_STATUS=$?
-# If LCOV_MERGER is not set, coverage is not supported.
-if [[ -z "$LCOV_MERGER" ]]; then
- exit $TEST_STATUS
-fi
-
-
# always create output files
touch $COVERAGE_OUTPUT_FILE
@@ -100,6 +107,35 @@ fi
cd $ROOT
+# If LCOV_MERGER is not set, use the legacy, awful, C++-only method to convert
+# coverage files.
+# NB: This is here just so that we don't regress. Do not add support for new
+# coverage features here. Implement it instead properly in LcovMerger.
+if [[ "$COVERAGE_LEGACY_MODE" ]]; then
+ cat "${COVERAGE_MANIFEST}" | grep ".gcno$" | while read path; do
+ mkdir -p "${COVERAGE_DIR}/$(dirname ${path})"
+ 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
+
+ # Run lcov over the .gcno and .gcda files to generate the lcov tracefile.
+ /usr/bin/lcov -c --no-external -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}).
+ sed -i -e "s*${COVERAGE_DIR}*${ROOT}*g" "${COVERAGE_OUTPUT_FILE}"
+
+ exit $TEST_STATUS
+fi
+
export LCOV_MERGER_CMD="java -jar ${LCOV_MERGER} --coverage_dir=${COVERAGE_DIR} \
--output_file=${COVERAGE_OUTPUT_FILE}"