@@ -51,6 +51,8 @@ PGO_PROF_USE_FLAG=@PGO_PROF_USE_FLAG@
5151LLVM_PROF_MERGER=@LLVM_PROF_MERGER@
5252LLVM_PROF_FILE=@LLVM_PROF_FILE@
5353LLVM_PROF_ERR=@LLVM_PROF_ERR@
54+ LLVM_PROFDATA=@LLVM_PROFDATA@
55+ LLVM_COV=@LLVM_COV@
5456DTRACE= @DTRACE@
5557DFLAGS= @DFLAGS@
5658DTRACE_HEADERS= @DTRACE_HEADERS@
@@ -321,6 +323,10 @@ COVERAGE_REPORT=$(abs_builddir)/lcov-report
321323COVERAGE_LCOV_OPTIONS=--rc lcov_branch_coverage=1
322324COVERAGE_REPORT_OPTIONS=--rc lcov_branch_coverage=1 --branch-coverage --title "CPython $(VERSION) LCOV report [commit $(shell $(GITVERSION))]"
323325
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
324330
325331# === Definitions added by makesetup ===
326332
@@ -693,6 +699,44 @@ coverage-report: regen-token regen-frozen
693699 @ # build lcov report
694700 $(MAKE) coverage-lcov
695701
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+
696740# Run "Argument Clinic" over all source files
697741.PHONY=clinic
698742clinic: check-clean-src $(srcdir)/Modules/_blake2/blake2s_impl.c
0 commit comments