-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
217 lines (183 loc) · 10.1 KB
/
Copy pathMakefile
File metadata and controls
217 lines (183 loc) · 10.1 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
.PHONY: clean build tests
.SECONDARY:
# Check is variable defined helper
check_defined = $(strip $(foreach 1,$1, $(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = $(if $(value $1),, $(error Undefined $1$(if $2, ($2))$(if $(value @), required by target '$@')))
# params: scheme, platform, logfile, simulator
define xctest
$(if $(filter $2,macOS),$(eval SDK=macosx)$(eval DEST='platform=macOS,arch=arm64'),)
$(if $(filter $2,iOSsim),$(eval SDK=iphonesimulator)$(eval DEST='platform=iOS Simulator,name=$4'),)
$(if $(filter $2,tvOSsim),$(eval SDK=appletvsimulator)$(eval DEST='platform=tvOS Simulator,name=$4'),)
$(if $(filter $2,watchOSsim),$(eval SDK=watchsimulator)$(eval DEST='platform=watchOS Simulator,name=$4'),)
$(if $(filter $2,visionOSsim),$(eval SDK=xrsimulator)$(eval DEST='platform=visionOS Simulator,name=$4'),)
$(if $3,\
set -o pipefail; xcodebuild -scheme $1 -sdk $(SDK) -destination $(DEST) test 2>&1 | tee $1-$2-$3.log | xcbeautify --report junit --report-path build/reports --junit-report-filename $1-$2.xml,\
xcodebuild -scheme $1 -sdk $(SDK) -destination $(DEST) test)
endef
## params: scheme, sdk, destination, name, logfile
define xcarchive
$(if $5,\
set -o pipefail; xcodebuild archive -scheme $1 -sdk $2 -destination $3 -archivePath \
build/$1/$4.xcarchive SKIP_INSTALL=NO 2>&1 | tee $1-$4-$5.log | xcbeautify,\
xcodebuild archive -scheme $1 -sdk $2 -destination $3 -archivePath build/$1/$4.xcarchive SKIP_INSTALL=NO)
endef
ROOT_DIR := $(shell pwd)
# params: scheme, platform, logfile, simulator
define xctestint
$(if $(filter $2,macOS),$(eval SDK=macosx)$(eval DEST='platform=macOS,arch=arm64'),)
$(if $(filter $2,iOSsim),$(eval SDK=iphonesimulator)$(eval DEST='platform=iOS Simulator,name=$4'),)
$(if $(filter $2,tvOSsim),$(eval SDK=appletvsimulator)$(eval DEST='platform=tvOS Simulator,name=$4'),)
$(if $(filter $2,watchOSsim),$(eval SDK=watchsimulator)$(eval DEST='platform=watchOS Simulator,name=$4'),)
$(if $(filter $2,visionOSsim),$(eval SDK=xrsimulator)$(eval DEST='platform=visionOS Simulator,name=$4'),)
$(if $3,mkdir -p logs-$3,)
$(if $3,\
set -o pipefail; INTEGRATION_TESTS_SDK=$(SDK) INTEGRATION_TESTS_PLATFORM=$(DEST) INTEGRATION_TESTS_LOG_PATH=$(ROOT_DIR)/logs-$3 xcodebuild -scheme $1 test 2>&1 | tee logs-$3/$1-$2-$3.log | xcbeautify,\
INTEGRATION_TESTS_SDK=$(SDK) INTEGRATION_TESTS_PLATFORM=$(DEST) xcodebuild -scheme $1 test)
endef
build/%/iphoneos.xcarchive:
$(call xcarchive,$*,iphoneos,'generic/platform=iOS',iphoneos,$(XC_LOG))
build/%/iphonesimulator.xcarchive:
$(call xcarchive,$*,iphonesimulator,'generic/platform=iOS Simulator',iphonesimulator,$(XC_LOG))
build/%/macos.xcarchive:
$(call xcarchive,$*,macosx,'generic/platform=macOS',macos,$(XC_LOG))
build/%/maccatalyst.xcarchive:
$(eval platform = 'generic/platform=macOS,variant=Mac Catalyst')
$(call xcarchive,$*,macosx,$(platform),maccatalyst,$(XC_LOG))
build/%/appletvos.xcarchive:
$(call xcarchive,$*,appletvos,'generic/platform=tvOS',appletvos,$(XC_LOG))
build/%/appletvsimulator.xcarchive:
$(call xcarchive,$*,appletvsimulator,'generic/platform=tvOS Simulator',appletvsimulator,$(XC_LOG))
build/%/watchos.xcarchive:
$(call xcarchive,$*,watchos,'generic/platform=watchOS',watchos,$(XC_LOG))
build/%/watchsimulator.xcarchive:
$(call xcarchive,$*,watchsimulator,'generic/platform=watchOS Simulator',watchsimulator,$(XC_LOG))
build/%/xros.xcarchive:
$(call xcarchive,$*,xros,'generic/platform=visionOS',xros,$(XC_LOG))
build/%/xrsimulator.xcarchive:
$(call xcarchive,$*,xrsimulator,'generic/platform=visionOS Simulator',xrsimulator,$(XC_LOG))
build/xcframework/%.xcframework: \
build/%/iphoneos.xcarchive build/%/iphonesimulator.xcarchive \
build/%/macos.xcarchive build/%/maccatalyst.xcarchive \
build/%/appletvos.xcarchive build/%/appletvsimulator.xcarchive \
build/%/watchos.xcarchive build/%/watchsimulator.xcarchive \
build/%/xros.xcarchive build/%/xrsimulator.xcarchive
@mkdir -p $(PWD)/build/xcframework
@xargs xcodebuild -create-xcframework -output $@ <<<"$(foreach archive,$^,-framework $(archive)/Products/Library/Frameworks/$*.framework)"
build/xcframework/%.zip: build/xcframework/%.xcframework
cd ./build/xcframework/; zip -ry ./$*.zip ./$*.xcframework
build/symbols/%.zip: \
build/%/iphoneos.xcarchive build/%/iphonesimulator.xcarchive \
build/%/macos.xcarchive build/%/maccatalyst.xcarchive \
build/%/appletvos.xcarchive build/%/appletvsimulator.xcarchive \
build/%/watchos.xcarchive build/%/watchsimulator.xcarchive \
build/%/xros.xcarchive build/%/xrsimulator.xcarchive
@for archive in $^ ; do \
name=$$(basename $$archive | cut -d'.' -f1) ;\
mkdir -p $(PWD)/build/symbols/$*/$$name ;\
cp -R $$archive/dSYMs/*.dSYM $(PWD)/build/symbols/$*/$$name/ ;\
done
@cd $(PWD)/build/symbols/$*; zip -ry ../$*.zip ./*
build: build/xcframework/DatadogSDKTesting.zip build/symbols/DatadogSDKTesting.zip
set_version:
@:$(call check_defined, version, release version)
sed -i "" "s|MARKETING_VERSION =.*|MARKETING_VERSION = \"$(version)\";|g" DatadogSDKTesting.xcodeproj/project.pbxproj
sed -i "" "s|s\.version\([[:blank:]]*\)=.*|s.version\1= '$(version)'|g" DatadogSDKTesting.podspec
sed -i "" "s|let[[:blank:]]*releaseVersion.*|let releaseVersion = \"$(version)\"|g" Package.swift
set_hash:
$(eval HASH := $(shell swift package compute-checksum ./build/xcframework/DatadogSDKTesting.zip))
sed -i "" "s|:sha256 =>.*|:sha256 => '$(HASH)'|g" DatadogSDKTesting.podspec
sed -i "" "s|let[[:blank:]]*relaseChecksum.*|let relaseChecksum = \"$(HASH)\"|g" Package.swift
release:
@$(MAKE) set_version
@$(MAKE) build
@$(MAKE) set_hash
github_release: release
@:$(call check_defined, GH_TOKEN, GitHub token)
@:$(call check_defined, GITHUB_REPOSITORY, GitHub repository with owner)
# Update gh utility if needed
@brew install gh || brew upgrade gh
# Stash changes
@git stash --include-untracked
# Create and push branch for release
@git checkout -b release-$(version)
@git push -f -u origin release-$(version)
# Get changes back
@git stash pop
# Commit updated xcodeproj, podspec and Package.swift
# We will use GH API to do that, because we need a signed commit
@gh api graphql \
-F githubRepository="$(GITHUB_REPOSITORY)" \
-F branchName="release-$(version)" \
-F expectedHeadOid=$$(git rev-parse HEAD) \
-F commitMessage="Updated binary package version to $(version)" \
-F files[][path]="Package.swift" -F files[][contents]=$$(base64 -i Package.swift) \
-F files[][path]="DatadogSDKTesting.podspec" -F files[][contents]=$$(base64 -i DatadogSDKTesting.podspec) \
-F files[][path]="DatadogSDKTesting.xcodeproj/project.pbxproj" -F files[][contents]=$$(base64 -i DatadogSDKTesting.xcodeproj/project.pbxproj) \
-F 'query=@.github/api/createCommitOnBranch.gql'
# Pull new commit
# Reset changes to files (we already pushed them)
@git reset --hard
# Save untracked
@git stash --include-untracked
# Pull latest commit
@git pull
# Create tag and push it
@git tag -f $(version)
@git push -f --tags origin release-$(version)
# Restore untracked
@git stash pop
# rename symbols file
@rm -f build/symbols/DatadogSDKTesting.symbols.zip
@mv build/symbols/DatadogSDKTesting.zip build/symbols/DatadogSDKTesting.symbols.zip
# make github release
@gh release create $(version) --prerelease --verify-tag --generate-notes \
build/xcframework/DatadogSDKTesting.zip build/symbols/DatadogSDKTesting.symbols.zip
publish_pod:
@:$(call check_defined, COCOAPODS_TRUNK_TOKEN, CocoaPods trunk token)
@pod trunk push --allow-warnings DatadogSDKTesting.podspec
clean:
rm -rf ./build
# params: scheme — run `scheme` across every unit-test platform.
define xctest_unit_all_platforms
$(if $(IOS_SIMULATOR),,$(eval IOS_SIMULATOR = iPhone 17))
$(if $(TVOS_SIMULATOR),,$(eval TVOS_SIMULATOR = Apple TV))
$(if $(WATCHOS_SIMULATOR),,$(eval WATCHOS_SIMULATOR = Apple Watch Series 11 (46mm)))
$(if $(VISIONOS_SIMULATOR),,$(eval VISIONOS_SIMULATOR = Apple Vision Pro))
$(call xctest,$1,macOS,$(XC_LOG),)
$(call xctest,$1,iOSsim,$(XC_LOG),$(IOS_SIMULATOR))
$(call xctest,$1,tvOSsim,$(XC_LOG),$(TVOS_SIMULATOR))
$(call xctest,$1,watchOSsim,$(XC_LOG),$(WATCHOS_SIMULATOR))
$(call xctest,$1,visionOSsim,$(XC_LOG),$(VISIONOS_SIMULATOR))
endef
# Per-platform target — runs both unit-test schemes on a single platform.
# The `%` placeholder is one of: macOS, iOSsim, tvOSsim, watchOSsim, visionOSsim.
tests/unit/%:
$(if $(IOS_SIMULATOR),,$(eval IOS_SIMULATOR = iPhone 17))
$(if $(TVOS_SIMULATOR),,$(eval TVOS_SIMULATOR = Apple TV))
$(if $(WATCHOS_SIMULATOR),,$(eval WATCHOS_SIMULATOR = Apple Watch Series 11 (46mm)))
$(if $(VISIONOS_SIMULATOR),,$(eval VISIONOS_SIMULATOR = Apple Vision Pro))
$(if $(filter $*,iOSsim),$(eval SIMULATOR=$(IOS_SIMULATOR)),$(eval SIMULATOR :=))
$(if $(filter $*,tvOSsim),$(eval SIMULATOR=$(TVOS_SIMULATOR)),)
$(if $(filter $*,watchOSsim),$(eval SIMULATOR=$(WATCHOS_SIMULATOR)),)
$(if $(filter $*,visionOSsim),$(eval SIMULATOR=$(VISIONOS_SIMULATOR)),)
$(call xctest,EventsExporter,$*,$(XC_LOG),$(SIMULATOR))
$(call xctest,DatadogSDKTesting,$*,$(XC_LOG),$(SIMULATOR))
# Per-scheme convenience targets — run a single unit-test scheme across every
# platform. Explicit names shadow the `tests/unit/%` pattern above.
tests/unit/EventsExporter:
$(call xctest_unit_all_platforms,EventsExporter)
tests/unit/DatadogSDKTesting:
$(call xctest_unit_all_platforms,DatadogSDKTesting)
tests/integration/%:
$(if $(IOS_SIMULATOR),,$(eval IOS_SIMULATOR = iPhone 17))
$(if $(TVOS_SIMULATOR),,$(eval TVOS_SIMULATOR = Apple TV))
$(if $(WATCHOS_SIMULATOR),,$(eval WATCHOS_SIMULATOR = Apple Watch Series 11 (46mm)))
$(if $(VISIONOS_SIMULATOR),,$(eval VISIONOS_SIMULATOR = Apple Vision Pro))
$(if $(filter $*,iOSsim),$(eval SIMULATOR=$(IOS_SIMULATOR)),$(eval SIMULATOR :=))
$(if $(filter $*,tvOSsim),$(eval SIMULATOR=$(TVOS_SIMULATOR)),)
$(if $(filter $*,watchOSsim),$(eval SIMULATOR=$(WATCHOS_SIMULATOR)),)
$(if $(filter $*,visionOSsim),$(eval SIMULATOR=$(VISIONOS_SIMULATOR)),)
$(call xctestint,IntegrationTests,$*,$(XC_LOG),$(SIMULATOR))
tests/unit: tests/unit/macOS tests/unit/iOSsim tests/unit/tvOSsim tests/unit/watchOSsim tests/unit/visionOSsim
tests/integration: tests/integration/macOS tests/integration/iOSsim tests/integration/tvOSsim tests/integration/watchOSsim tests/integration/visionOSsim
tests: tests/unit