Skip to content

Commit 19c04d2

Browse files
committed
Automatically select the coverage approach based on the compiler
1 parent 4affb6a commit 19c04d2

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

.github/workflows/c-coverage.yml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 18 additions & 11 deletions
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@
@@ -656,9 +657,20 @@ bolt-opt: @PREBOLT_RULE@
656657
rm -f $(BUILDPYTHON).bolt_inst
657658
mv $(BUILDPYTHON).bolt $(BUILDPYTHON)
658659

660+
.PHONY=coverage-report
661+
coverage-report:
662+
@if [ $(CC_NAME) = "gcc" ]; then \
663+
$(MAKE) coverage-report-lcov; \
664+
elif [ $(CC_NAME) = "clang" ]; then \
665+
$(MAKE) coverage-report-llvm; \
666+
else \
667+
echo "Coverage is not supported with the $(CC_NAME) compiler"; \
668+
exit 1; \
669+
fi
670+
659671
# Compile and run with gcov
660-
.PHONY=coverage coverage-lcov coverage-report
661-
coverage:
672+
.PHONY=coverage-gcc coverage-lcov coverage-report-lcov
673+
coverage-gcc:
662674
@echo "Building with support for coverage checking:"
663675
$(MAKE) clean
664676
$(MAKE) @DEF_MAKE_RULE@ CFLAGS="$(CFLAGS) -O0 -pg --coverage" LDFLAGS="$(LDFLAGS) --coverage"
@@ -694,7 +706,7 @@ coverage-lcov:
694706
@echo
695707

696708
# Force regeneration of parser and frozen modules
697-
coverage-report: regen-token regen-frozen
709+
coverage-report-lcov: regen-token regen-frozen
698710
@ # build with coverage info
699711
$(MAKE) coverage
700712
@ # run tests, ignore failures
@@ -703,14 +715,9 @@ coverage-report: regen-token regen-frozen
703715
$(MAKE) coverage-lcov
704716

705717
# Compile and calculate coverage with llvm-cov
706-
.PHONY=check-clang coverage-llvm coverage-profdata coverage-report-llvm
707-
708-
# Check whether the compiler is clang, and if not, error out.
709-
check-clang:
710-
($(CC) --version | grep clang) || \
711-
(echo "LLVM coverage only works with clang. Set CC=clang and CXX=clang++ and re-run ./configure"; exit 1)
718+
.PHONY=coverage-clang coverage-profdata coverage-report-llvm
712719

713-
coverage-llvm: check-clang
720+
coverage-clang:
714721
@echo "Building with support for coverage checking:"
715722
$(MAKE) clean
716723
@ # Override CC rather than CFLAGS since these flags must come first
@@ -734,7 +741,7 @@ coverage-profdata:
734741
# into temporary directories created by tests.
735742
coverage-report-llvm: regen-token regen-importlib
736743
@ # build with coverage info
737-
$(MAKE) coverage-llvm
744+
$(MAKE) coverage-clang
738745
@ # run tests, ignore failures
739746
LLVM_PROFILE_FILE=${PWD}/python%m.profraw $(TESTRUNNER) $(TESTOPTS) || true
740747
@ # build llvm-cov report
Lines changed: 2 additions & 4 deletions
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

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,9 @@ fi
869869
rm -f conftest.c conftest.out
870870
])
871871

872+
AC_SUBST(CC_NAME)
873+
CC_NAME=$ac_cv_cc_name
874+
872875
# checks for UNIX variants that set C preprocessor variables
873876
# may set _GNU_SOURCE, __EXTENSIONS__, _POSIX_PTHREAD_SEMANTICS,
874877
# _POSIX_SOURCE, _POSIX_1_SOURCE, and more

0 commit comments

Comments
 (0)