Skip to content

Commit ddcc5e9

Browse files
committed
Move more logic into configure
1 parent 775d154 commit ddcc5e9

File tree

3 files changed

+103
-73
lines changed

3 files changed

+103
-73
lines changed

Makefile.pre.in

Lines changed: 32 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,15 @@ HOST_GNU_TYPE= @host@
311311
# PROFILE_TASK="-m test --pgo-extended"
312312
PROFILE_TASK= @PROFILE_TASK@
313313

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

325324
# === Definitions added by makesetup ===
326325

@@ -658,36 +657,38 @@ bolt-opt: @PREBOLT_RULE@
658657
rm -f $(BUILDPYTHON).bolt_inst
659658
mv $(BUILDPYTHON).bolt $(BUILDPYTHON)
660659

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

672-
# Compile and run with gcov
673-
.PHONY=coverage-gcc coverage-lcov coverage-report-lcov
674-
coverage-gcc:
674+
# Compile and run generating coverage
675+
coverage:
675676
@echo "Building with support for coverage checking:"
676677
$(MAKE) clean
677-
$(MAKE) @DEF_MAKE_RULE@ CFLAGS="$(CFLAGS) -O0 -pg --coverage" LDFLAGS="$(LDFLAGS) --coverage"
678+
$(MAKE) @DEF_MAKE_RULE@ CC="$(COVERAGE_CC)" CFLAGS="$(CFLAGS) $(COVERAGE_CFLAGS)" LDFLAGS="$(LDFLAGS) $(COVERAGE_LDFLAGS)"
678679

679-
coverage-lcov:
680+
coverage-generate-lcov:
680681
@echo "Creating Coverage HTML report with LCOV:"
681682
@rm -f $(COVERAGE_INFO)
682683
@rm -rf $(COVERAGE_REPORT)
683-
@lcov $(COVERAGE_LCOV_OPTIONS) --capture \
684+
@lcov $(COVERAGE_OPTIONS) --capture \
684685
--directory $(abs_builddir) \
685686
--base-directory $(realpath $(abs_builddir)) \
686687
--path $(realpath $(abs_srcdir)) \
687688
--output-file $(COVERAGE_INFO)
688689
@ # remove 3rd party modules, system headers and internal files with
689690
@ # debug, test or dummy functions.
690-
@lcov $(COVERAGE_LCOV_OPTIONS) --remove $(COVERAGE_INFO) \
691+
@lcov $(COVERAGE_OPTIONS) --remove $(COVERAGE_INFO) \
691692
'*/Modules/_blake2/impl/*' \
692693
'*/Modules/_ctypes/libffi*/*' \
693694
'*/Modules/_decimal/libmpdec/*' \
@@ -702,51 +703,15 @@ coverage-lcov:
702703
@genhtml $(COVERAGE_INFO) \
703704
--output-directory $(COVERAGE_REPORT) \
704705
$(COVERAGE_REPORT_OPTIONS)
705-
@echo
706-
@echo "lcov report at $(COVERAGE_REPORT)/index.html"
707-
@echo
708-
709-
# Force regeneration of parser and frozen modules
710-
coverage-report-lcov: regen-token regen-frozen
711-
@ # build with coverage info
712-
$(MAKE) coverage-gcc
713-
@ # run tests, ignore failures
714-
$(TESTRUNNER) $(TESTOPTS) || true
715-
@ # build lcov report
716-
$(MAKE) coverage-lcov
717706

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

751716
# Run "Argument Clinic" over all source files
752717
.PHONY=clinic

configure

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

configure.ac

Lines changed: 32 additions & 2 deletions
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
@@ -2047,6 +2045,38 @@ case $CC in
20472045
LLVM_PROF_FILE=""
20482046
;;
20492047
esac
2048+
2049+
# Coverage flags
2050+
2051+
case $CC in
2052+
*clang*)
2053+
COVERAGE_CC="\$(CC) -fprofile-instr-generate -fcoverage-mapping"
2054+
COVERAGE_CFLAGS=""
2055+
COVERAGE_LDFLAGS=""
2056+
COVERAGE_GEN_TARGET="coverage-generate-profdata"
2057+
COVERAGE_INFO="coverage.profdata"
2058+
COVERAGE_OPTIONS=""
2059+
COVERAGE_REPORT_OPTIONS="-show-branches=count -show-regions"
2060+
;;
2061+
*gcc*)
2062+
COVERAGE_CC="\$(CC)"
2063+
COVERAGE_CFLAGS="-O0 -pg --coverage"
2064+
COVERAGE_LDFLAGS="--coverage"
2065+
COVERAGE_GEN_TARGET="coverage-generate-lcov"
2066+
COVERAGE_INFO="coverage.info"
2067+
COVERAGE_OPTIONS="--rc lcov_brange_coverage=1"
2068+
COVERAGE_REPORT_OPTIONS="\$(COVERAGE_OPTIONS) --branch-coverage --title \"CPython \$(VERSION) LCOV report [commit \$(shell \$(GITVERSION))]\""
2069+
;;
2070+
*)
2071+
esac
2072+
2073+
AC_SUBST(COVERAGE_CC)
2074+
AC_SUBST(COVERAGE_CFLAGS)
2075+
AC_SUBST(COVERAGE_LDFLAGS)
2076+
AC_SUBST(COVERAGE_GEN_TARGET)
2077+
AC_SUBST(COVERAGE_INFO)
2078+
AC_SUBST(COVERAGE_OPTIONS)
2079+
AC_SUBST(COVERAGE_REPORT_OPTIONS)
20502080
AC_SUBST(LLVM_COV)
20512081
AC_PATH_TOOL(LLVM_COV, llvm-cov, '', ${llvm_path})
20522082

0 commit comments

Comments
 (0)