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