Skip to content

Commit 84f042a

Browse files
committed
Move more logic into configure
1 parent 50ba4f4 commit 84f042a

File tree

3 files changed

+103
-73
lines changed

3 files changed

+103
-73
lines changed

Makefile.pre.in

+32-67
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,15 @@ HOST_GNU_TYPE= @host@
313313
# PROFILE_TASK="-m test --pgo-extended"
314314
PROFILE_TASK= @PROFILE_TASK@
315315

316-
# report files for gcov / lcov coverage report
317-
COVERAGE_INFO= $(abs_builddir)/coverage.info
318-
COVERAGE_REPORT=$(abs_builddir)/lcov-report
319-
COVERAGE_LCOV_OPTIONS=--rc lcov_branch_coverage=1
320-
COVERAGE_REPORT_OPTIONS=--rc lcov_branch_coverage=1 --branch-coverage --title "CPython $(VERSION) LCOV report [commit $(shell $(GITVERSION))]"
321-
322-
# report files for llvm-cov coverage report
323-
COVERAGE_INFO_LLVM= $(abs_builddir)/coverage.profdata
324-
COVERAGE_REPORT_LLVM=$(abs_builddir)/llvm-cov-report
325-
COVERAGE_REPORT_OPTIONS_LLVM=-show-branches=count -show-regions
316+
# parameters for coverage
317+
COVERAGE_CC=@COVERAGE_CC@
318+
COVERAGE_CFLAGS=@COVERAGE_CFLAGS@
319+
COVERAGE_LDFLAGS=@COVERAGE_LDFLAGS@
320+
COVERAGE_GEN_TARGET=@COVERAGE_GEN_TARGET@
321+
COVERAGE_INFO=$(abs_builddir)/@COVERAGE_INFO@
322+
COVERAGE_REPORT=$(abs_builddir)/coverage-report
323+
COVERAGE_OPTIONS=@COVERAGE_OPTIONS@
324+
COVERAGE_REPORT_OPTIONS=@COVERAGE_REPORT_OPTIONS@
326325

327326
# === Definitions added by makesetup ===
328327

@@ -662,36 +661,38 @@ bolt-opt: @PREBOLT_RULE@
662661
rm -f $(BUILDPYTHON).bolt_inst
663662
mv $(BUILDPYTHON).bolt $(BUILDPYTHON)
664663

665-
.PHONY=coverage-report
664+
.PHONY=coverage-report coverage coverage-generate-lcov coverage-generate-profdata
666665
coverage-report:
667-
@if [ $(CC_NAME) = "gcc" ]; then \
668-
$(MAKE) coverage-report-lcov; \
669-
elif [ $(CC_NAME) = "clang" ]; then \
670-
$(MAKE) coverage-report-llvm; \
671-
else \
672-
echo "Coverage is not supported with the $(CC_NAME) compiler"; \
673-
exit 1; \
674-
fi
666+
@ # build with coverage info
667+
$(MAKE) coverage
668+
@ # run tests, ignore failures
669+
@ # The LLVM_PROFILE_FILE must specify %m so results can be collected in parallel.
670+
@ # Also, must be an absolute path since test suite changes working directory.
671+
LLVM_PROFILE_FILE=${abs_builddir}/python%m.profraw $(TESTRUNNER) $(TESTOPTS) || true
672+
@ # build lcov report
673+
$(MAKE) $(COVERAGE_GEN_TARGET)
674+
@echo
675+
@echo "coverage report at $(COVERAGE_REPORT)/index.html"
676+
@echo
675677

676-
# Compile and run with gcov
677-
.PHONY=coverage-gcc coverage-lcov coverage-report-lcov
678-
coverage-gcc:
678+
# Compile and run generating coverage
679+
coverage:
679680
@echo "Building with support for coverage checking:"
680681
$(MAKE) clean
681-
$(MAKE) @DEF_MAKE_RULE@ CFLAGS="$(CFLAGS) -O0 -pg --coverage" LDFLAGS="$(LDFLAGS) --coverage"
682+
$(MAKE) @DEF_MAKE_RULE@ CC="$(COVERAGE_CC)" CFLAGS="$(CFLAGS) $(COVERAGE_CFLAGS)" LDFLAGS="$(LDFLAGS) $(COVERAGE_LDFLAGS)"
682683

683-
coverage-lcov:
684+
coverage-generate-lcov:
684685
@echo "Creating Coverage HTML report with LCOV:"
685686
@rm -f $(COVERAGE_INFO)
686687
@rm -rf $(COVERAGE_REPORT)
687-
@lcov $(COVERAGE_LCOV_OPTIONS) --capture \
688+
@lcov $(COVERAGE_OPTIONS) --capture \
688689
--directory $(abs_builddir) \
689690
--base-directory $(realpath $(abs_builddir)) \
690691
--path $(realpath $(abs_srcdir)) \
691692
--output-file $(COVERAGE_INFO)
692693
@ # remove 3rd party modules, system headers and internal files with
693694
@ # debug, test or dummy functions.
694-
@lcov $(COVERAGE_LCOV_OPTIONS) --remove $(COVERAGE_INFO) \
695+
@lcov $(COVERAGE_OPTIONS) --remove $(COVERAGE_INFO) \
695696
'*/Modules/_blake2/impl/*' \
696697
'*/Modules/_ctypes/libffi*/*' \
697698
'*/Modules/_decimal/libmpdec/*' \
@@ -706,51 +707,15 @@ coverage-lcov:
706707
@genhtml $(COVERAGE_INFO) \
707708
--output-directory $(COVERAGE_REPORT) \
708709
$(COVERAGE_REPORT_OPTIONS)
709-
@echo
710-
@echo "lcov report at $(COVERAGE_REPORT)/index.html"
711-
@echo
712-
713-
# Force regeneration of parser and frozen modules
714-
coverage-report-lcov: regen-token regen-frozen
715-
@ # build with coverage info
716-
$(MAKE) coverage-gcc
717-
@ # run tests, ignore failures
718-
$(TESTRUNNER) $(TESTOPTS) || true
719-
@ # build lcov report
720-
$(MAKE) coverage-lcov
721710

722-
# Compile and calculate coverage with llvm-cov
723-
.PHONY=coverage-clang coverage-profdata coverage-report-llvm
724-
725-
coverage-clang:
726-
@echo "Building with support for coverage checking:"
727-
$(MAKE) clean
728-
@ # Override CC rather than CFLAGS since these flags must come first
729-
$(MAKE) @DEF_MAKE_RULE@ CC="$(CC) -fprofile-instr-generate -fcoverage-mapping"
730-
731-
coverage-profdata:
711+
coverage-generate-profdata:
732712
@echo "Creating Coverage HTML report with llvm-profdata/llvm-cov:"
733-
@rm -f $(COVERAGE_INFO_LLVM)
734-
@rm -rf $(COVERAGE_REPORT_LLVM)
713+
@rm -f $(COVERAGE_INFO)
714+
@rm -rf $(COVERAGE_REPORT)
735715
@ # Merge coverage results
736-
$(LLVM_PROFDATA) merge -sparse python*.profraw -o $(COVERAGE_INFO_LLVM)
716+
$(LLVM_PROFDATA) merge -sparse python*.profraw -o $(COVERAGE_INFO)
737717
@ # Generate HTML
738-
$(LLVM_COV) show -format=html -output-dir=$(COVERAGE_REPORT_LLVM) -instr-profile=$(COVERAGE_INFO_LLVM) $(COVERAGE_REPORT_OPTIONS_LLVM) python .
739-
@echo
740-
@echo "llvm-cov report at $(COVERAGE_REPORT_LLVM)/index.html"
741-
@echo
742-
743-
# Force regeneration of parser and importlib
744-
# Specify the LLVM_PROFILE_FILE using %m so multiple shared objects can write
745-
# in parallel. Set the full path to the directory so results aren't written
746-
# into temporary directories created by tests.
747-
coverage-report-llvm: regen-token regen-importlib
748-
@ # build with coverage info
749-
$(MAKE) coverage-clang
750-
@ # run tests, ignore failures
751-
LLVM_PROFILE_FILE=${PWD}/python%m.profraw $(TESTRUNNER) $(TESTOPTS) || true
752-
@ # build llvm-cov report
753-
$(MAKE) coverage-profdata
718+
$(LLVM_COV) show -format=html -output-dir=$(COVERAGE_REPORT) -instr-profile=$(COVERAGE_INFO) $(COVERAGE_REPORT_OPTIONS) python .
754719

755720
# Run "Argument Clinic" over all source files
756721
.PHONY=clinic

configure

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

configure.ac

+32-2
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,6 @@ fi
869869
rm -f conftest.c conftest.out
870870
])
871871

872-
AC_SUBST([CC_NAME], [$ac_cv_cc_name])
873-
874872
# checks for UNIX variants that set C preprocessor variables
875873
# may set _GNU_SOURCE, __EXTENSIONS__, _POSIX_PTHREAD_SEMANTICS,
876874
# _POSIX_SOURCE, _POSIX_1_SOURCE, and more
@@ -2057,6 +2055,38 @@ case $CC in
20572055
LLVM_PROF_FILE=""
20582056
;;
20592057
esac
2058+
2059+
# Coverage flags
2060+
2061+
case $CC in
2062+
*clang*)
2063+
COVERAGE_CC="\$(CC) -fprofile-instr-generate -fcoverage-mapping"
2064+
COVERAGE_CFLAGS=""
2065+
COVERAGE_LDFLAGS=""
2066+
COVERAGE_GEN_TARGET="coverage-generate-profdata"
2067+
COVERAGE_INFO="coverage.profdata"
2068+
COVERAGE_OPTIONS=""
2069+
COVERAGE_REPORT_OPTIONS="-show-branches=count -show-regions"
2070+
;;
2071+
*gcc*)
2072+
COVERAGE_CC="\$(CC)"
2073+
COVERAGE_CFLAGS="-O0 -pg --coverage"
2074+
COVERAGE_LDFLAGS="--coverage"
2075+
COVERAGE_GEN_TARGET="coverage-generate-lcov"
2076+
COVERAGE_INFO="coverage.info"
2077+
COVERAGE_OPTIONS="--rc lcov_brange_coverage=1"
2078+
COVERAGE_REPORT_OPTIONS="\$(COVERAGE_OPTIONS) --branch-coverage --title \"CPython \$(VERSION) LCOV report [commit \$(shell \$(GITVERSION))]\""
2079+
;;
2080+
*)
2081+
esac
2082+
2083+
AC_SUBST(COVERAGE_CC)
2084+
AC_SUBST(COVERAGE_CFLAGS)
2085+
AC_SUBST(COVERAGE_LDFLAGS)
2086+
AC_SUBST(COVERAGE_GEN_TARGET)
2087+
AC_SUBST(COVERAGE_INFO)
2088+
AC_SUBST(COVERAGE_OPTIONS)
2089+
AC_SUBST(COVERAGE_REPORT_OPTIONS)
20602090
AC_SUBST(LLVM_COV)
20612091
AC_PATH_TOOL(LLVM_COV, llvm-cov, '', ${llvm_path})
20622092

0 commit comments

Comments
 (0)