Skip to content

Commit 7f628d7

Browse files
c-mitacopybara-github
authored andcommitted
Check if json.gz files exist, not the gcov version.
Different versions of gcov output different types of files; older versions output textual data, newer ones output compressed JSON files (the switch happens in gcov). "llvm-cov gcov" is supposed to be compatible with gcov, but never outputs compressed JSON files. This means the version check will break if gcov is substituted with this tool. Checking for the output files created should avoid this issue, and be a more robust check overall. Fixes #18874 Closes #18878. PiperOrigin-RevId: 546901422 Change-Id: Ibcff1310de06bc8bd4637ad8a22f719d7608ea20
1 parent 192702c commit 7f628d7

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

tools/test/collect_cc_coverage.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,10 @@ function gcov_coverage() {
150150
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84879).
151151
"${GCOV}" -i $COVERAGE_GCOV_OPTIONS -o "$(dirname ${gcda})" "${gcda}"
152152

153-
# Extract gcov's version: the output of `gcov --version` contains the
154-
# version as a set of major-minor-patch numbers, of which we extract
155-
# the major version.
156-
gcov_major_version=$("${GCOV}" --version | sed -n -E -e 's/^.*\s([0-9]+)\.[0-9]+\.[0-9]+\s?.*$/\1/p')
157-
158-
# Check the gcov version so we can process the data correctly
159-
if [[ $gcov_major_version -ge 9 ]]; then
160-
# gcov 9 or higher use a JSON based format for their coverage reports.
161-
# The output is generated into multiple files: "$(basename ${gcda}).gcov.json.gz"
153+
# Check the type of output: gcov 9 or later outputs compressed JSON
154+
# files, but earlier versions of gcov, and all versions of llvm-cov,
155+
# do not. These output textual information.
156+
if stat --printf='' *.gcov.json.gz > /dev/null 2>&1; then
162157
# Concatenating JSON documents does not yield a valid document, so they are moved individually
163158
mv -- *.gcov.json.gz "$(dirname "$output_file")/$(dirname ${gcno_path})"
164159
else

0 commit comments

Comments
 (0)