@@ -51,6 +51,8 @@ PGO_PROF_USE_FLAG=@PGO_PROF_USE_FLAG@
51
51
LLVM_PROF_MERGER=@LLVM_PROF_MERGER@
52
52
LLVM_PROF_FILE=@LLVM_PROF_FILE@
53
53
LLVM_PROF_ERR=@LLVM_PROF_ERR@
54
+ LLVM_PROFDATA=@LLVM_PROFDATA@
55
+ LLVM_COV=@LLVM_COV@
54
56
DTRACE= @DTRACE@
55
57
DFLAGS= @DFLAGS@
56
58
DTRACE_HEADERS= @DTRACE_HEADERS@
@@ -321,6 +323,10 @@ COVERAGE_REPORT=$(abs_builddir)/lcov-report
321
323
COVERAGE_LCOV_OPTIONS=--rc lcov_branch_coverage=1
322
324
COVERAGE_REPORT_OPTIONS=--rc lcov_branch_coverage=1 --branch-coverage --title "CPython $(VERSION) LCOV report [commit $(shell $(GITVERSION))]"
323
325
326
+ # report files for llvm-cov coverage report
327
+ COVERAGE_INFO_LLVM= $(abs_builddir)/coverage.profdata
328
+ COVERAGE_REPORT_LLVM=$(abs_builddir)/llvm-cov-report
329
+ COVERAGE_REPORT_OPTIONS_LLVM=-show-branches=count -show-regions
324
330
325
331
# === Definitions added by makesetup ===
326
332
@@ -693,6 +699,44 @@ coverage-report: regen-token regen-frozen
693
699
@ # build lcov report
694
700
$(MAKE) coverage-lcov
695
701
702
+ # Compile and calculate coverage with llvm-cov
703
+ .PHONY=check-clang coverage-llvm coverage-profdata coverage-report-llvm
704
+
705
+ # Check whether the compiler is clang, and if not, error out.
706
+ check-clang:
707
+ ($(CC) --version | grep clang) || \
708
+ (echo "LLVM coverage only works with clang. Set CC=clang and CXX=clang++ and re-run ./configure"; exit 1)
709
+
710
+ coverage-llvm: check-clang
711
+ @echo "Building with support for coverage checking:"
712
+ $(MAKE) clean
713
+ @ # Override CC rather than CFLAGS since these flags must come first
714
+ $(MAKE) @DEF_MAKE_RULE@ CC="$(CC) -fprofile-instr-generate -fcoverage-mapping"
715
+
716
+ coverage-profdata:
717
+ @echo "Creating Coverage HTML report with llvm-profdata/llvm-cov:"
718
+ @rm -f $(COVERAGE_INFO_LLVM)
719
+ @rm -rf $(COVERAGE_REPORT_LLVM)
720
+ @ # Merge coverage results
721
+ $(LLVM_PROFDATA) merge -sparse python*.profraw -o $(COVERAGE_INFO_LLVM)
722
+ @ # Generate HTML
723
+ $(LLVM_COV) show -format=html -output-dir=$(COVERAGE_REPORT_LLVM) -instr-profile=$(COVERAGE_INFO_LLVM) $(COVERAGE_REPORT_OPTIONS_LLVM) python .
724
+ @echo
725
+ @echo "llvm-cov report at $(COVERAGE_REPORT_LLVM)/index.html"
726
+ @echo
727
+
728
+ # Force regeneration of parser and importlib
729
+ # Specify the LLVM_PROFILE_FILE using %m so multiple shared objects can write
730
+ # in parallel. Set the full path to the directory so results aren't written
731
+ # into temporary directories created by tests.
732
+ coverage-report-llvm: regen-token regen-importlib
733
+ @ # build with coverage info
734
+ $(MAKE) coverage-llvm
735
+ @ # run tests, ignore failures
736
+ LLVM_PROFILE_FILE=${PWD}/python%m.profraw $(TESTRUNNER) $(TESTOPTS) || true
737
+ @ # build llvm-cov report
738
+ $(MAKE) coverage-profdata
739
+
696
740
# Run "Argument Clinic" over all source files
697
741
.PHONY=clinic
698
742
clinic: check-clean-src $(srcdir)/Modules/_blake2/blake2s_impl.c
0 commit comments