forked from vsimon/webrtcbuilds
-
Notifications
You must be signed in to change notification settings - Fork 71
/
util.sh
747 lines (664 loc) · 22.4 KB
/
util.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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
# Detect the host platform.
# Set PLATFORM environment variable to override default behavior.
# Supported platform types - 'linux', 'win', 'mac'
# 'msys' is the git bash shell, built using mingw-w64, running under Microsoft
# Windows.
function detect-platform() {
# set PLATFORM to android on linux host to build android
case "$OSTYPE" in
darwin*) PLATFORM=${PLATFORM:-mac} ;;
linux*) PLATFORM=${PLATFORM:-linux} ;;
win32*|msys*) PLATFORM=${PLATFORM:-win} ;;
*) echo "Building on unsupported OS: $OSTYPE"; exit 1; ;;
esac
}
# Cleanup the output directory.
#
# $1: The output directory.
function clean() {
local outdir="$1"
rm -rf $outdir/* $outdir/.gclient*
}
# Make sure depot tools are present.
#
# $1: The platform type.
# $2: The depot tools url.
# $3: The depot tools directory.
function check::depot-tools() {
local platform="$1"
local depot_tools_url="$2"
local depot_tools_dir="$3"
if [ ! -d $depot_tools_dir ]; then
git clone -q $depot_tools_url $depot_tools_dir
if [ $platform = 'win' ]; then
# run gclient.bat to get python
pushd $depot_tools_dir >/dev/null
./gclient.bat
popd >/dev/null
fi
else
pushd $depot_tools_dir >/dev/null
git reset --hard -q
popd >/dev/null
fi
}
# Make sure a package is installed. Depends on sudo to be installed first.
#
# $1: The name of the package
# $2: Existence check binary. Defaults to name of the package.
function ensure-package() {
local name="$1"
local binary="${2:-$1}"
if ! which $binary > /dev/null ; then
sudo apt-get update -qq
sudo apt-get install -y $name
fi
}
# Check if any of the arguments is executable (logical OR condition).
# Using plain "type" without any option because has-binary is intended
# to know if there is a program that one can call regardless if it is
# an alias, builtin, function, or a disk file that would be executed.
function has-binary () {
type "$1" &> /dev/null ;
}
# Setup Visual Studio build environment variables.
function init-msenv() {
# Rudimentary support for VS2017 in default install location due to
# lack of VS1S0COMNTOOLS environment variable.
if [ -d "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build" ]; then
vcvars_path="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build"
elif [ ! -z "$VS140COMNTOOLS" ]; then
vcvars_path="${VS140COMNTOOLS}../../VC"
else
echo "Building under Microsoft Windows requires Microsoft Visual Studio 2015 Update 3"
exit 1
fi
export DEPOT_TOOLS_WIN_TOOLCHAIN=0
pushd "$vcvars_path" >/dev/null
OLDIFS=$IFS
IFS=$'\n'
msvars=$(cmd //c "vcvarsall.bat $TARGET_CPU && set")
for line in $msvars; do
case $line in
INCLUDE=*|LIB=*|LIBPATH=*)
export $line ;;
PATH=*)
PATH=$(echo $line | sed \
-e 's/PATH=//' \
-e 's/\([a-zA-Z]\):[\\\/]/\/\1\//g' \
-e 's/\\/\//g' \
-e 's/;\//:\//g'):$PATH
export PATH
;;
esac
done
IFS=$OLDIFS
popd >/dev/null
}
# Make sure all build dependencies are present and platform specific
# environment variables are set.
#
# $1: The platform type.
function check::build::env() {
local platform="$1"
local target_cpu="$2"
case $platform in
mac)
# for GNU version of cp: gcp
which gcp || brew install coreutils
;;
linux)
if ! grep -v \# /etc/apt/sources.list | grep -q multiverse ; then
echo "*** Warning: The Multiverse repository is probably not enabled ***"
echo "*** which is required for things like msttcorefonts. ***"
fi
if ! which sudo > /dev/null ; then
apt-get update -qq
apt-get install -y sudo
fi
ensure-package curl
ensure-package git
ensure-package python
ensure-package lbzip2
ensure-package lsb-release lsb_release
;;
win)
init-msenv
# Required programs that may be missing on Windows
# TODO: check before running platform specific commands
REQUIRED_PROGS=(
bash
sed
git
openssl
find
grep
xargs
pwd
curl
rm
cat
# strings
)
# Check that required programs exist on the system.
# If they are missing, we abort.
for f in "${REQUIRED_PROGS[@]}" ; do
if ! has-binary "$f" ; then
echo "Error: '$f' is not installed." >&2
exit 1
fi
done
;;
esac
}
# Make sure all WebRTC build dependencies are present.
# $1: The platform type.
function check::webrtc::deps() {
local platform="$1"
local outdir="$2"
local target_os="$3"
case $platform in
linux)
# Automatically accepts ttf-mscorefonts EULA
echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections
sudo $outdir/src/build/install-build-deps.sh --no-syms --no-arm --no-chromeos-fonts --no-nacl --no-prompt
;;
esac
if [ $target_os = 'android' ]; then
sudo $outdir/src/build/install-build-deps-android.sh
fi
}
# Check out a specific revision.
#
# $1: The target OS type.
# $2: The output directory.
# $3: Revision represented as a git SHA.
function checkout() {
local target_os="$1"
local outdir="$2"
local revision="$3"
pushd $outdir >/dev/null
local prev_target_os=$(cat $outdir/.webrtcbuilds_target_os 2>/dev/null)
if [[ -n "$prev_target_os" && "$target_os" != "$prev_target_os" ]]; then
echo The target OS has changed. Refetching sources for the new target OS
rm -rf src .gclient*
fi
# Fetch only the first-time, otherwise sync.
if [ ! -d src ]; then
case $target_os in
android)
yes | fetch --nohooks webrtc_android
;;
ios)
fetch --nohooks webrtc_ios
;;
*)
fetch --nohooks webrtc
;;
esac
fi
# Remove all unstaged files that can break gclient sync
# NOTE: need to redownload resources
pushd src >/dev/null
# git reset --hard
git clean -f
popd >/dev/null
# Checkout the specific revision after fetch
gclient sync --force --revision $revision
# Cache the target OS
echo $target_os > $outdir/.webrtcbuilds_target_os
popd >/dev/null
}
# Patch a checkout for before building libraries.
#
# $1: The platform type.
# $2: The output directory.
function patch() {
local platform="$1"
local outdir="$2"
pushd $outdir/src >/dev/null
# This removes the examples from being built.
sed -i.bak 's|"//webrtc/examples",|#"//webrtc/examples",|' BUILD.gn
# This patches a GN error with the video_loopback executable depending on a
# test but since we disable building tests GN detects a dependency error.
# Replacing the outer conditional with 'rtc_include_tests' works around this.
# sed -i.bak 's|if (!build_with_chromium)|if (rtc_include_tests)|' webrtc/BUILD.gn
# Enable RTTI if required by removing the 'no_rtti' compiler flag.
# This fixes issues when compiling WebRTC with other libraries that have RTTI enabled.
# if [ $ENABLE_RTTI = 1 ]; then
# echo "Enabling RTTI"
# sed -i.bak 's|"//build/config/compiler:no_rtti",|#"//build/config/compiler:no_rtti",|' \
# build/config/BUILDCONFIG.gn
# fi
popd >/dev/null
}
# Compile using ninja.
#
# $1 The output directory, 'out/$TARGET_CPU/Debug', or 'out/$TARGET_CPU/Release'
# $2 Additional gn arguments
function compile::ninja() {
local outputdir="$1"
local gn_args="$2"
echo "Generating project files with: $gn_args"
gn gen $outputdir --args="$gn_args"
pushd $outputdir >/dev/null
# ninja -v -C .
ninja -C .
popd >/dev/null
}
# Combine build artifact objects into one library.
#
# The Microsoft Windows tools use different file extensions than the other tools:
# '.obj' as the object file extension, instead of '.o'
# '.lib' as the static library file extension, instead of '.a'
# '.dll' as the shared library file extension, instead of '.so'
#
# The Microsoft Windows tools have different names than the other tools:
# 'lib' as the librarian, instead of 'ar'. 'lib' must be found through the path
# variable $VS140COMNTOOLS.
#
# $1: The platform
# $2: The list of object file paths to be combined
# $3: The output library name
function combine::objects() {
local platform="$1"
local outputdir="$2"
local libname="libwebrtc_full"
# if [ $platform = 'win' ]; then
# local extname='obj'
# else
# local extname='o'
# fi
pushd $outputdir >/dev/null
rm -f $libname.*
# Prevent blacklisted objects such as ones containing a main function from
# being combined.
# Blacklist objects from video_capture_external and device_info_external so
# that the internal video capture module implementations get linked.
# unittest_main because it has a main function defined.
local blacklist="unittest|examples|tools|yasm/|protobuf_lite|main.o|video_capture_external.o|device_info_external.o"
# Method 1: Collect all .o files from .ninja_deps and some missing intrinsics
local objlist=$(strings .ninja_deps | grep -o ".*\.o")
local extras=$(find \
obj/third_party/libvpx/libvpx_* \
obj/third_party/libjpeg_turbo/simd_asm \
obj/third_party/boringssl/boringssl_asm -name "*\.o")
echo "$objlist" | tr ' ' '\n' | grep -v -E $blacklist >$libname.list
echo "$extras" | tr ' ' '\n' | grep -v -E $blacklist >>$libname.list
# Method 2: Collect all .o files from output directory
# local objlist=$(find . -name '*.o' | grep -v -E $blacklist)
# echo "$objlist" >$libname.list
# Combine all objects into one static library
case $platform in
win)
# TODO: Support VS 2017
"$VS140COMNTOOLS../../VC/bin/lib" /OUT:$libname.lib @$libname.list
;;
*)
# Combine *.o objects using ar
cat $libname.list | xargs ar -crs $libname.a
# Combine *.o objects into a thin library using ar
# cat $libname.list | xargs ar -ccT $libname.a
ranlib $libname.a
;;
esac
popd >/dev/null
}
# Combine built static libraries into one library.
#
# NOTE: This method is currently preferred since combining .o objects is
# causing undefined references to libvpx intrinsics on both Linux and Windows.
#
# The Microsoft Windows tools use different file extensions than the other tools:
# '.obj' as the object file extension, instead of '.o'
# '.lib' as the static library file extension, instead of '.a'
# '.dll' as the shared library file extension, instead of '.so'
#
# The Microsoft Windows tools have different names than the other tools:
# 'lib' as the librarian, instead of 'ar'. 'lib' must be found through the path
# variable $VS140COMNTOOLS.
#
# $1: The platform
# $2: The list of object file paths to be combined
# $3: The output library name
function combine::static() {
local platform="$1"
local outputdir="$2"
local libname="$3"
echo $libname
pushd $outputdir >/dev/null
rm -f $libname.*
# Find only the libraries we need
if [ $platform = 'win' ]; then
local whitelist="boringssl.dll.lib|protobuf_lite.dll.lib|webrtc\.lib|field_trial_default.lib|metrics_default.lib"
else
local whitelist="boringssl\.a|protobuf_full\.a|webrtc\.a|field_trial_default\.a|metrics_default\.a"
fi
cat .ninja_log | tr '\t' '\n' | grep -E $whitelist | sort -u >$libname.list
# Combine all objects into one static library
case $platform in
win)
# TODO: Support VS 2017
"$VS140COMNTOOLS../../VC/bin/lib" /OUT:$libname.lib @$libname.list
;;
*)
# Combine *.a static libraries
echo "CREATE $libname.a" >$libname.ar
while read a; do
echo "ADDLIB $a" >>$libname.ar
done <$libname.list
echo "SAVE" >>$libname.ar
echo "END" >>$libname.ar
ar -M < $libname.ar
ranlib $libname.a
;;
esac
popd >/dev/null
}
# Compile the libraries.
#
# $1: The platform type.
# $2: The output directory.
function compile() {
local platform="$1"
local outdir="$2"
local target_os="$3"
local target_cpu="$4"
local configs="$5"
local blacklist="$5"
# Set default default common and target args.
# `rtc_include_tests=false`: Disable all unit tests
# `treat_warnings_as_errors=false`: Don't error out on compiler warnings
local common_args="rtc_include_tests=false treat_warnings_as_errors=false"
local target_args="target_os=\"$target_os\" target_cpu=\"$target_cpu\""
# Build WebRTC with RTII enbled.
[ $ENABLE_RTTI = 1 ] && common_args+=" use_rtti=true"
# Static vs Dynamic CRT: When `is_component_build` is false static CTR will be
# enforced.By default Debug builds are dynamic and Release builds are static.
[ $ENABLE_STATIC_LIBS = 1 ] && common_args+=" is_component_build=false"
# `enable_iterator_debugging=false`: Disable libstdc++ debugging facilities
# unless all your compiled applications and dependencies define _GLIBCXX_DEBUG=1.
# This will cause errors like: undefined reference to `non-virtual thunk to
# cricket::VideoCapturer::AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>*,
# rtc::VideoSinkWants const&)'
[ $ENABLE_ITERATOR_DEBUGGING = 0 ] && common_args+=" enable_iterator_debugging=false"
# Use clang or gcc to compile WebRTC.
# The default compiler used by Chromium/WebRTC is clang, so there are frequent
# bugs and incompatabilities with gcc, especially with newer versions >= 4.8.
# Use gcc at your own risk, but it may be necessary if your compiler doesn't
# like the clang compiled libraries, so the option is there.
# Set `is_clang=false` and `use_sysroot=false` to build using gcc.
if [ $ENABLE_CLANG = 0 ]; then
common_args+=" is_clang=false"
[ $platform = 'linux' ] && common_args+=" use_sysroot=false linux_use_bundled_binutils=false use_custom_libcxx=false use_custom_libcxx_for_host=false"
fi
pushd $outdir/src >/dev/null
for cfg in $configs; do
[ "$cfg" = 'Release' ] && common_args+=' is_debug=false strip_debug_info=true symbol_level=0'
compile::ninja "out/$target_cpu/$cfg" "$common_args $target_args"
if [ $COMBINE_LIBRARIES = 1 ]; then
# Method 1: Merge the static .a/.lib libraries.
combine::static $platform "out/$target_cpu/$cfg" libwebrtc_full
# Method 2: Merge .o/.obj objects to create the library, although results
# have been inconsistent so the static merging method is default.
# combine::objects $platform "out/$target_cpu/$cfg" libwebrtc_full
fi
done
popd >/dev/null
}
# Package a compiled build into an archive file in the output directory.
#
# $1: The platform type.
# $2: The output directory.
# $3: The package filename.
# $4: The project's resource dirctory.
# $5: The build configurations.
# $6: The revision number.
function package::prepare() {
local platform="$1"
local outdir="$2"
local package_filename="$3"
local resource_dir="$4"
local configs="$5"
local revision_number="$6"
if [ $platform = 'mac' ]; then
CP='gcp'
else
CP='cp'
fi
pushd $outdir >/dev/null
# Create directory structure
mkdir -p $package_filename/include packages
pushd src >/dev/null
# Find and copy header files
local header_source_dir=webrtc
# Revision 19846 moved src/webrtc to src/
# https://webrtc.googlesource.com/src/+/92ea95e34af5966555903026f45164afbd7e2088
[ $revision_number -ge 19846 ] && header_source_dir=.
# Copy header files, skip third_party dir
find $header_source_dir -path './third_party' -prune -o -type f \( -name '*.h' \) -print | \
xargs -I '{}' $CP --parents '{}' $outdir/$package_filename/include
# Find and copy dependencies
# The following build dependencies were excluded:
# gflags, ffmpeg, openh264, openmax_dl, winsdk_samples, yasm
find $header_source_dir -name '*.h' -o -name README -o -name LICENSE -o -name COPYING | \
grep './third_party' | \
grep -E 'boringssl|expat/files|jsoncpp/source/json|libjpeg|libjpeg_turbo|libsrtp|libyuv|libvpx|opus|protobuf|usrsctp/usrsctpout/usrsctpout' | \
xargs -I '{}' $CP --parents '{}' $outdir/$package_filename/include
popd >/dev/null
# Find and copy libraries
for cfg in $configs; do
mkdir -p $package_filename/lib/$TARGET_CPU/$cfg
pushd src/out/$TARGET_CPU/$cfg >/dev/null
mkdir -p $outdir/$package_filename/lib/$TARGET_CPU/$cfg
if [ $COMBINE_LIBRARIES = 1 ]; then
find . -name '*.so' -o -name '*.dll' -o -name '*.lib' -o -name '*.a' -o -name '*.jar' | \
grep -E 'webrtc_full' | \
xargs -I '{}' $CP '{}' $outdir/$package_filename/lib/$TARGET_CPU/$cfg
else
find . -name '*.so' -o -name '*.dll' -o -name '*.lib' -o -name '*.a' -o -name '*.jar' | \
grep -E 'webrtc\.|boringssl|protobuf|system_wrappers' | \
xargs -I '{}' $CP '{}' $outdir/$package_filename/lib/$TARGET_CPU/$cfg
fi
popd >/dev/null
done
# Create pkgconfig files on linux
if [ $platform = 'linux' ]; then
for cfg in $configs; do
mkdir -p $package_filename/lib/$TARGET_CPU/$cfg/pkgconfig
CONFIG=$cfg envsubst '$CONFIG' < $resource_dir/pkgconfig/libwebrtc_full.pc.in > \
$package_filename/lib/$TARGET_CPU/$cfg/pkgconfig/libwebrtc_full.pc
done
fi
popd >/dev/null
}
# This packages a compiled build into a archive file in the output directory.
# $1: The platform type.
# $2: The output directory.
# $3: The package filename.
function package::archive() {
local platform="$1"
local outdir="$2"
local package_filename="$3"
if [ $platform = 'win' ]; then
OUTFILE=$package_filename.7z
else
OUTFILE=$package_filename.tar.gz #.tar.bz2
fi
pushd $outdir >/dev/null
# Archive the package
rm -f $OUTFILE
pushd $package_filename >/dev/null
if [ $platform = 'win' ]; then
$TOOLS_DIR/win/7z/7z.exe a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -ir!lib/$TARGET_CPU -ir!include -r ../packages/$OUTFILE
else
tar -czvf ../packages/$OUTFILE lib/$TARGET_CPU include
# tar cvf - lib/$TARGET_CPU include | gzip --best > ../packages/$OUTFILE
# zip -r $package_filename.zip $package_filename >/dev/null
fi
popd >/dev/null
popd >/dev/null
}
# This packages into a debian package in the output directory.
# $1: The output directory.
# $2: The package filename.
# $3: The package name.
# $4: The package version.
# $5: The architecture.
function package::debian() {
local outdir="$1"
local package_filename="$2"
local package_name="$3"
local package_version="$4"
local arch="$5"
local debianize="debianize/$package_filename"
echo "Debianize WebRTC"
pushd $outdir >/dev/null
mkdir -p $debianize/DEBIAN
mkdir -p $debianize/opt
mv $package_filename $debianize/opt/webrtc
cat << EOF > $debianize/DEBIAN/control
Package: $package_name
Architecture: $arch
Maintainer: Sourcey
Depends: debconf (>= 0.5.00)
Priority: optional
Version: $package_version
Description: webrtc static library
This package provides webrtc library generated with webrtcbuilds
EOF
fakeroot dpkg-deb --build $debianize
mv debianize/*.deb .
rm -rf debianize
popd >/dev/null
}
# Build and merge the output manifest.
#
# $1: The platform type.
# $2: The output directory.
# $3: The package filename.
function package::manifest() {
local platform="$1"
local outdir="$2"
local package_filename="$3"
if [ $platform = 'win' ]; then
OUTFILE=$package_filename.7z
else
OUTFILE=$package_filename.tar.gz
fi
mkdir -p $outdir/packages
pushd $outdir/packages >/dev/null
# Create a JSON manifest
rm -f $package_filename.json
cat << EOF > $package_filename.json
{
"file": "$OUTFILE",
"date": "$(current-rev-date)",
"branch": "${BRANCH}",
"revision": "${REVISION_NUMBER}",
"sha": "${REVISION}",
"crc": "$(file-crc $OUTFILE)",
"target_os": "${TARGET_OS}",
"target_cpu": "${TARGET_CPU}"
}
EOF
# # Merge JSON manifests
# # node manifest.js
# rm -f manifest.json
# echo '[' > manifest.json
# files=(*.json)
# (
# set -- "${files[@]}"
# until (( $# == 1 )); do
# if [ ! $1 = 'manifest.json' ]; then
# cat $1 >> manifest.json
# echo ',' >> manifest.json
# fi
# shift
# done
# cat $1 >> manifest.json
# )
# sed -i ':a;N;$!ba;s/\n//g' manifest.json
# sed -i 's/{/\n {/g' manifest.json
# echo ']' >> manifest.json
popd >/dev/null
}
# This interprets a pattern and returns the interpreted one.
# $1: The pattern.
# $2: The output directory.
# $3: The platform type.
# $4: The target os for cross-compilation.
# $5: The target cpu for cross-compilation.
# $6: The branch.
# $7: The revision.
# $8: The revision number.
function interpret-pattern() {
local pattern="$1"
local platform="$2"
local outdir="$3"
local target_os="$4"
local target_cpu="$5"
local branch="$6"
local revision="$7"
local revision_number="$8"
local debian_arch="$(debian-arch $target_cpu)"
local short_revision="$(short-rev $revision)"
pattern=${pattern//%p%/$platform}
pattern=${pattern//%to%/$target_os}
pattern=${pattern//%tc%/$target_cpu}
pattern=${pattern//%b%/$branch}
pattern=${pattern//%r%/$revision}
pattern=${pattern//%rn%/$revision_number}
pattern=${pattern//%da%/$debian_arch}
pattern=${pattern//%sr%/$short_revision}
echo "$pattern"
}
# Return the latest revision date from the current git repo.
function current-rev-date() {
git log -1 --format=%cd
}
# Return the latest revision from the git repo.
#
# $1: The git repo URL
function file-crc() {
local file_path="$1"
md5sum $file_path | grep -o '^\S*'
}
# Return the latest revision from the git repo.
#
# $1: The git repo URL
function latest-rev() {
local repo_url="$1"
git ls-remote $repo_url HEAD | cut -f1
}
# Return the associated revision number for a given git sha revision.
#
# $1: The git repo URL
# $2: The revision git sha string
function revision-number() {
local repo_url="$1"
local revision="$2"
# This says curl the revision log with text format, base64 decode it using
# openssl since its more portable than just 'base64', take the last line which
# contains the commit revision number and output only the matching {#nnn} part
openssl base64 -d -A <<< $(curl --silent $repo_url/+/$revision?format=TEXT) \
| tail -1 | egrep -o '{#([0-9]+)}' | tr -d '{}#'
}
# Return a short revision sha.
#
# $1: The revision string
function short-rev() {
local revision="$1"
echo $revision | cut -c -7
}
# This returns a short revision sha.
# $1: The target cpu for cross-compilation.
function debian-arch() {
local target_cpu="$1"
# set PLATFORM to android on linux host to build android
case "$target_cpu" in
x86*) echo "i386" ;;
x64*) echo "amd64" ;;
*) echo "$target_cpu" ;;
esac
}