Repository navigation
Expand file tree
/
Copy pathdev-android.sh
More file actions
executable file
·216 lines (181 loc) · 7.11 KB
/
Copy pathdev-android.sh
File metadata and controls
executable file
·216 lines (181 loc) · 7.11 KB
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
#!/bin/bash
set -euo pipefail
# All paths are relative to the repository root
cd "$(dirname "$0")"
TARGETS="${WEBRTC_TARGETS:-arm arm64 x86 x64}"
BUILD_ARGS="${WEBRTC_BUILD_ARGS:-symbol_level=1 enable_libaom=false rtc_enable_protobuf=false rtc_include_dav1d_in_internal_decoder_factory=false}"
function print_usage {
echo "Usage: $0 <command> [<args>]"
echo ""
echo " clean"
echo " build-tools"
echo ""
echo " fetch [<revision>]"
echo " update"
echo " sync"
echo " patch [<patch-glob>]"
echo " format"
echo " build [<${TARGETS}>]"
echo " enter"
exit 1
}
function require_tools_image {
docker image inspect threema/webrtc-build-tools &>/dev/null || (
echo "Build tools image must be built first: \"$0 build-tools\""
exit 2
)
}
# Rootless podman maps the host user to root inside the container, so the
# container user could not write to the mounted volumes without keep-id
function docker_run {
if docker --version 2>/dev/null | grep -qi podman; then
docker run --userns=keep-id "$@"
else
docker run "$@"
fi
}
case ${1-} in
clean)
echo "Removing artifacts and build files"
rm -rf ./artifacts/android ./artifacts/android-dirty ./build/android
echo "Removing source files"
rm -rf ./webrtc/android
echo "Removing tools image"
docker rmi --force threema/webrtc-build-tools:latest || true
;;
build-tools)
echo "Building tools image"
docker build --build-arg UID="$(id -u)" --build-arg GID="$(id -g)" --pull --no-cache -t \
threema/webrtc-build-tools:latest build-tools/
;;
fetch)
require_tools_image
if [[ -d ./webrtc/android ]]; then
echo "Cannot fetch, source directory \"webrtc/android\" already exists"
echo "Run \"rm -rf webrtc/android\" to start from scratch"
exit 3;
fi
# Fetch sources
mkdir -p ./webrtc/android
revision="${2:-main}"
docker_run --rm -ti -v "$(pwd)/webrtc/android:/webrtc" threema/webrtc-build-tools:latest bash -c "
set -euo pipefail
echo \"Fetching sources\"
fetch webrtc_android
echo \"Syncing against ${revision}\"
(cd ./src && git checkout \"${revision}\")
gclient sync -D
"
;;
update)
require_tools_image
if [[ ! -d ./webrtc/android ]]; then
echo "Cannot update, source directory \"webrtc/android\" does not exist"
echo "Did you forget to run \"$0 fetch\"?"
exit 4;
fi
# Stash existing patches/uncommitted changes
(cd ./webrtc/android/src && git stash push -u)
# Update sources
docker_run --rm -ti -v "$(pwd)/webrtc/android:/webrtc" threema/webrtc-build-tools:latest bash -c "
set -euo pipefail
echo \"Updating source files and tracking branches\"
echo \"Note: This will leave all untracked branches untouched!\"
(cd ./src && git rebase-update)
gclient sync -D
echo \"Done. Any patches and uncommitted changes to libwebrtc need to be reapplied.\"
"
;;
sync)
require_tools_image
if [[ ! -d ./webrtc/android ]]; then
echo "Cannot update, source directory \"webrtc/android\" does not exist"
echo "Did you forget to run \"$0 fetch\"?"
exit 4;
fi
# Sync sources
docker_run --rm -ti -v "$(pwd)/webrtc/android:/webrtc" threema/webrtc-build-tools:latest bash -c "
set -euo pipefail
echo \"Syncing third party repos and running pre-compile hooks\"
gclient sync -D
"
;;
patch)
if [[ ! -d ./webrtc/android ]]; then
echo "Cannot patch, source directory \"webrtc/android\" does not exist"
echo "Did you forget to run \"$0 fetch\"?"
exit 4;
fi
# Stash existing patches/uncommitted changes
(cd ./webrtc/android/src && git stash push -u)
# Apply patches
pattern=${2-*.patch}
cd ./webrtc/android/src
shopt -s nullglob
patch_count=0
for patch in ../../../patches/${pattern}; do
echo "Applying patch ${patch}"
git apply "${patch}"
patch_count=$((patch_count+1))
done
echo "Applied ${patch_count} patches"
;;
format)
require_tools_image
if [[ ! -d ./webrtc/android ]]; then
echo "Cannot format, source directory \"webrtc/android\" does not exist"
echo "Did you forget to run \"$0 fetch\"?"
exit 4;
fi
# Format
docker_run --rm -ti -v "$(pwd)/webrtc/android:/webrtc" threema/webrtc-build-tools:latest bash -c "
set -euo pipefail
cd ./src
git cl format
"
;;
build)
require_tools_image
if [[ ! -d ./webrtc/android ]]; then
echo "Cannot build, source directory \"webrtc/android\" does not exist"
echo "Did you forget to run \"$0 fetch\"?"
exit 4;
fi
# Log revision, status and build args
echo "Logging revision, status and build args"
mkdir -p ./artifacts/android-dirty
(
cd ./webrtc/android/src
git log --pretty=fuller HEAD...HEAD^ > ../../../artifacts/android-dirty/revision.txt
echo "" >> ../../../artifacts/android-dirty/revision.txt
git status --short >> ../../../artifacts/android-dirty/revision.txt
)
echo "${BUILD_ARGS}" > ./artifacts/android-dirty/build-args.txt
# Build each target and copy artifacts
if [ -n "${2-}" ]; then
targets=("${@:2}")
else
IFS=' ' read -r -a targets <<< "${TARGETS}"
fi
for target in "${targets[@]}"; do
echo "Building for ${target}"
docker_run --rm -ti -v "$(pwd)/webrtc/android:/webrtc" threema/webrtc-build-tools:latest bash -ci "
set -euo pipefail
cd ./src
gn gen \"./out/android/${target}\" --args=\"cc_wrapper=\\\"ccache\\\" target_os=\\\"android\\\" debuggable_apks=false is_component_build=false rtc_include_tests=false target_cpu=\\\"${target}\\\" android_static_analysis=\\\"off\\\" use_siso=true ${BUILD_ARGS}\"
source ./build/android/envsetup.sh
autoninja -C \"./out/android/${target}\" sdk/android:libwebrtc sdk/android:libjingle_peerconnection_so
"
mkdir -p "./artifacts/android-dirty/${target}/"
cp "./webrtc/android/src/out/android/${target}/libjingle_peerconnection_so.so" "./artifacts/android-dirty/${target}/"
cp "./webrtc/android/src/out/android/${target}/lib.java/sdk/android/libwebrtc.jar" ./artifacts/android-dirty/
done
;;
enter)
require_tools_image
# Enter an interactive shell
docker_run --rm -ti -v "$(pwd)/webrtc/android:/webrtc" -v "$(pwd)/patches:/patches" threema/webrtc-build-tools:latest
;;
*)
print_usage "$0"
esac