Skip to content

Commit d814d9f

Browse files
Rework build_android.sh to run parallel builds
1 parent af26fd4 commit d814d9f

File tree

1 file changed

+45
-51
lines changed

1 file changed

+45
-51
lines changed

build_android.sh

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22
set -euo pipefail
3+
shopt -s failglob
34

45
THIS_FILE=$(readlink -f "$0")
56
BASEDIR=$(dirname "$THIS_FILE")
@@ -9,8 +10,9 @@ LIB=$BASEDIR/lib-android
910
THIRD_PARTY_DIR=$BASEDIR/3rdparty
1011
THIRD_PARTY_DIR_SLASH_ESCAPED="${THIRD_PARTY_DIR//\//\\\/}\/"
1112

12-
# Based on Android app generate a project for library
13-
if [ ! -d "$LIB" ]; then
13+
# Generate library gradle project based on Android app
14+
if ! test -d "$LIB"
15+
then
1416
echo "Preparing $LIB"
1517

1618
# Copy necessary files from android app to android lib
@@ -52,68 +54,60 @@ fi
5254
# Build 3rdparty libraries
5355
cd $LIB
5456
./gradlew assemble
55-
for build_type in $THIRD_PARTY_DIR/built/cmake/*; do
56-
for build_type_and_abi in $build_type/*; do
57-
echo "Building LIB: $build_type_and_abi"
58-
cmake --build $build_type_and_abi
57+
58+
function wait_on_children_processes() {
59+
for pid in $pids
60+
do
61+
if ! wait $pid
62+
then
63+
echo "Build failed. Waiting for other subprocesses..."
64+
wait
65+
exit 1
66+
fi
5967
done
68+
}
69+
70+
pids=
71+
for build_target in $THIRD_PARTY_DIR/built/cmake/*/*
72+
do
73+
cmake --build $build_target &
74+
pids="$pids $!"
6075
done
76+
wait_on_children_processes $pids
6177

6278
# Build pdf2htmlEX
6379
cd $APP
6480
./gradlew assemble
65-
for build_type in $APP/app/.externalNativeBuild/cmake/*; do
66-
build_type_string=$(basename ${build_type})
67-
for build_type_and_abi in $build_type/*; do
68-
abi_string=$(basename ${build_type_and_abi})
69-
cmake --build $build_type_and_abi --target install
70-
71-
if [ ! -d "$build_type_and_abi/built/sample_pdfs" ]; then
72-
mkdir $build_type_and_abi/built/sample_pdfs
73-
fi
74-
cp -v $BASEDIR/test/browser_tests/*.pdf $build_type_and_abi/built/sample_pdfs/
75-
done
76-
done
77-
78-
echo ""
79-
echo ""
8081

81-
# Pack pdf2htmlEX binaries with UPX
82-
for build_type in $APP/app/.externalNativeBuild/cmake/*; do
83-
build_type_string=$(basename ${build_type})
84-
for build_type_and_abi in $build_type/*; do
85-
abi_string=$(basename ${build_type_and_abi})
82+
pids=
83+
for build_target in $APP/app/.externalNativeBuild/cmake/*/*
84+
do
85+
(
86+
set -euo pipefail
87+
cmake --build $build_target --target install
8688

87-
FINAL_BINARY=$build_type_and_abi/built/bin/pdf2htmlEX
89+
abi=$(basename $build_target)
90+
build_type=$(basename ${build_target%$abi})
8891

8992
# UPX only works on armeabi-v7a
9093
# Other ABIs produce segfaults.
91-
if [ "$abi_string" == "armeabi-v7a" ]; then
92-
upx --ultra-brute --8mib-ram $FINAL_BINARY
93-
upx -t $FINAL_BINARY
94+
if test $abi = "armeabi-v7a"
95+
then
96+
upx --ultra-brute --8mib-ram $build_target/built/bin/pdf2htmlEX
9497
fi
9598

96-
FINAL_TAR=$build_type_and_abi/${build_type_string}-${abi_string}-pdf2htmlEX.tar
97-
if [ -f "${FINAL_TAR}" ]; then
98-
echo "$FINAL_TAR is ready!"
99-
fi
99+
# Compress binaries and other files into .tar's
100+
mkdir --parents $build_target/built/sample_pdfs
101+
cp $BASEDIR/test/browser_tests/*.pdf $build_target/built/sample_pdfs/
100102

101-
ls -lha $build_type_and_abi/built/bin/pdf2htmlEX
102-
done
103+
tar --create --file $build_target/$build_type-$abi-pdf2htmlEX.tar --directory $build_target built
104+
) &
105+
pids="$pids $!"
103106
done
107+
wait_on_children_processes $pids
104108

105-
echo ""
106-
echo ""
107-
108-
# Compress binaries and other files into .tar's
109-
for build_type in $APP/app/.externalNativeBuild/cmake/*; do
110-
build_type_string=$(basename ${build_type})
111-
for build_type_and_abi in $build_type/*; do
112-
abi_string=$(basename ${build_type_and_abi})
113-
114-
FINAL_TAR=$build_type_and_abi/${build_type_string}-${abi_string}-pdf2htmlEX.tar
115-
tar -cf $FINAL_TAR --directory $build_type_and_abi built
116-
tar --list -f $FINAL_TAR
117-
echo "$FINAL_TAR is ready!"
118-
done
109+
for ft in $APP/app/.externalNativeBuild/cmake/*/*/*-pdf2htmlEX.tar
110+
do
111+
echo "$ft is ready!"
119112
done
113+

0 commit comments

Comments
 (0)