This repository has been archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathprebuild.sh
executable file
·303 lines (257 loc) · 10.2 KB
/
prebuild.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
#!/bin/bash
#
# Fennec build scripts
# Copyright (C) 2020-2024 Matías Zúñiga, Andrew Nayenko, Tavi
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
set -e
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 versionName versionCode" >&1
exit 1
fi
# shellcheck source=paths.sh
source "$(dirname "$0")/paths.sh"
function localize_maven {
# Replace custom Maven repositories with mavenLocal()
find ./* -name '*.gradle' -type f -print0 | xargs -0 \
sed -n -i \
-e '/maven {/{:loop;N;/}$/!b loop;/plugins.gradle.org/!s/maven .*/mavenLocal()/};p'
# Make gradlew scripts call our Gradle wrapper
find ./* -name gradlew -type f | while read -r gradlew; do
echo -e '#!/bin/sh\ngradle "$@"' > "$gradlew"
chmod 755 "$gradlew"
done
}
# Set up Rust
"$rustup"/rustup-init.sh -y --no-update-default-toolchain
# shellcheck disable=SC1090,SC1091
source "$HOME/.cargo/env"
rustup default 1.82.0
#
# Fenix
#
pushd "$fenix"
# Set up the app ID, version name and version code
sed -i \
-e 's|applicationId "org.mozilla"|applicationId "us.spotco"|' \
-e 's|applicationIdSuffix ".firefox"|applicationIdSuffix ".fennec_dos"|' \
-e 's|"sharedUserId": "org.mozilla.firefox.sharedID"|"sharedUserId": "us.spotco.fennec_dos.sharedID"|' \
-e "s/Config.releaseVersionName(project)/'$1'/" \
-e "s/Config.generateFennecVersionCode(arch, aab)/$2/" \
app/build.gradle
sed -i \
-e '/android:targetPackage/s/org.mozilla.firefox/us.spotco.fennec_dos/' \
app/src/release/res/xml/shortcuts.xml
# Disable crash reporting
sed -i -e '/CRASH_REPORTING/s/true/false/' app/build.gradle
# Disable MetricController
sed -i -e '/TELEMETRY/s/true/false/' app/build.gradle
# Let it be Mull
sed -i \
-e 's/Firefox Daylight/Mull/; s/Firefox/Mull/g' \
-e '/about_content/s/Mozilla/Divested Computing Group/' \
app/src/*/res/values*/*strings.xml
# Fenix uses reflection to create a instance of profile based on the text of
# the label, see
# app/src/main/java/org/mozilla/fenix/perf/ProfilerStartDialogFragment.kt#185
sed -i \
-e '/Firefox(.*, .*)/s/Firefox/Mull/' \
-e 's/firefox_threads/mull_threads/' \
-e 's/firefox_features/mull_features/' \
app/src/main/java/org/mozilla/fenix/perf/ProfilerUtils.kt
# Replace proprietary artwork
rm app/src/release/res/drawable/ic_launcher_foreground.xml
rm app/src/release/res/mipmap-*/ic_launcher.webp
rm app/src/release/res/values/colors.xml
rm app/src/main/res/values-v24/styles.xml
sed -i -e '/android:roundIcon/d' app/src/main/AndroidManifest.xml
sed -i -e '/SplashScreen/,+5d' app/src/main/res/values-v27/styles.xml
find "$patches/fenix-overlay" -type f | while read -r src; do
dst=app/src/release/${src#"$patches/fenix-overlay/"}
mkdir -p "$(dirname "$dst")"
cp "$src" "$dst"
done
sed -i \
-e 's/googleg_standard_color_18/ic_download/' \
app/src/main/java/org/mozilla/fenix/components/menu/compose/ExtensionsSubmenu.kt \
app/src/main/java/org/mozilla/fenix/components/menu/compose/MenuItem.kt \
app/src/main/java/org/mozilla/fenix/compose/list/ListItem.kt
# Enable about:config
sed -i \
-e 's/aboutConfigEnabled(.*)/aboutConfigEnabled(true)/' \
app/src/*/java/org/mozilla/fenix/*/GeckoProvider.kt
# Enable cookie banner handling
sed -i \
-e '168s/channel: developer/channel: release/' app/nimbus.fml.yaml
# Set up target parameters
case $(echo "$2" | cut -c 7) in
0)
abi=armeabi-v7a
target=arm-linux-androideabi
echo "ARM" > "$llvm/targets_to_build"
rusttarget=arm
rustup target add thumbv7neon-linux-androideabi
rustup target add armv7-linux-androideabi
;;
1)
abi=x86
target=i686-linux-android
echo "X86" > "$llvm/targets_to_build"
rusttarget=x86
rustup target add i686-linux-android
;;
2)
abi=arm64-v8a
target=aarch64-linux-android
echo "AArch64" > "$llvm/targets_to_build"
rusttarget=arm64
rustup target add aarch64-linux-android
;;
*)
echo "Unknown target code in $2." >&2
exit 1
;;
esac
sed -i -e "s/include \".*\"/include \"$abi\"/" app/build.gradle
# Enable the auto-publication workflow
echo "autoPublish.application-services.dir=$application_services" >> local.properties
popd
#
# Glean
#
pushd "$glean"
echo "rust.targets=linux-x86-64,$rusttarget" >> local.properties
localize_maven
popd
#
# Android Components
#
pushd "$android_components"
find "$patches/a-c-overlay" -type f | while read -r src; do
cp "$src" "${src#"$patches/a-c-overlay/"}"
done
# Add the added search engines as `general` engines
sed -i \
-e '41i \ \ \ \ "brave",\n\ \ \ \ "ddghtml",\n\ \ \ \ "ddglite",\n\ \ \ \ "metager",\n\ \ \ \ "mojeek",\n\ \ \ \ "qwantlite",\n\ \ \ \ "startpage",' \
components/feature/search/src/main/java/mozilla/components/feature/search/storage/SearchEngineReader.kt
# Hack to prevent too long string from breaking build
sed -i '/val statusCmd/,+3d' plugins/config/src/main/java/ConfigPlugin.kt
sed -i '/\/\/ Append "+"/a \ val statusSuffix = "+"' plugins/config/src/main/java/ConfigPlugin.kt
popd
#
# Application Services
#
pushd "$application_services"
# Break the dependency on older A-C
sed -i -e '/android-components = /s/131\.0\.2/133.0.3/' gradle/libs.versions.toml
echo "rust.targets=linux-x86-64,$rusttarget" >> local.properties
sed -i -e '/NDK ez-install/,/^$/d' libs/verify-android-ci-environment.sh
sed -i -e '/content {/,/}/d' build.gradle
localize_maven
# Fix stray
sed -i -e '/^ mavenLocal/{n;d}' tools/nimbus-gradle-plugin/build.gradle
# Fail on use of prebuilt binary
sed -i 's|https://|hxxps://|' tools/nimbus-gradle-plugin/src/main/groovy/org/mozilla/appservices/tooling/nimbus/NimbusGradlePlugin.groovy
popd
#
# WASI SDK
#
pushd "$wasi"
patch -p1 --no-backup-if-mismatch --quiet < "$mozilla_release/taskcluster/scripts/misc/wasi-sdk.patch"
popd
#
# GeckoView
#
pushd "$mozilla_release"
# Remove Mozilla repositories substitution and explicitly add the required ones
patch -p1 --no-backup-if-mismatch --quiet < "$patches/gecko-localize_maven.patch"
# Replace GMS with microG client library
patch -p1 --no-backup-if-mismatch --quiet < "$patches/gecko-liberate.patch"
# Patch the use of proprietary and tracking libraries
patch -p1 --no-backup-if-mismatch --quiet < "$patches/fenix-liberate.patch"
# Set strict ETP by default
patch -p1 --no-backup-if-mismatch --quiet < "$patches/strict_etp.patch"
# Enable HTTPS only mode by default
patch -p1 --no-backup-if-mismatch --quiet < "$patches/https_only.patch"
# Fix v125 compile error
patch -p1 --no-backup-if-mismatch --quiet < "$patches/gecko-fix-125-compile.patch"
# Fix v125 aar output not including native libraries
sed -i \
-e 's/singleVariant("debug")/singleVariant("release")/' \
mobile/android/exoplayer2/build.gradle
sed -i \
-e "s/singleVariant('debug')/singleVariant('release')/" \
mobile/android/geckoview/build.gradle
# Hack the timeout for
# geckoview:generateJNIWrappersForGeneratedWithGeckoBinariesDebug
sed -i \
-e 's/max_wait_seconds=600/max_wait_seconds=1800/' \
mobile/android/gradle.py
# Patch the LLVM source code
# Search clang- in https://android.googlesource.com/platform/ndk/+/refs/tags/ndk-r27/ndk/toolchains.py
LLVM_SVN='522817'
python3 $toolchain_utils/llvm_tools/patch_manager.py \
--svn_version $LLVM_SVN \
--patch_metadata_file $llvm_android/patches/PATCHES.json \
--src_path $llvm
# Configure
sed -i -e '/check_android_tools("emulator"/d' build/moz.configure/android-sdk.configure
cat << EOF > mozconfig
ac_add_options --disable-crashreporter
ac_add_options --disable-debug
ac_add_options --disable-nodejs
ac_add_options --disable-profiling
ac_add_options --disable-rust-debug
ac_add_options --disable-tests
ac_add_options --disable-updater
ac_add_options --enable-application=mobile/android
ac_add_options --enable-hardening
ac_add_options --enable-optimize
ac_add_options --enable-release
ac_add_options --enable-minify=properties # JS minification breaks addons
ac_add_options --enable-update-channel=release
ac_add_options --enable-rust-simd
ac_add_options --enable-strip
ac_add_options --target=$target
ac_add_options --with-android-ndk="$ANDROID_NDK"
ac_add_options --with-android-sdk="$ANDROID_SDK"
ac_add_options --with-libclang-path="$llvm/out/lib"
ac_add_options --with-java-bin-path="/usr/bin"
ac_add_options --with-gradle=$(command -v gradle)
ac_add_options --with-wasi-sysroot="$wasi/build/install/wasi/share/wasi-sysroot"
ac_add_options CC="$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"
ac_add_options CXX="$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++"
ac_add_options STRIP="$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip"
ac_add_options WASM_CC="$wasi/build/install/wasi/bin/clang"
ac_add_options WASM_CXX="$wasi/build/install/wasi/bin/clang++"
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj
EOF
# Disable Gecko Media Plugins and casting
sed -i -e '/gmp-provider/d; /casting.enabled/d' mobile/android/app/geckoview-prefs.js
cat << EOF >> mobile/android/app/geckoview-prefs.js
// Disable Encrypted Media Extensions
pref("media.eme.enabled", false);
// Disable Gecko Media Plugins
pref("media.gmp-provider.enabled", false);
// Avoid openh264 being downloaded
pref("media.gmp-manager.url.override", "data:text/plain,");
// Disable openh264 if it is already downloaded
pref("media.gmp-gmpopenh264.enabled", false);
// Disable casting (Roku, Chromecast)
pref("browser.casting.enabled", false);
EOF
cat "$patches/preferences/userjs-arkenfox.js" >> mobile/android/app/geckoview-prefs.js
cat "$patches/preferences/userjs-brace.js" >> mobile/android/app/geckoview-prefs.js
popd