-
Notifications
You must be signed in to change notification settings - Fork 447
/
build.sh
executable file
·640 lines (521 loc) · 22.9 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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
#!/bin/sh
# build.sh
# WebRTC
#
# Created by Rahul Behera on 6/18/14.
# Copyright (c) 2014 Pristine, Inc. All rights reserved.
# Get location of the script itself .. thanks SO ! http://stackoverflow.com/a/246128
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
PROJECT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
DEFAULT_WEBRTC_URL="https://chromium.googlesource.com/external/webrtc"
DEFAULT_POD_URL="https://s3.amazonaws.com/libjingle"
WEBRTC="$PROJECT_DIR/webrtc"
DEPOT_TOOLS="$PROJECT_DIR/depot_tools"
BUILD="$WEBRTC/libjingle_peerconnection_builds"
WEBRTC_TARGET="libWebRTC_objc"
MAC_SDK="10.11"
function create_directory_if_not_found() {
if [ ! -d "$1" ];
then
mkdir -v "$1"
fi
}
function exec_libtool() {
echo "Running libtool"
libtool -static -v -o $@
}
function exec_strip() {
echo "Running strip"
strip -S -X $@
}
function exec_ninja() {
echo "Running ninja"
ninja -C $1 $WEBRTC_TARGET
}
create_directory_if_not_found "$PROJECT_DIR"
create_directory_if_not_found "$WEBRTC"
# Update/Get/Ensure the Gclient Depot Tools
function pull_depot_tools() {
echo Get the current working directory so we can change directories back when done
WORKING_DIR=`pwd`
echo If no directory where depot tools should be...
if [ ! -d "$DEPOT_TOOLS" ]
then
echo Make directory for gclient called Depot Tools
mkdir -p "$DEPOT_TOOLS"
echo Pull the depot tools project from chromium source into the depot tools directory
git clone "https://chromium.googlesource.com/chromium/tools/depot_tools.git" "$DEPOT_TOOLS"
else
echo Change directory into the depot tools
cd "$DEPOT_TOOLS"
echo Pull the depot tools down to the latest
git pull
fi
PATH="$PATH:$DEPOT_TOOLS"
echo "Go back to working directory"
cd "$WORKING_DIR"
}
function choose_code_signing() {
if [ "$WEBRTC_TARGET" == "AppRTCDemo" ]; then
echo "AppRTCDemo target requires code signing since we are building an *.ipa"
if [[ -z $IDENTITY ]]
then
COUNT=$(security find-identity -v | grep -c "iPhone Developer")
if [[ $COUNT -gt 1 ]]
then
security find-identity -v
echo "Please select your code signing identity index from the above list:"
read INDEX
IDENTITY=$(security find-identity -v | awk -v i=$INDEX -F "\\\) |\"" '{if (i==$1) {print $3}}')
else
IDENTITY=$(security find-identity -v | grep "iPhone Developer" | awk -F "\) |\"" '{print $3}')
fi
echo Using code signing identity $IDENTITY
fi
sed -i -e "s/\'CODE_SIGN_IDENTITY\[sdk=iphoneos\*\]\': \'iPhone Developer\',/\'CODE_SIGN_IDENTITY[sdk=iphoneos*]\': \'$IDENTITY\',/" $WEBRTC/src/build/common.gypi
fi
}
# Set the base of the GYP defines, instructing gclient runhooks what to generate
function wrbase() {
export GYP_CROSSCOMPILE=1
if [ "$WEBRTC_TARGET" != "AppRTCDemo" ]; then
GYP_DEFINES="chromium_ios_signing=0"
fi
export GYP_GENERATORS="ninja,xcode-ninja"
}
# Add the iOS Device specific defines on top of the base
function wrios_armv7() {
wrbase
export GYP_DEFINES="$GYP_DEFINES OS=ios target_arch=arm"
export GYP_GENERATOR_FLAGS="output_dir=out_ios_armeabi_v7a"
export GYP_CROSSCOMPILE=1
}
# Add the iOS ARM 64 Device specific defines on top of the base
function wrios_armv8() {
wrbase
export GYP_DEFINES="$GYP_DEFINES OS=ios target_arch=arm64"
export GYP_GENERATOR_FLAGS="output_dir=out_ios_arm64_v8a"
export GYP_CROSSCOMPILE=1
}
# Add the iOS Simulator X86 specific defines on top of the base
function wrX86() {
wrbase
export GYP_DEFINES="$GYP_DEFINES OS=ios target_arch=ia32"
export GYP_GENERATOR_FLAGS="output_dir=out_ios_x86"
}
# Add the iOS Simulator X64 specific defines on top of the base
function wrX86_64() {
wrbase
export GYP_DEFINES="$GYP_DEFINES OS=ios target_arch=x64 target_subarch=arm64"
export GYP_GENERATOR_FLAGS="output_dir=out_ios_x86_64"
}
# Add the Mac 64 bit intel defines
function wrMac64() {
wrbase
export GYP_DEFINES="$GYP_DEFINES OS=mac target_arch=x64 mac_sdk=$MAC_SDK"
export GYP_GENERATOR_FLAGS="output_dir=out_mac_x86_64"
}
# Gets the revision number of the current WebRTC svn repo on the filesystem
function get_revision_number() {
DIR=`pwd`
cd "$WEBRTC/src"
REVISION_NUMBER=`git log -1 | grep 'Cr-Commit-Position: refs/heads/master@{#' | grep -v '>' | egrep -o "[0-9]+}" | tr -d '}'`
if [ -z "$REVISION_NUMBER" ]
then
REVISION_NUMBER=`git log -1 | grep 'Cr-Commit-Position: refs/branch-heads/' | grep -v '>' | egrep -o "[0-9]+" | awk 'NR%2{printf $0"-";next;}1'`
fi
if [ -z "$REVISION_NUMBER" ]
then
REVISION_NUMBER=`git describe --tags | sed 's/\([0-9]*\)-.*/\1/'`
fi
if [ -z "$REVISION_NUMBER" ]
then
echo "Error grabbing revision number"
exit 1
fi
echo $REVISION_NUMBER
cd "$DIR"
}
# This function allows you to pull the latest changes from WebRTC without doing an entire clone, much faster to build and try changes
# Pass in a revision number as an argument to pull that specific revision ex: update2Revision 6798
function update2Revision() {
# Ensure that we have gclient added to our environment, so this function can run standalone
pull_depot_tools
cd "$WEBRTC"
# Setup gclient config
echo Configuring gclient for iOS build
if [ -z $USER_WEBRTC_URL ]
then
echo "User has not specified a different webrtc url. Using default"
gclient config --unmanaged --name=src "$DEFAULT_WEBRTC_URL"
else
echo "User has specified their own webrtc url $USER_WEBRTC_URL"
gclient config --unmanaged --name=src "$USER_WEBRTC_URL"
fi
# # Make sure that the target os is set to JUST MAC at first by adding that to the .gclient file that gclient config command created
# # Note this is a workaround until one of the depot_tools/ios bugs has been fixed
# echo "target_os = ['mac']" >> .gclient
# if [ -z $1 ]
# then
# sync
# else
# sync "$1"
# fi
# # Delete the last line saying we will only build for mac
# sed -i "" '$d' .gclient
# Write mac and ios to the target os in the gclient file generated by gclient config
echo "target_os = ['ios', 'mac']" >> .gclient
if [ -z $1 ]
then
sync
else
sync "$1"
fi
# Inject the new libWebRTC_objc target magic
if [ "$WEBRTC_TARGET" == "libWebRTC_objc" ] ; then
twiddle_objc_target
fi
echo "-- webrtc has been successfully updated"
}
# This function cleans out your webrtc directory and does a fresh clone -- slower than a pull
# Pass in a revision number as an argument to clone that specific revision ex: clone 6798
function clone() {
DIR=`pwd`
rm -rf "$WEBRTC"
mkdir -v "$WEBRTC"
update2Revision "$1"
}
# Fire the sync command. Accepts an argument as the revision number that you want to sync to
function sync() {
pull_depot_tools
cd "$WEBRTC"
choose_code_signing
if [ "$WEBRTC_TARGET" == "libWebRTC_objc" ] ; then
twiddle_objc_target
else
untwiddle_objc_target
fi
if [ -z $1 ]
then
gclient sync --with_branch_heads || true
else
gclient sync -r "$1" --with_branch_heads || true
fi
}
# Functions to twiddle the libWebRTC_objc target so that we can build the files that we need and exclude socket rocket and such
function twiddle_objc_target () {
cd "$WEBRTC"
echo "Adding a new libWebRTC_objc target"
echo "$PROJECT_DIR/insert_two_lines_after_text.py"
python "$PROJECT_DIR/insert_two_lines_after_text.py" "$WEBRTC/src/webrtc/webrtc_examples.gyp"
}
function untwiddle_objc_target () {
cd "$WEBRTC/src"
file_changed=`git status --porcelain webrtc/webrtc_examples.gyp | awk '/^ M/{ print $2 }'`
if [ "$file_changed" == "webrtc/webrtc_examples.gyp" ] ; then
echo "Untwiddling the libWebRTC_objc target"
git checkout -- webrtc/webrtc_examples.gyp
fi
}
# Convenience function to copy the headers by creating a symbolic link to the headers directory deep within webrtc src
function copy_headers() {
if [ ! -h "$WEBRTC/headers" ]; then
create_directory_if_not_found "$BUILD"
ln -s "$WEBRTC/src/talk/app/webrtc/objc/public/" "$WEBRTC/headers" || true
fi
}
function build_webrtc_mac() {
if [ -d "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$MAC_SDK.sdk" ]
then
echo "Found $MAC_SDK sdk"
cd "$WEBRTC/src"
wrMac64
export MACOSX_DEPLOYMENT_TARGET="$MAC_SDK"
choose_code_signing
gclient runhooks
copy_headers
WEBRTC_REVISION=`get_revision_number`
if [ "$WEBRTC_DEBUG" = true ] ; then
exec_ninja "out_mac_x86_64/Debug/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-mac-x86_64-Debug.a" "$WEBRTC"/src/out_mac_x86_64/Debug/*.a
fi
if [ "$WEBRTC_RELEASE" = true ] ; then
exec_ninja "out_mac_x86_64/Release/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-mac-x86_64-Release.a" "$WEBRTC"/src/out_mac_x86_64/Release/*.a
exec_strip "$BUILD/libWebRTC-$WEBRTC_REVISION-mac-x86_64-Release.a"
fi
else
echo "Change the OSX Target by changing the MAC_SDK environment variable to 10.9. There is a bug with building mac target 10.10 (it assumes its 10.1 and lower than 10.8)"
echo "---------- OR ----------"
echo "Please download Xcode 5.1.1 (http://adcdownload.apple.com/Developer_Tools/xcode_5.1.1/xcode_5.1.1.dmg) and open"
echo "Copy the MacOSX10.8.sdk from the DMG to the current Xcode SDK"
echo "sudo cp -a /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs"
exit 1
fi
}
# Build AppRTC Demo for the simulator (ia32 architecture)
function build_apprtc_sim() {
cd "$WEBRTC/src"
wrX86
choose_code_signing
gclient runhooks
copy_headers
WEBRTC_REVISION=`get_revision_number`
if [ "$WEBRTC_DEBUG" = true ] ; then
exec_ninja "out_ios_x86/Debug-iphonesimulator/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-x86-Debug.a" "$WEBRTC"/src/out_ios_x86/Debug-iphonesimulator/*.a
fi
if [ "$WEBRTC_PROFILE" = true ] ; then
exec_ninja "out_ios_x86/Profile-iphonesimulator/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-x86-Profile.a" "$WEBRTC"/src/out_ios_x86/Profile-iphonesimulator/*.a
fi
if [ "$WEBRTC_RELEASE" = true ] ; then
exec_ninja "out_ios_x86/Release-iphonesimulator/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-x86-Release.a" "$WEBRTC"/src/out_ios_x86/Release-iphonesimulator/*.a
exec_strip "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-x86-Release.a"
fi
}
# Build AppRTC Demo for the 64 bit simulator (x86_64 architecture)
function build_apprtc_sim64() {
cd "$WEBRTC/src"
wrX86_64
choose_code_signing
gclient runhooks
copy_headers
WEBRTC_REVISION=`get_revision_number`
if [ "$WEBRTC_DEBUG" = true ] ; then
exec_ninja "out_ios_x86_64/Debug-iphonesimulator/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-x86_64-Debug.a" "$WEBRTC"/src/out_ios_x86_64/Debug-iphonesimulator/*.a
fi
if [ "$WEBRTC_PROFILE" = true ] ; then
exec_ninja "out_ios_x86_64/Profile-iphonesimulator/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-x86_64-Profile.a" "$WEBRTC"/src/out_ios_x86_64/Profile-iphonesimulator/*.a
fi
if [ "$WEBRTC_RELEASE" = true ] ; then
exec_ninja "out_ios_x86_64/Release-iphonesimulator/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-x86_64-Release.a" "$WEBRTC"/src/out_ios_x86_64/Release-iphonesimulator/*.a
exec_strip "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-x86_64-Release.a"
fi
}
# Build AppRTC Demo for a real device
function build_apprtc() {
cd "$WEBRTC/src"
wrios_armv7
choose_code_signing
gclient runhooks
copy_headers
WEBRTC_REVISION=`get_revision_number`
if [ "$WEBRTC_DEBUG" = true ] ; then
exec_ninja "out_ios_armeabi_v7a/Debug-iphoneos/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-armeabi_v7a-Debug.a" "$WEBRTC"/src/out_ios_armeabi_v7a/Debug-iphoneos/*.a
fi
if [ "$WEBRTC_PROFILE" = true ] ; then
exec_ninja "out_ios_armeabi_v7a/Profile-iphoneos/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-armeabi_v7a-Profile.a" "$WEBRTC"/src/out_ios_armeabi_v7a/Profile-iphoneos/*.a
fi
if [ "$WEBRTC_RELEASE" = true ] ; then
exec_ninja "out_ios_armeabi_v7a/Release-iphoneos/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-armeabi_v7a-Release.a" "$WEBRTC"/src/out_ios_armeabi_v7a/Release-iphoneos/*.a
exec_strip "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-armeabi_v7a-Release.a"
fi
}
# Build AppRTC Demo for an armv7 real device
function build_apprtc_arm64() {
cd "$WEBRTC/src"
wrios_armv8
choose_code_signing
gclient runhooks
copy_headers
WEBRTC_REVISION=`get_revision_number`
if [ "$WEBRTC_DEBUG" = true ] ; then
exec_ninja "out_ios_arm64_v8a/Debug-iphoneos/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-arm64_v8a-Debug.a" "$WEBRTC"/src/out_ios_arm64_v8a/Debug-iphoneos/*.a
fi
if [ "$WEBRTC_PROFILE" = true ] ; then
exec_ninja "out_ios_arm64_v8a/Profile-iphoneos/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-arm64_v8a-Profile.a" "$WEBRTC"/src/out_ios_arm64_v8a/Profile-iphoneos/*.a
fi
if [ "$WEBRTC_RELEASE" = true ] ; then
exec_ninja "out_ios_arm64_v8a/Release-iphoneos/"
exec_libtool "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-arm64_v8a-Release.a" "$WEBRTC"/src/out_ios_arm64_v8a/Release-iphoneos/*.a
exec_strip "$BUILD/libWebRTC-$WEBRTC_REVISION-ios-arm64_v8a-Release.a"
fi
}
# This function is used to put together the intel (simulator), armv7 and arm64 builds (device) into one static library so its easy to deal with in Xcode
# Outputs the file into the build directory with the revision number
function lipo_intel_and_arm() {
if [ "$WEBRTC_DEBUG" = true ] ; then
lipo_for_configuration "Debug"
fi
if [ "$WEBRTC_PROFILE" = true ] ; then
lipo_for_configuration "Profile"
fi
if [ "$WEBRTC_RELEASE" = true ] ; then
lipo_for_configuration "Release"
fi
}
function lipo_for_configuration() {
CONFIGURATION=$1
WEBRTC_REVISION=`get_revision_number`
# Directories to use for lipo, armv7 and ia32 as default
LIPO_DIRS="$BUILD/libWebRTC-$WEBRTC_REVISION-ios-armeabi_v7a-$CONFIGURATION.a"
# Add ARM64
LIPO_DIRS="$LIPO_DIRS $BUILD/libWebRTC-$WEBRTC_REVISION-ios-arm64_v8a-$CONFIGURATION.a"
# Add x86
LIPO_DIRS="$LIPO_DIRS $BUILD/libWebRTC-$WEBRTC_REVISION-ios-x86-$CONFIGURATION.a"
# and add x86_64
LIPO_DIRS="$LIPO_DIRS $BUILD/libWebRTC-$WEBRTC_REVISION-ios-x86_64-$CONFIGURATION.a"
# Lipo the simulator build with the ios build into a universal library
lipo -create -output "$BUILD/libWebRTC-$WEBRTC_REVISION-arm-intel-$CONFIGURATION.a" $LIPO_DIRS
# Delete the latest symbolic link just in case :)
if [ -a "$WEBRTC/libWebRTC-LATEST-Universal-$CONFIGURATION.a" ]
then
rm "$WEBRTC/libWebRTC-LATEST-Universal-$CONFIGURATION.a"
fi
# Create a symbolic link pointing to the exact revision that is the latest. This way I don't have to change the xcode project file every time we update the revision number, while still keeping it easy to track which revision you are on
ln -sf "$BUILD/libWebRTC-$WEBRTC_REVISION-arm-intel-$CONFIGURATION.a" "$WEBRTC/libWebRTC-LATEST-Universal-$CONFIGURATION.a"
# Make it clear which revision you are using .... You don't want to get in the state where you don't know which revision you were using... trust me
echo "The libWebRTC-LATEST-Universal-$CONFIGURATION.a in this same directory, is revision " > "$WEBRTC/libWebRTC-LATEST-Universal-$CONFIGURATION.a.version.txt"
# Also write to a file for funzies
echo $WEBRTC_REVISION >> "$WEBRTC/libWebRTC-LATEST-Universal-$CONFIGURATION.a.version.txt"
# Write the version down to a file
echo "Architectures Built" >> "$BUILD/libWebRTC-$WEBRTC_REVISION-arm-intel-$CONFIGURATION.a.version.txt"
echo "ia32 - Intel x86" >> "$BUILD/libWebRTC-$WEBRTC_REVISION-arm-intel-$CONFIGURATION.a.version.txt"
echo "ia64 - Intel x86_64" >> "$BUILD/libWebRTC-$WEBRTC_REVISION-arm-intel-$CONFIGURATION.a.version.txt"
echo "armv7 - Arm x86" >> "$BUILD/libWebRTC-$WEBRTC_REVISION-arm-intel-$CONFIGURATION.a.version.txt"
echo "arm64_v8a - Arm 64 (armv8)" >> "$BUILD/libWebRTC-$WEBRTC_REVISION-arm-intel-$CONFIGURATION.a.version.txt"
}
# Convenience method to just "get webrtc" -- a clone
# Pass in an argument if you want to get a specific webrtc revision
function get_webrtc() {
pull_depot_tools
update2Revision "$1"
}
# Build webrtc for an ios device and simulator, then create a universal library
function build_webrtc() {
pull_depot_tools
build_apprtc
build_apprtc_arm64
build_apprtc_sim
build_apprtc_sim64
lipo_intel_and_arm
}
# Create the static library, requires an argument specifiying Debug or Release
function create_archive_of_static_libraries() {
echo Get the current working directory so we can change directories back when done
WORKING_DIR=`pwd`
VERSION_BUILD=0
WEBRTC_REVISION=`get_revision_number`
echo "Creating Static Library"
create_directory_if_not_found "$BUILD/archives"
rm -rf "$BUILD/archives/$WEBRTC_REVISION/$1"
create_directory_if_not_found "$BUILD/archives/$WEBRTC_REVISION"
create_directory_if_not_found "$BUILD/archives/$WEBRTC_REVISION/$1"
create_directory_if_not_found "$BUILD/archives/LATEST/"
ln -sfv "$BUILD/archives/$WEBRTC_REVISION/$1" "$BUILD/archives/LATEST/"
cd "$BUILD/archives/$WEBRTC_REVISION/$1"
create_directory_if_not_found libjingle_peerconnection/
# Copy podspec with ios and mac
cp -v "$PROJECT_DIR/libjingle_peerconnection.podspec" "libjingle_peerconnection.podspec"
# inject pod url
if [ -z $USER_POD_URL ]
then
echo "User has not specified a different pod url. Using default"
sed -ic "s|{POD_URL}|"$DEFAULT_POD_URL"|g" libjingle_peerconnection.podspec
else
echo "User has specified their own pod url $USER_POD_URL"
sed -ic "s|{POD_URL}|"$USER_POD_URL"|g" libjingle_peerconnection.podspec
fi
# inject revision number
sed -ic "s/{WEBRTC_REVISION}/$WEBRTC_REVISION/g" libjingle_peerconnection.podspec
# inject build type string
sed -ic "s/{BUILD_TYPE_STRING}/$1/g" libjingle_peerconnection.podspec
if [ $1 = "Debug" ]
then
VERSION_BUILD=`get_version_build "$WEBRTC_REVISION" 0`
cp -fv "$BUILD/libWebRTC-$WEBRTC_REVISION-arm-intel-Debug.a" "libjingle_peerconnection/libWebRTC.a"
cp -fv "$BUILD/libWebRTC-$WEBRTC_REVISION-mac-x86_64-Debug.a" "libjingle_peerconnection/libWebRTC-osx.a"
sed -ic "s/{BUILD_TYPE}/0/g" libjingle_peerconnection.podspec
sed -ic "s/{VERSION_BUILD}/$VERSION_BUILD/g" libjingle_peerconnection.podspec
fi
if [ $1 = "Release" ]
then
VERSION_BUILD=`get_version_build "$WEBRTC_REVISION" 2`
cp -fv "$BUILD/libWebRTC-$WEBRTC_REVISION-arm-intel-Release.a" "libjingle_peerconnection/libWebRTC.a"
cp -fv "$BUILD/libWebRTC-$WEBRTC_REVISION-mac-x86_64-Release.a" "libjingle_peerconnection/libWebRTC-osx.a"
sed -ic "s/{BUILD_TYPE}/2/g" libjingle_peerconnection.podspec
sed -ic "s/{VERSION_BUILD}/$VERSION_BUILD/g" libjingle_peerconnection.podspec
fi
# write the revision and build type into a file
echo "revision $WEBRTC_REVISION $1 build" > "libjingle_peerconnection/libjingle_peerconnection_revision_build.txt"
# add headers
cp -fvR "$WEBRTC/src/talk/app/webrtc/objc/public/" "libjingle_peerconnection/Headers"
# Compress artifact
tar --use-compress-prog=pbzip2 -cvLf "libWebRTC.tar.bz2" *
echo Go back to working directory
cd "$WORKING_DIR"
}
# Grabs the current version build based on what is
function get_version_build() {
# Set version build
VERSION_BUILD=0
# Create temp output file to parse
pod search libjingle_peerconnection > /tmp/libjingle_search.log
if [ -z $USER_POD_URL ]
then
VERSION_BUILD=`egrep -o 'Versions: .*\[master repo\]' /tmp/libjingle_search.log | egrep -o '\d+\.\d\.\d+' | awk -v REVISION_NUM="$1" -v BUILD_TYPE="$2" -F '.' 'BEGIN{ VERSION_COUNT = 0 }; { if ($1 == REVISION_NUM && $2 == BUILD_TYPE) VERSION_COUNT += 1 }; END{ print VERSION_COUNT };'`
else
VERSION_BUILD=`egrep -o '\[master repo\].*' /tmp/libjingle_search.log | egrep -o '\d+\.\d\.\d+' | awk -v REVISION_NUM="$1" -v BUILD_TYPE="$2" -F '.' 'BEGIN{ VERSION_COUNT = 0 }; { if ($1 == REVISION_NUM && $2 == BUILD_TYPE) VERSION_COUNT += 1 }; END{ print VERSION_COUNT };'`
fi
echo "$VERSION_BUILD"
}
# Create an iOS "framework" for distribution sans CocoaPods
function create_ios_framework() {
if [ "$WEBRTC_DEBUG" = true ] ; then
create_ios_framework_for_configuration "Debug"
fi
if [ "$WEBRTC_PROFILE" = true ] ; then
create_ios_framework_for_configuration "Profile"
fi
if [ "$WEBRTC_RELEASE" = true ] ; then
create_ios_framework_for_configuration "Release"
fi
}
function create_ios_framework_for_configuration () {
CONFIGURATION=$1
rm -rf "$WEBRTC/Framework/$CONFIGURATION/WebRTC.framework"
mkdir -p "$WEBRTC/Framework/$CONFIGURATION/WebRTC.framework/Versions/A/Headers"
cp "$WEBRTC"/src/talk/app/webrtc/objc/public/*.h "$WEBRTC/Framework/$CONFIGURATION/WebRTC.framework/Versions/A/Headers"
cp "$WEBRTC/libWebRTC-LATEST-Universal-$CONFIGURATION.a" "$WEBRTC/Framework/$CONFIGURATION/WebRTC.framework/Versions/A/WebRTC"
WEBRTC_REVISION=`get_revision_number`
echo $WEBRTC_REVISION >> "$WEBRTC/Framework/$CONFIGURATION/WebRTC.framework/Version.txt"
pushd "$WEBRTC/Framework/$CONFIGURATION/WebRTC.framework/Versions"
ln -sfh A Current
popd
pushd "$WEBRTC/Framework/$CONFIGURATION/WebRTC.framework"
ln -sfh Versions/Current/Headers Headers
ln -sfh Versions/Current/WebRTC WebRTC
popd
}
# Get webrtc then build webrtc
function dance() {
# These next if statement trickery is so that if you run from the command line and don't set anything to build, it will default to the debug profile.
BUILD_DEBUG=true
if [ "$WEBRTC_RELEASE" = true ] ; then
BUILD_DEBUG=false
fi
if [ "$WEBRTC_PROFILE" = true ] ; then
BUILD_DEBUG=false
fi
if [ "$BUILD_DEBUG" = true ] ; then
WEBRTC_DEBUG=true
fi
get_webrtc $@
build_webrtc
echo "Finished Dancing!"
}