.PHONY: fmt fmt-check clippy test-local test-debugger-socket clean coverage coverage-xml coverage-json coverage-report-json coverage-domain-list coverage-domain-evidence coverage-domain-audit coverage-domain-gate test ci ci-domains cobertura

fmt:
	cargo fmt --all

fmt-check:
	cargo fmt --all -- --check

clippy:
	cargo clippy --workspace --all-targets --all-features -- -D warnings

test-local:
	cargo test --workspace --all-targets --all-features --no-fail-fast

test-debugger-socket:
	cargo test -p prometeu-host-desktop-winit --lib runner::tests -- --ignored

clean:
	cargo llvm-cov clean --workspace

coverage:
	cargo llvm-cov --workspace --all-features --html --output-dir target/llvm-cov

coverage-report-json:
	cargo llvm-cov report --json --output-path target/llvm-cov/report.json

coverage-xml:
	cargo llvm-cov report --cobertura --output-path target/llvm-cov/cobertura.xml

coverage-json:
	cargo llvm-cov report --json --summary-only --output-path target/llvm-cov/summary.json

coverage-domain-list:
	./scripts/coverage-domain-evidence.sh --list

coverage-domain-audit:
	python3 scripts/audit-coverage-domains.py --report target/llvm-cov/report.json

coverage-domain-evidence:
	@if [ -z "$(DOMAIN)" ]; then \
		echo "usage: make coverage-domain-evidence DOMAIN=<domain>"; \
		exit 1; \
	fi
	./scripts/coverage-domain-evidence.sh "$(DOMAIN)"

coverage-domain-gate:
	./scripts/coverage-domain-evidence.sh --check-all

test: fmt-check clippy test-local test-debugger-socket
# Local and GitHub entry point; Jenkins exposes the same targets as stages.
CI_DOMAIN_STEPS = clean fmt-check clippy test-local test-debugger-socket coverage coverage-report-json coverage-xml coverage-json coverage-domain-audit coverage-domain-gate

ci: ci-domains
ci-domains:
	rm -rf target/llvm-cov
	+@set -e; for step in $(CI_DOMAIN_STEPS); do $(MAKE) --no-print-directory -j1 $$step; done

cobertura: coverage-xml coverage-json
