@@ -313,16 +313,15 @@ HOST_GNU_TYPE= @host@
313
313
# PROFILE_TASK="-m test --pgo-extended"
314
314
PROFILE_TASK= @PROFILE_TASK@
315
315
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@
326
325
327
326
# === Definitions added by makesetup ===
328
327
@@ -662,36 +661,38 @@ bolt-opt: @PREBOLT_RULE@
662
661
rm -f $(BUILDPYTHON).bolt_inst
663
662
mv $(BUILDPYTHON).bolt $(BUILDPYTHON)
664
663
665
- .PHONY=coverage-report
664
+ .PHONY=coverage-report coverage coverage-generate-lcov coverage-generate-profdata
666
665
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
675
677
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:
679
680
@echo "Building with support for coverage checking:"
680
681
$(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) "
682
683
683
- coverage-lcov:
684
+ coverage-generate- lcov:
684
685
@echo "Creating Coverage HTML report with LCOV:"
685
686
@rm -f $(COVERAGE_INFO)
686
687
@rm -rf $(COVERAGE_REPORT)
687
- @lcov $(COVERAGE_LCOV_OPTIONS ) --capture \
688
+ @lcov $(COVERAGE_OPTIONS ) --capture \
688
689
--directory $(abs_builddir) \
689
690
--base-directory $(realpath $(abs_builddir)) \
690
691
--path $(realpath $(abs_srcdir)) \
691
692
--output-file $(COVERAGE_INFO)
692
693
@ # remove 3rd party modules, system headers and internal files with
693
694
@ # debug, test or dummy functions.
694
- @lcov $(COVERAGE_LCOV_OPTIONS ) --remove $(COVERAGE_INFO) \
695
+ @lcov $(COVERAGE_OPTIONS ) --remove $(COVERAGE_INFO) \
695
696
'*/Modules/_blake2/impl/*' \
696
697
'*/Modules/_ctypes/libffi*/*' \
697
698
'*/Modules/_decimal/libmpdec/*' \
@@ -706,51 +707,15 @@ coverage-lcov:
706
707
@genhtml $(COVERAGE_INFO) \
707
708
--output-directory $(COVERAGE_REPORT) \
708
709
$(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
721
710
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:
732
712
@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 )
735
715
@ # Merge coverage results
736
- $(LLVM_PROFDATA) merge -sparse python*.profraw -o $(COVERAGE_INFO_LLVM )
716
+ $(LLVM_PROFDATA) merge -sparse python*.profraw -o $(COVERAGE_INFO )
737
717
@ # 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 .
754
719
755
720
# Run "Argument Clinic" over all source files
756
721
.PHONY=clinic
0 commit comments