Skip to content

Commit 90c69ce

Browse files
committed
Automatically select the coverage approach based on the compiler
1 parent 502483e commit 90c69ce

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
@@ -37,6 +37,7 @@ abs_builddir= @abs_builddir@
3737
CC= @CC@
3838
CXX= @CXX@
3939
LINKCC= @LINKCC@
40+
CC_NAME=@CC_NAME@
4041
AR= @AR@
4142
READELF= @READELF@
4243
SOABI= @SOABI@
@@ -646,9 +647,20 @@ profile-opt: profile-run-stamp
646647
-rm -f profile-clean-stamp
647648
$(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS_NODIST) $(PGO_PROF_USE_FLAG)" LDFLAGS_NODIST="$(LDFLAGS_NODIST)"
648649

650+
.PHONY=coverage-report
651+
coverage-report:
652+
@if [ $(CC_NAME) = "gcc" ]; then \
653+
$(MAKE) coverage-report-lcov; \
654+
elif [ $(CC_NAME) = "clang" ]; then \
655+
$(MAKE) coverage-report-llvm; \
656+
else \
657+
echo "Coverage is not supported with the $(CC_NAME) compiler"; \
658+
exit 1; \
659+
fi
660+
649661
# Compile and run with gcov
650-
.PHONY=coverage coverage-lcov coverage-report
651-
coverage:
662+
.PHONY=coverage-gcc coverage-lcov coverage-report-lcov
663+
coverage-gcc:
652664
@echo "Building with support for coverage checking:"
653665
$(MAKE) clean
654666
$(MAKE) @DEF_MAKE_RULE@ CFLAGS="$(CFLAGS) -O0 -pg --coverage" LDFLAGS="$(LDFLAGS) --coverage"
@@ -684,7 +696,7 @@ coverage-lcov:
684696
@echo
685697

686698
# Force regeneration of parser and frozen modules
687-
coverage-report: regen-token regen-frozen
699+
coverage-report-lcov: regen-token regen-frozen
688700
@ # build with coverage info
689701
$(MAKE) coverage
690702
@ # run tests, ignore failures
@@ -693,14 +705,9 @@ coverage-report: regen-token regen-frozen
693705
$(MAKE) coverage-lcov
694706

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

703-
coverage-llvm: check-clang
710+
coverage-clang:
704711
@echo "Building with support for coverage checking:"
705712
$(MAKE) clean
706713
@ # Override CC rather than CFLAGS since these flags must come first
@@ -724,7 +731,7 @@ coverage-profdata:
724731
# into temporary directories created by tests.
725732
coverage-report-llvm: regen-token regen-importlib
726733
@ # build with coverage info
727-
$(MAKE) coverage-llvm
734+
$(MAKE) coverage-clang
728735
@ # run tests, ignore failures
729736
LLVM_PROFILE_FILE=${PWD}/python%m.profraw $(TESTRUNNER) $(TESTOPTS) || true
730737
@ # 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)