make: add coverage target (#307)

Add coverage target for getting csv code-coverage output

Signed-off-by: Eric Ernst <eric_ernst@apple.com>
This commit is contained in:
Eric Ernst
2025-10-03 09:43:11 +01:00
committed by GitHub
parent 183255ee0e
commit f9ae8f7801
+15
View File
@@ -22,6 +22,8 @@ SWIFT_CONFIGURATION = $(if $(filter-out false,$(WARNINGS_AS_ERRORS)),-Xswiftc -w
SWIFT := "/usr/bin/swift"
ROOT_DIR := $(shell git rev-parse --show-toplevel)
BUILD_BIN_DIR = $(shell $(SWIFT) build -c $(BUILD_CONFIGURATION) --show-bin-path)
COV_DATA_DIR = $(shell $(SWIFT) test --show-coverage-path | xargs dirname)
COV_REPORT_FILE = $(ROOT_DIR)/code-coverage-report
# Variables for libarchive integration
LIBARCHIVE_UPSTREAM_REPO := https://github.com/libarchive/libarchive
@@ -90,6 +92,18 @@ test:
@echo Testing all test targets...
@$(SWIFT) test --enable-code-coverage $(SWIFT_CONFIGURATION)
.PHONY: coverage
coverage: test
@echo Generating code coverage report...
@xcrun llvm-cov show --compilation-dir=`pwd` \
-instr-profile=$(COV_DATA_DIR)/default.profdata \
--ignore-filename-regex=".build/" \
--ignore-filename-regex=".pb.swift" \
--ignore-filename-regex=".proto" \
--ignore-filename-regex=".grpc.swift" \
$(BUILD_BIN_DIR)/ContainerizationPackageTests.xctest/Contents/MacOS/ContainerizationPackageTests > $(COV_REPORT_FILE)
@echo Code coverage report generated: $(COV_REPORT_FILE)
.PHONY: integration
integration:
ifeq (,$(wildcard bin/vmlinux))
@@ -159,5 +173,6 @@ clean:
@rm -rf bin/
@rm -rf _site/
@rm -rf _serve/
@rm -f $(COV_REPORT_FILE)
@$(SWIFT) package clean
@"$(MAKE)" -C vminitd clean