forked from heardrwt/realm-cocoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
344 lines (294 loc) · 11.5 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/bin/sh
##################################################################################
# Custom build tool for Realm Objective C binding.
#
# (C) Copyright 2011-2014 by realm.io.
##################################################################################
# Warning: pipefail is not a POSIX compatible option, but on OS X it works just fine.
# OS X uses a POSIX complain version of bash as /bin/sh, but apparently it does
# not strip away this feature. Also, this will fail if somebody forces the script
# to be run with zsh.
set -o pipefail
PATH=/usr/local/bin:/usr/bin:/bin:/usr/libexec:$PATH
if ! [ -z "${JENKINS_HOME}" ]; then
XCPRETTY_PARAMS="--no-utf --report junit --output build/reports/junit.xml"
CODESIGN_PARAMS="CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO"
fi
usage() {
cat <<EOF
Usage: sh $0 command [argument]
command:
download-core: downloads core library (binary version)
clean [xcmode]: clean up/remove all generated files
build [xcmode]: builds iOS and OS X frameworks with release configuration
build-debug [xcmode]: builds iOS and OS X frameworks with debug configuration
ios [xcmode]: builds iOS framework with release configuration
ios-debug [xcmode]: builds iOS framework with debug configuration
osx [xcmode]: builds OS X framework with release configuration
osx-debug [xcmode]: builds OS X framework with debug configuration
test-ios [xcmode]: tests iOS framework with release configuration
test-osx [xcmode]: tests OSX framework with release configuration
test [xcmode]: tests iOS and OS X frameworks with release configuration
test-debug [xcmode]: tests iOS and OS X frameworks with debug configuration
test-all [xcmode]: tests iOS and OS X frameworks with debug and release configurations, on Xcode 5 and Xcode 6
examples [xcmode]: builds all examples in examples/ in release configuration
examples-debug [xcmode]: builds all examples in examples/ in debug configuration
verify [xcmode]: cleans, removes docs/output/, then runs docs, test-all and examples
docs: builds docs in docs/output
get-version: get the current version
set-version version: set the version
argument:
xcmode: xcodebuild (default), xcpretty or xctool
version: version in the x.y.z format
EOF
}
######################################
# Xcode Helpers
######################################
if [ -z "$XCODE_VERSION" ]; then
XCODE_VERSION=5
fi
xcode5() {
mkdir -p build/DerivedData
ln -s /Applications/Xcode.app/Contents/Developer/usr/bin bin || exit 1
PATH=./bin:$PATH xcodebuild -IDECustomDerivedDataLocation=build/DerivedData $@
}
xcode6() {
mkdir -p build/DerivedData
ln -s /Applications/Xcode6-Beta3.app/Contents/Developer/usr/bin bin || exit 1
PATH=./bin:$PATH xcodebuild -IDECustomDerivedDataLocation=build/DerivedData $@
}
xcode() {
rm -rf bin
case "$XCODE_VERSION" in
5)
xcode5 $@
;;
6)
xcode6 $@
;;
*)
echo "Unsupported version of xcode specified"
exit 1
esac
rm -rf bin
}
xc() {
echo "Building target \"$1\" with xcode${XCODE_VERSION}"
if [[ "$XCMODE" == "xcodebuild" ]]; then
xcode $1 || exit 1
elif [[ "$XCMODE" == "xcpretty" ]]; then
xcode $1 | tee build.log | xcpretty -c ${XCPRETTY_PARAMS}
if [ "$?" -ne 0 ]; then
echo "The raw xcodebuild output is available in build.log"
exit 1
fi
elif [[ "$XCMODE" == "xctool" ]]; then
xctool $1 || exit 1
fi
}
xcrealm() {
PROJECT=Realm.xcodeproj
if [[ "$XCODE_VERSION" == "6" ]]; then
PROJECT=Realm-Xcode6.xcodeproj
fi
xc "-project $PROJECT $1"
}
######################################
# Input Validation
######################################
if [ "$#" -eq 0 -o "$#" -gt 2 ]; then
usage
exit 1
fi
######################################
# Variables
######################################
# Xcode sets this variable - set to current directory if running standalone
if [ -z "$SRCROOT" ]; then
SRCROOT="$(pwd)"
fi
# You can override the version of the core library
# Otherwise, use the default value
if [ -z "$REALM_CORE_VERSION" ]; then
REALM_CORE_VERSION=0.80.0
fi
download_core() {
rm -rf core
curl -L -s "http://static.realm.io/downloads/core/realm-core-${REALM_CORE_VERSION}.zip" -o "/tmp/core-${REALM_CORE_VERSION}.zip" || exit 1
unzip "/tmp/core-${REALM_CORE_VERSION}.zip" || exit 1
rm -f "/tmp/core-${REALM_CORE_VERSION}.zip" || exit 1
}
COMMAND="$1"
XCMODE="$2"
: ${XCMODE:=xcodebuild} # must be one of: xcodebuild (default), xcpretty, xctool
case "$COMMAND" in
######################################
# Clean
######################################
"clean")
xcrealm "-scheme iOS -configuration Debug -sdk iphonesimulator clean" || exit 1
xcrealm "-scheme iOS -configuration Release -sdk iphonesimulator clean" || exit 1
xcrealm "-scheme OSX -configuration Debug clean" || exit 1
xcrealm "-scheme OSX -configuration Release clean" || exit 1
exit 0
;;
######################################
# Download Core Library
######################################
"download-core")
echo "Downloading dependency: core ${REALM_CORE_VERSION}"
if ! [ -d core ]; then
download_core
elif ! $(head -n 1 core/release_notes.txt | grep ${REALM_CORE_VERSION} >/dev/null); then
download_core
else
echo "The core library seems to be up to date."
echo "To force an update remove the folder 'core' and rerun."
fi
exit 0
;;
######################################
# Building
######################################
"build")
sh build.sh ios "$XCMODE" || exit 1
sh build.sh osx "$XCMODE" || exit 1
exit 0
;;
"build-debug")
sh build.sh ios-debug "$XCMODE" || exit 1
sh build.sh osx-debug "$XCMODE" || exit 1
exit 0
;;
"ios")
xcrealm "-scheme iOS -configuration Release"
exit 0
;;
"osx")
xcrealm "-scheme OSX -configuration Release"
exit 0
;;
"ios-debug")
xcrealm "-scheme iOS -configuration Debug"
exit 0
;;
"osx-debug")
xcrealm "-scheme OSX -configuration Debug"
exit 0
;;
"docs")
sh scripts/build-docs.sh || exit 1
exit 0
;;
######################################
# Testing
######################################
"test")
sh build.sh test-ios "$XCMODE"
sh build.sh test-osx "$XCMODE"
exit 0
;;
"test-debug")
sh build.sh test-osx-debug "$XCMODE"
sh build.sh test-ios-debug "$XCMODE"
exit 0
;;
"test-all")
sh build.sh test "$XCMODE" || exit 1
sh build.sh test-debug "$XCMODE" || exit 1
XCODE_VERSION=6 sh build.sh test "$XCMODE" || exit 1
XCODE_VERSION=6 sh build.sh test-debug "$XCMODE" || exit 1
;;
"test-ios")
xcrealm "-scheme iOS -configuration Release -sdk iphonesimulator test"
exit 0
;;
"test-osx")
xcrealm "-scheme OSX -configuration Release test"
exit 0
;;
"test-ios-debug")
xcrealm "-scheme iOS -configuration Debug -sdk iphonesimulator test"
exit 0
;;
"test-osx-debug")
xcrealm "-scheme OSX -configuration Debug test"
exit 0
;;
"test-cover")
echo "Not yet implemented"
exit 0
;;
"verify")
sh build.sh docs || exit 1
sh build.sh test-all "$XCMODE" || exit 1
sh build.sh examples "$XCMODE" || exit 1
exit 0
;;
######################################
# Docs
######################################
"docs")
sh scripts/build-docs.sh || exit 1
exit 0
;;
######################################
# Examples
######################################
"examples")
cd examples
if [[ "$XCVERSION" == "6" ]]; then
xc "-project swift/RealmSwiftSimpleExample/RealmSwiftSimpleExample.xcodeproj -scheme RealmSwiftSimpleExample -configuration Release clean build ${CODESIGN_PARAMS}"
xc "-project swift/RealmSwiftTableViewExample/RealmSwiftTableViewExample.xcodeproj -scheme RealmSwiftTableViewExample -configuration Release clean build ${CODESIGN_PARAMS}"
fi
xc "-project objc/RealmSimpleExample/RealmSwiftSimpleExample.xcodeproj -scheme RealmSimpleExample -configuration Release clean build ${CODESIGN_PARAMS}"
xc "-project objc/RealmTableViewExample/RealmTableViewExample.xcodeproj -scheme RealmTableViewExample -configuration Release clean build ${CODESIGN_PARAMS}"
xc "-project objc/RealmMigrationExample/RealmMigrationExample.xcodeproj -scheme RealmMigrationExample -configuration Release clean build ${CODESIGN_PARAMS}"
xc "-project objc/RealmRestExample/RealmRestExample.xcodeproj -scheme RealmRestExample -configuration Release clean build ${CODESIGN_PARAMS}"
# Not all examples can be built using Xcode 6
if [[ "$XCVERSION" != "6" ]]; then
xc "-project objc/RealmJSONImportExample/RealmJSONImportExample.xcodeproj -scheme RealmJSONImportExample -configuration Release clean build ${CODESIGN_PARAMS}"
fi
exit 0
;;
"examples-debug")
cd examples
if [[ "$XCVERSION" == "6" ]]; then
xc "-project swift/RealmSwiftSimpleExample/RealmSwiftSimpleExample.xcodeproj -scheme RealmSwiftSimpleExample -configuration Debug clean build ${CODESIGN_PARAMS}"
xc "-project swift/RealmSwiftTableViewExample/RealmSwiftTableViewExample.xcodeproj -scheme RealmSwiftTableViewExample -configuration Debug clean build ${CODESIGN_PARAMS}"
fi
xc "-project objc/RealmSimpleExample/RealmSimpleExample.xcodeproj -scheme RealmSimpleExample -configuration Debug clean build ${CODESIGN_PARAMS}"
xc "-project objc/RealmTableViewExample/RealmTableViewExample.xcodeproj -scheme RealmTableViewExample -configuration Debug clean build ${CODESIGN_PARAMS}"
xc "-project objc/RealmMigrationExample/RealmMigrationExample.xcodeproj -scheme RealmMigrationExample -configuration Debug clean build ${CODESIGN_PARAMS}"
xc "-project objc/RealmRestExample/RealmRestExample.xcodeproj -scheme RealmRestExample -configuration Debug clean build ${CODESIGN_PARAMS}"
# Not all examples can be built using Xcode 6
if [[ "$XCVERSION" != "6" ]]; then
xc "-project objc/RealmJSONImportExample/RealmJSONImportExample.xcodeproj -scheme RealmJSONImportExample -configuration Debug clean build ${CODESIGN_PARAMS}"
fi
exit 0
;;
######################################
# Versioning
######################################
"get-version")
version_file="Realm/Realm-Info.plist"
echo "$(PlistBuddy -c "Print :CFBundleVersion" "$version_file")"
exit 0
;;
"set-version")
realm_version="$2"
version_file="Realm/Realm-Info.plist"
if [ -z "$realm_version" ]; then
echo "You must specify a version."
exit 1
fi
PlistBuddy -c "Set :CFBundleVersion $realm_version" "$version_file"
PlistBuddy -c "Set :CFBundleShortVersionString $realm_version" "$version_file"
exit 0
;;
*)
usage
exit 1
;;
esac