Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
148 lines (123 loc) · 7.11 KB
/
Copy pathMakefile
File metadata and controls
148 lines (123 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
PROJECT := MeetingBar.xcodeproj
SCHEME := MeetingBar
XCODEBUILD ?= xcodebuild
SWIFT ?= swift
SWIFTLINT ?= swiftlint
BUILD_DIR ?= build
COVERAGE_DIR := $(BUILD_DIR)/coverage
XCODE_RESULT_BUNDLE := $(COVERAGE_DIR)/MeetingBar.xcresult
DERIVED_DATA_DIR := $(BUILD_DIR)/DerivedData
XCODE_SOURCE_PACKAGES_DIR := $(BUILD_DIR)/SourcePackages
HOST_ARCH := $(shell uname -m)
DESTINATION ?= platform=macOS,arch=$(HOST_ARCH)
XCODEBUILD_FLAGS := -project $(PROJECT) -scheme $(SCHEME) -destination '$(DESTINATION)' -derivedDataPath $(DERIVED_DATA_DIR) -clonedSourcePackagesDirPath $(XCODE_SOURCE_PACKAGES_DIR) -onlyUsePackageVersionsFromResolvedFile
LOCAL_CODESIGN_FLAGS := CODE_SIGN_IDENTITY="" CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO
LOGIC_COVERAGE_SOURCES := MeetingBar/Calendar MeetingBar/Meetings MeetingBar/Notifications MeetingBar/UI/StatusBar MeetingBar/Utilities/Diagnostics
# Pipe xcodebuild through xcbeautify when available; otherwise grep for the lines that matter.
XCFILTER := $(shell command -v xcbeautify >/dev/null 2>&1 && echo 'xcbeautify --quiet --renderer terminal' || echo "grep -E '(error:|warning:|FAIL|PASS|\\*\\* )'")
# Append a JUnit report to app-hosted test runs when xcbeautify is available.
JUNIT_REPORT := $(shell command -v xcbeautify >/dev/null 2>&1 && echo '--report junit --report-path $(BUILD_DIR)/test-results')
.PHONY: build build-quiet build-release test-config test test-quiet test-app test-app-quiet test-logic test-logic-quiet test-performance coverage coverage-report coverage-logic-report coverage-app-report coverage-gate test-summary coverage-codecov coverage-codecov-logic lint lint-fix open validate-strings
build:
@mkdir -p $(BUILD_DIR)
$(XCODEBUILD) $(XCODEBUILD_FLAGS) -configuration Debug build $(LOCAL_CODESIGN_FLAGS)
build-quiet:
@mkdir -p $(BUILD_DIR)
@set -o pipefail; $(XCODEBUILD) $(XCODEBUILD_FLAGS) -configuration Debug build $(LOCAL_CODESIGN_FLAGS) 2>&1 | $(XCFILTER)
build-release:
@mkdir -p $(BUILD_DIR)
$(XCODEBUILD) $(XCODEBUILD_FLAGS) -configuration Release build
test-config:
@bash Scripts/tests/test_validate_xcconfig.sh
test: test-config test-logic test-app
test-quiet: test-config test-logic-quiet test-app-quiet
test-app:
@mkdir -p $(COVERAGE_DIR)
@rm -rf $(XCODE_RESULT_BUNDLE)
$(XCODEBUILD) $(XCODEBUILD_FLAGS) -configuration Debug -enableCodeCoverage YES -resultBundlePath $(XCODE_RESULT_BUNDLE) build test $(LOCAL_CODESIGN_FLAGS)
@$(MAKE) --no-print-directory coverage-app-report
test-app-quiet:
@mkdir -p $(COVERAGE_DIR) $(BUILD_DIR)/test-results
@rm -rf $(XCODE_RESULT_BUNDLE)
@set -o pipefail; $(XCODEBUILD) $(XCODEBUILD_FLAGS) -configuration Debug -enableCodeCoverage YES -resultBundlePath $(XCODE_RESULT_BUNDLE) build test $(LOCAL_CODESIGN_FLAGS) 2>&1 | $(XCFILTER) $(JUNIT_REPORT)
@$(MAKE) --no-print-directory coverage-app-report
test-logic:
$(SWIFT) test --enable-code-coverage
@$(MAKE) --no-print-directory coverage-logic-report
test-logic-quiet:
$(SWIFT) test --enable-code-coverage --quiet
@$(MAKE) --no-print-directory coverage-logic-report
# Opt-in reproducible workload baselines. These are not CI gates.
test-performance:
MEETINGBAR_PERF_TESTS=1 $(SWIFT) test --filter PerformanceBaselineTests
coverage: test
coverage-report: coverage-logic-report coverage-app-report
coverage-logic-report:
@PROFILE="$$(ls -d .build/*/debug/codecov/default.profdata .build/debug/codecov/default.profdata 2>/dev/null | head -n 1)" ; \
TEST_BINARY="$$(ls -d .build/*/debug/MeetingBarLogicPackageTests.xctest/Contents/MacOS/MeetingBarLogicPackageTests .build/debug/MeetingBarLogicPackageTests.xctest/Contents/MacOS/MeetingBarLogicPackageTests 2>/dev/null | head -n 1)" ; \
if [ ! -f "$$PROFILE" ] || [ ! -x "$$TEST_BINARY" ]; then \
echo "SwiftPM coverage is unavailable. Run 'make test-logic' first."; \
exit 1; \
fi ; \
echo "" ; \
echo "SwiftPM hostless coverage (source files only):" ; \
xcrun llvm-cov report "$$TEST_BINARY" -instr-profile "$$PROFILE" $(LOGIC_COVERAGE_SOURCES)
coverage-gate:
@PROFILE="$$(ls -d .build/*/debug/codecov/default.profdata .build/debug/codecov/default.profdata 2>/dev/null | head -n 1)" ; \
TEST_BINARY="$$(ls -d .build/*/debug/MeetingBarLogicPackageTests.xctest/Contents/MacOS/MeetingBarLogicPackageTests .build/debug/MeetingBarLogicPackageTests.xctest/Contents/MacOS/MeetingBarLogicPackageTests 2>/dev/null | head -n 1)" ; \
if [ ! -f "$$PROFILE" ] || [ ! -x "$$TEST_BINARY" ]; then \
echo "SwiftPM coverage data not found. Run 'make test-logic' first."; \
exit 1; \
fi ; \
COVERAGE=$$(xcrun llvm-cov report "$$TEST_BINARY" -instr-profile "$$PROFILE" $(LOGIC_COVERAGE_SOURCES) 2>/dev/null | tail -1 | awk '{print $$4}' | tr -d '%') ; \
echo "" ; \
echo "Logic coverage gate (threshold: 90%):" ; \
awk -v cov="$$COVERAGE" 'BEGIN { if (cov + 0 < 90.0) { print " NOTE: " cov "% is below 90% target (gate is reporting-only)" } else { print " PASS: " cov "% meets 90% target" } }'
coverage-app-report:
@if [ ! -d "$(XCODE_RESULT_BUNDLE)" ]; then \
echo "Xcode coverage is unavailable. Run 'make test' or 'make test-quiet' first."; \
exit 1; \
fi
@echo ""
@echo "Xcode app-hosted coverage (target summary):"
@set -o pipefail; xcrun xccov view --report --only-targets $(XCODE_RESULT_BUNDLE) 2>/dev/null | awk 'NR <= 2 || /MeetingBar\.app/'
lint:
@if command -v $(SWIFTLINT) >/dev/null 2>&1; then \
$(SWIFTLINT); \
else \
echo "SwiftLint is not installed. Install it from https://github.com/realm/SwiftLint"; \
exit 1; \
fi
lint-fix:
@if command -v $(SWIFTLINT) >/dev/null 2>&1; then \
$(SWIFTLINT) --fix; \
$(SWIFTLINT); \
else \
echo "SwiftLint is not installed. Install it from https://github.com/realm/SwiftLint"; \
exit 1; \
fi
open:
open $(PROJECT)
validate-strings:
@bash Scripts/validate_localizations.sh
test-summary:
@bash Scripts/test_summary.sh $(XCODE_RESULT_BUNDLE)
# Export SwiftPM logic-test coverage in LCOV format for Codecov. The app-hosted
# Slather report does not include the separate MeetingBarLogic test binary.
coverage-codecov-logic:
@mkdir -p $(COVERAGE_DIR)
@PROFILE="$$(ls -d .build/*/debug/codecov/default.profdata .build/debug/codecov/default.profdata 2>/dev/null | head -n 1)" ; \
TEST_BINARY="$$(ls -d .build/*/debug/MeetingBarLogicPackageTests.xctest/Contents/MacOS/MeetingBarLogicPackageTests .build/debug/MeetingBarLogicPackageTests.xctest/Contents/MacOS/MeetingBarLogicPackageTests 2>/dev/null | head -n 1)" ; \
if [ ! -f "$$PROFILE" ] || [ ! -x "$$TEST_BINARY" ]; then \
echo "SwiftPM coverage data not found. Run 'make test-logic' first."; \
exit 1; \
fi ; \
xcrun llvm-cov export "$$TEST_BINARY" -instr-profile "$$PROFILE" -format=lcov $(LOGIC_COVERAGE_SOURCES) > "$(COVERAGE_DIR)/swiftpm.lcov"
# Generate a Cobertura coverage report from the app-hosted test build for
# Codecov. Uses slather against our custom derived-data path; skips cleanly
# (rather than failing) when slather is not installed locally.
coverage-codecov:
@mkdir -p $(COVERAGE_DIR)
@if command -v slather >/dev/null 2>&1; then \
slather coverage --scheme $(SCHEME) --cobertura-xml --build-directory $(DERIVED_DATA_DIR) --output-directory $(COVERAGE_DIR) $(PROJECT) ; \
else echo "slather not installed; skipping cobertura. Install with: gem install slather" ; fi