-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathbuild.sh
executable file
·268 lines (208 loc) · 7.67 KB
/
build.sh
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/bin/sh
reveal_archive_in_finder=true
project="kingpin-dev.xcodeproj"
project_dir="$(pwd)/kingpin-dev"
build_dir="$project_dir/Build"
configuration="Release"
ios_framework_name="kingpin"
ios_framework="${ios_framework_name}.framework"
osx_framework_name="kingpinOSX"
osx_framework="${osx_framework_name}.framework"
ios_scheme="kingpin-iOS"
osx_scheme="kingpin-OSX"
unit_tests_scheme="kingpin-Unit-Tests-iOS"
ios_simulator_path="${build_dir}/${ios_scheme}/${configuration}-iphonesimulator"
ios_simulator_binary="${ios_simulator_path}/${ios_framework}/${ios_framework_name}"
ios_device_path="${build_dir}/${ios_scheme}/${configuration}-iphoneos"
ios_device_binary="${ios_device_path}/${ios_framework}/${ios_framework_name}"
ios_universal_path="${build_dir}/${ios_scheme}/${configuration}-iphoneuniversal"
ios_universal_framework="${ios_universal_path}/${ios_framework}"
ios_universal_binary="${ios_universal_path}/${ios_framework}/${ios_framework_name}"
osx_path="${build_dir}/${osx_scheme}/${configuration}-macosx"
osx_framework="${osx_path}/${osx_framework}"
distribution_path="$(pwd)/kingpin-frameworks"
distribution_path_ios="${distribution_path}/iOS"
distribution_path_osx="${distribution_path}/OSX"
# Examples
examples_project="kingpin-examples.xcodeproj"
examples_dir="$(pwd)/kingpin-examples"
examples_build_dir="$examples_dir/Build"
ios_example_scheme="Example-iOS"
ios_swift_example_scheme="Example-iOS-Swift"
osx_example_scheme="Example-OSX"
osx_swift_example_scheme="Example-OSX-Swift"
ios_example_device_path="${examples_build_dir}/${ios_example_scheme}/${configuration}-iphoneos"
ios_example_device_binary="${ios_example_device_path}/${ios_example_scheme}.app"
ios_example_simulator_path="${examples_build_dir}/${ios_example_scheme}/${configuration}-iphonesimulator"
ios_example_simulator_binary="${ios_example_simulator_path}/${ios_example_scheme}.app"
osx_swift_example_path="${examples_build_dir}/${osx_swift_example_scheme}/${configuration}-macosx"
osx_swift_example_binary="${osx_swift_example_path}/${osx_swift_example_scheme}.app"
usage() {
cat <<EOF
Usage: sh $0 command
command:
print_configuration print all configuration variables
test run tests
build_ios build iOS frameworks for device and simulator and create universal iOS framework
build_osx build OSX framework
export_ios export built iOS framework to distribution folder (needs build_ios)
export_osx export built OSX framework to distribution folder (needs build_osx)
validate_ios validate universal iOS framework against Example-iOS app (needs build_ios, export_ios)
validate_osx validate OSX frameworks against Example-OSX-Swift application (needs build_osx, export_osx)
distribute run tests, build iOS frameworks, validate iOS frameworks
EOF
}
run() {
echo "Running command:$@"
eval $@ || {
echo "Command failed: \"$@\""
exit 1
}
}
print_configuration() {
cat <<EOF
Project: $project
Project dir: $project_dir
Build dir: $build_dir
Configuration: $configuration
Scheme iOS: $ios_scheme
Scheme OSX: $osx_scheme
iOS Simulator build path: $ios_simulator_path
iOS Device build path: $ios_device_path
iOS Universal build path: $ios_universal_path
iOS Universal framework: $ios_universal_framework
OSX Build path $osx_path
OSX Framework $osx_framework
Distribution path: $distribution_path"
Distribution path (iOS): $distribution_path_ios"
Distribution path (OSX): $distribution_path_osx"
Examples project $examples_project
Examples project dir: $examples_dir
Examples build dir: $examples_build_dir
EOF
}
clean() {
rm -rf "$distribution_path"
rm -rf "${build_dir}"
mkdir -p "${build_dir}"
rm -rf "${examples_build_dir}"
mkdir -p "${examples_build_dir}"
}
test() {
run "
cd $project_dir;
xcodebuild -project ${project_dir}/${project}
-scheme ${unit_tests_scheme}
-sdk iphonesimulator
-destination 'platform=iOS Simulator,name=iPhone 6S Plus,OS=latest'
clean test"
}
build_ios() {
run "
cd $project_dir;
xcodebuild -project ${project}
-scheme ${ios_scheme}
-sdk iphonesimulator
-configuration ${configuration}
-destination 'platform=iOS Simulator,name=iPhone 6S Plus,OS=latest'
CONFIGURATION_BUILD_DIR=${ios_simulator_path}
clean build"
run "
cd $project_dir &&
xcodebuild -project ${project}
-scheme ${ios_scheme}
-sdk iphoneos
-configuration ${configuration}
CONFIGURATION_BUILD_DIR=${ios_device_path}
clean build"
rm -rf "${ios_universal_path}"
mkdir "${ios_universal_path}"
mkdir -p "${ios_universal_framework}"
cp -av "${ios_device_path}/." "${ios_universal_path}"
run lipo "${ios_simulator_binary}" "${ios_device_binary}" -create -output "${ios_universal_binary}"
}
build_osx() {
run "
cd $project_dir &&
xcodebuild -project ${project}
-scheme ${osx_scheme}
-sdk macosx
-configuration ${configuration}
CONFIGURATION_BUILD_DIR=${osx_path}
clean build"
}
export_ios() {
mkdir -p "$distribution_path_ios"
cp -av "${ios_universal_framework}" "${distribution_path_ios}"
cd "${distribution_path_ios}" && zip -FSrv "${distribution_path}/kingpin-iOS.zip" kingpin.framework
}
export_osx() {
mkdir -p "$distribution_path_osx"
cp -av "${osx_framework}" "${distribution_path_osx}"
cd "${distribution_path_osx}" && zip -FSrv "${distribution_path}/kingpin-OSX.zip" kingpinOSX.framework
}
validate_ios() {
rm -rf $examples_build_dir
# Build Example iOS app against simulator
run "
cd $examples_dir &&
xcodebuild -project ${examples_project}
-target ${ios_example_scheme}
-sdk iphonesimulator
-configuration ${configuration}
CONFIGURATION_BUILD_DIR=${ios_example_simulator_path}
clean build"
# Build Example iOS app against device
run "
cd $examples_dir &&
xcodebuild -project ${examples_project}
-scheme ${ios_example_scheme}
-sdk iphoneos
-configuration ${configuration}
CONFIGURATION_BUILD_DIR=${ios_example_device_path}
clean build"
run codesign -vvvv --verify --deep ${ios_example_device_binary}
# How To Perform iOS App Validation From the Command Line
# http://stackoverflow.com/questions/7568420/how-to-perform-ios-app-validation-from-the-command-line
# run xcrun -v -sdk iphoneos Validation ${ios_example_device_binary}
}
validate_osx() {
rm -rf $examples_build_dir
# Build Example OSX Swift app
run "
cd $examples_dir &&
xcodebuild -project ${examples_project}
-target ${osx_swift_example_scheme}
-sdk macosx
-configuration ${configuration}
CONFIGURATION_BUILD_DIR=${osx_swift_example_path}
clean build"
run codesign -vvvv --verify --deep ${osx_swift_example_binary}
}
open_distribution_folder() {
if [ ${reveal_archive_in_finder} = true ]; then
open "${distribution_path}"
fi
}
distribute() {
clean
test
build_ios
build_osx
export_ios
export_osx
validate_ios
validate_osx
open_distribution_folder
}
# Show usage instructions if no arguments passed
if [ "$#" -eq 0 -o "$#" -gt 2 ]; then
usage
exit 1
fi
# This is needed for commands like: "./build.sh distribute" to work from command line, outside this script
if type -t $@ | grep "function" &> /dev/null; then
$@
else
echo "Command '$@' not found"
fi