Skip to content

Commit 58e38af

Browse files
committedJul 18, 2022
Automatically select the coverage approach based on the compiler
1 parent d996775 commit 58e38af

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed
 

‎.github/workflows/c-coverage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
run: ./configure --with-pydebug --with-openssl=$OPENSSL_DIR
4747
- name: Generate coverage report
4848
# Using "-j1" is important, or the Github Action runs out of memory
49-
run: EXTRATESTOPTS=-j1 xvfb-run make coverage-report-llvm
49+
run: EXTRATESTOPTS=-j1 xvfb-run make coverage-report
5050
- name: Publish coverage-report
5151
uses: JamesIves/github-pages-deploy-action@v4
5252
with:

‎Makefile.pre.in

+18-11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ CC= @CC@
3838
CXX= @CXX@
3939
MAINCC= @MAINCC@
4040
LINKCC= @LINKCC@
41+
CC_NAME=@CC_NAME@
4142
AR= @AR@
4243
READELF= @READELF@
4344
SOABI= @SOABI@
@@ -648,9 +649,20 @@ profile-opt: profile-run-stamp
648649
-rm -f profile-clean-stamp
649650
$(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS_NODIST) $(PGO_PROF_USE_FLAG)" LDFLAGS_NODIST="$(LDFLAGS_NODIST)"
650651

652+
.PHONY=coverage-report
653+
coverage-report:
654+
@if [ $(CC_NAME) = "gcc" ]; then \
655+
$(MAKE) coverage-report-lcov; \
656+
elif [ $(CC_NAME) = "clang" ]; then \
657+
$(MAKE) coverage-report-llvm; \
658+
else \
659+
echo "Coverage is not supported with the $(CC_NAME) compiler"; \
660+
exit 1; \
661+
fi
662+
651663
# Compile and run with gcov
652-
.PHONY=coverage coverage-lcov coverage-report
653-
coverage:
664+
.PHONY=coverage-gcc coverage-lcov coverage-report-lcov
665+
coverage-gcc:
654666
@echo "Building with support for coverage checking:"
655667
$(MAKE) clean
656668
$(MAKE) @DEF_MAKE_RULE@ CFLAGS="$(CFLAGS) -O0 -pg --coverage" LDFLAGS="$(LDFLAGS) --coverage"
@@ -686,7 +698,7 @@ coverage-lcov:
686698
@echo
687699

688700
# Force regeneration of parser and frozen modules
689-
coverage-report: regen-token regen-frozen
701+
coverage-report-lcov: regen-token regen-frozen
690702
@ # build with coverage info
691703
$(MAKE) coverage
692704
@ # run tests, ignore failures
@@ -695,14 +707,9 @@ coverage-report: regen-token regen-frozen
695707
$(MAKE) coverage-lcov
696708

697709
# Compile and calculate coverage with llvm-cov
698-
.PHONY=check-clang coverage-llvm coverage-profdata coverage-report-llvm
699-
700-
# Check whether the compiler is clang, and if not, error out.
701-
check-clang:
702-
($(CC) --version | grep clang) || \
703-
(echo "LLVM coverage only works with clang. Set CC=clang and CXX=clang++ and re-run ./configure"; exit 1)
710+
.PHONY=coverage-clang coverage-profdata coverage-report-llvm
704711

705-
coverage-llvm: check-clang
712+
coverage-clang:
706713
@echo "Building with support for coverage checking:"
707714
$(MAKE) clean
708715
@ # Override CC rather than CFLAGS since these flags must come first
@@ -726,7 +733,7 @@ coverage-profdata:
726733
# into temporary directories created by tests.
727734
coverage-report-llvm: regen-token regen-importlib
728735
@ # build with coverage info
729-
$(MAKE) coverage-llvm
736+
$(MAKE) coverage-clang
730737
@ # run tests, ignore failures
731738
LLVM_PROFILE_FILE=${PWD}/python%m.profraw $(TESTRUNNER) $(TESTOPTS) || true
732739
@ # build llvm-cov report
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
A new Makefile target ``coverage-report-llvm`` will use ``clang`` and
2-
``llvm-cov`` to generate a coverage report. This provides more details about
3-
branch coverage and subexpressions than the existing ``gcc`` and ``lcov``
4-
based ``coverage-report``.
1+
The ``coverage-report`` Makefile target will now automatically use ``llvm-cov`` to generate a coverage report when using ``clang``.
2+
This provides more details about branch coverage and subexpressions than the existing ``gcc`` and ``lcov`` based ``coverage-report``.

‎configure

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac

+3
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,9 @@ fi
859859
rm -f conftest.c conftest.out
860860
])
861861

862+
AC_SUBST(CC_NAME)
863+
CC_NAME=$ac_cv_cc_name
864+
862865
# checks for UNIX variants that set C preprocessor variables
863866
# may set _GNU_SOURCE, __EXTENSIONS__, _POSIX_PTHREAD_SEMANTICS,
864867
# _POSIX_SOURCE, _POSIX_1_SOURCE, and more

0 commit comments

Comments
 (0)