From f9ae8f780100f9dfd287b8c9a7584faa0961ba6e Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Fri, 3 Oct 2025 09:43:11 +0100 Subject: [PATCH] make: add coverage target (#307) Add coverage target for getting csv code-coverage output Signed-off-by: Eric Ernst --- Makefile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Makefile b/Makefile index 0946776..2f21988 100644 --- a/Makefile +++ b/Makefile @@ -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