-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.sh
executable file
·338 lines (309 loc) · 10.2 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
#!/bin/bash
if [ "$#" -ne 1 ] && [ "$#" -ne 2 ]; then
echo "Usage: $0 VERSION [apply|noclobber]" >&2
exit 1
fi
APPLY=""
NOCLOBBER=""
DELRES=""
if [ "$#" -eq 2 ]; then
if [ "$2" = "apply" ]; then
APPLY="apply"
elif [ "$2" = "noclobber" ]; then
NOCLOBBER="noclobber"
elif [ "$2" = "delres" ]; then
DELRES="delres"
else
echo "Usage: $0 VERSION [apply|noclobber]" >&2
exit 1
fi
fi
if ! [ -d thunderbird-patches ]; then
echo "No clone of https://github.com/Betterbird/thunderbird-patches.git" >&2
echo "How did you get this build script in the first place?" >&2
exit 1
fi
echo
echo "======================================================="
echo "Updating Betterbird patches"
cd thunderbird-patches
git pull
cd ..
DIFF=$(diff -q build.sh thunderbird-patches/build/build.sh)
if [ "|$DIFF|" != "||" ]; then
echo "Newer version of build script available."
echo "Please |cp thunderbird-patches/build/build.sh .| and restart"
exit 1
fi
if ! [ -d thunderbird-patches/"$1" ]; then
echo "No such version" >&2
exit 1
fi
VERSION="$1"
UNAME=$(uname)
# uname -i doesn't work on Mac.
UNAME_ARCH="unknown"
if [ "$UNAME" = "Linux" ]; then
UNAME_FULL=$(uname -a)
UNAME_ARCH=$(uname -i)
# Hack for Debian 11 Bullseye on Amazon EC2 image.
if [[ "$UNAME_FULL" == *"aarch64"* ]] && [ "$UNAME_ARCH" = "unknown" ]; then
UNAME_ARCH="aarch64"
fi
fi
# Windows: Cater for newer and older MozillaBuild: MINGW32_NT-6.2 or MSYS_NT-10
if [[ "$UNAME" == *"_NT-"* ]]; then
UNAME="Windows"
fi
. ./thunderbird-patches/$VERSION/$VERSION.sh
echo
echo "======================================================="
echo "Preparing Mozilla repo"
echo " for $MOZILLA_REPO"
echo " at $MOZILLA_REV"
MOZILLA_DIR="$(basename $MOZILLA_REPO)"
if [ -d $MOZILLA_DIR ]; then
cd $MOZILLA_DIR
else
echo "Mozilla directory $MOZILLA_DIR not found"
echo "Do you want to clone the Mozilla repo?"
echo "This will take 30 minutes or more and will pull 2 GB of data."
read -p "Proceed? (Y/N) " ANSWER
if [ "$ANSWER" != "Y" ]; then
echo "Y not received, exiting"
exit 1
fi
echo
echo "======================================================="
echo "Cloning $MOZILLA_REPO"
hg clone $MOZILLA_REPO || exit 1
echo
echo "======================================================="
echo "Cloning $COMM_REPO"
cd $MOZILLA_DIR
hg clone $COMM_REPO comm || exit 1
fi
if [ "$UNAME" = "Windows" ] && [ "$DELRES" = "delres" ] && [ -d obj-x86_64-pc-mingw32 ]; then
echo
echo "======================================================="
echo "Deleting .rc and .res files"
cd obj-x86_64-pc-mingw32
# del /s is much faster than find.
/C/Windows/system32/cmd.exe /C"del/s *.rc"
/C/Windows/system32/cmd.exe /C"del/s *.res"
cd ..
exit 0
fi
if [ "$UNAME" = "Linux" ] || [ "$UNAME" = "Darwin" ]; then
MQ=$(grep "mq =" .hg/hgrc)
if [ "|$MQ|" = "||" ]; then
echo "[extensions]" >> .hg/hgrc
echo "mq =" >> .hg/hgrc
fi
MQ=$(grep "mq =" comm/.hg/hgrc)
if [ "|$MQ|" = "||" ]; then
echo "[extensions]" >> comm/.hg/hgrc
echo "mq =" >> comm/.hg/hgrc
fi
else
# On Windows we assume mercurial.ini in the build directory.
if [ -f ../mercurial.ini ]; then
MQ=$(grep "mq =" ../mercurial.ini)
if [ "|$MQ|" = "||" ]; then
echo "[extensions]" >> ../mercurial.ini
echo "mq =" >> ../mercurial.ini
fi
fi
fi
set -e # fail on failing commands
# this is not at start of file due to grep "mq =" causing exit
echo
echo "======================================================="
echo "Removing old patches from $MOZILLA_DIR and updating"
hg revert --all
hg qpop --all
hg pull
hg update -r $MOZILLA_REV
echo
echo "======================================================="
echo "Preparing comm repo"
echo " for $COMM_REPO"
echo " at $COMM_REV"
cd comm
echo
echo "======================================================="
echo "Removing old patches from $MOZILLA_DIR/comm and updating"
hg revert --all
hg qpop --all
hg pull
hg update -r $COMM_REV
cd ..
echo
echo "======================================================="
echo "Copying patches and series file from thunderbird-patches"
if ! [ -d .hg/patches ]; then
mkdir .hg/patches
fi
if ! [ -d comm/.hg/patches ]; then
mkdir comm/.hg/patches
fi
cp ../thunderbird-patches/$VERSION/series$MOZU .hg/patches/series
cp ../thunderbird-patches/$VERSION/series comm/.hg/patches/series
cp ../thunderbird-patches/$VERSION/branding/*.patch comm/.hg/patches/
cp ../thunderbird-patches/$VERSION/bugs/*.patch comm/.hg/patches/
cp ../thunderbird-patches/$VERSION/features/*.patch comm/.hg/patches/
cp ../thunderbird-patches/$VERSION/misc/*.patch comm/.hg/patches/
mv comm/.hg/patches/*$MOZ.patch .hg/patches/
if [ -d ../private-patches ]; then
echo
echo "======================="
echo "Copying private patches"
cp ../private-patches/*.patch comm/.hg/patches/
fi
echo
echo "======================================================="
echo "Retrieving external patches for Mozilla repo"
echo "#!/bin/sh" > external.sh
grep " # " .hg/patches/series | grep -v "^#" >> external.sh || true
sed -i -e 's/\/rev\//\/raw-rev\//' external.sh
sed -i -e 's/\(.*\) # \(.*\)/wget -nc \2 -O .hg\/patches\/\1 || true/' external.sh
chmod 700 external.sh
. ./external.sh
rm external.sh
echo
echo "======================================================="
echo "Retrieving external patches for comm repo"
cd comm
echo "#!/bin/sh" > external.sh
grep " # " .hg/patches/series | grep -v "^#" >> external.sh || true
sed -i -e 's/\/rev\//\/raw-rev\//' external.sh
sed -i -e 's/\(.*\) # \(.*\)/wget -nc \2 -O .hg\/patches\/\1 || true/' external.sh
chmod 700 external.sh
. ./external.sh
rm external.sh
cd ..
echo
echo "======================================================="
echo "Pushing all patches"
hg qpush -all
hg qseries
cd comm
hg qpush -all
hg qseries
cd ..
if [ "$APPLY" = "apply" ]; then
echo
echo "======================================================="
echo "Patches applied, exiting."
exit 0
fi
if [ -f ../mach_bootstrap_was_run_$VERSION ]; then
echo
echo "======================================================="
echo "NOT running ./mach bootstrap since ./mach_bootstrap_was_run_$VERSION is present."
else
echo
echo "======================================================="
echo "Running ./mach bootstrap ONCE. This is controlled by ./mach_bootstrap_was_run_$VERSION."
echo "Note that this may require a restart of the shell."
touch ../mach_bootstrap_was_run_$VERSION
./mach --no-interactive bootstrap --application-choice "Firefox for Desktop"
$HOME/.cargo/bin/rustup override set $RUST_VER
if [ "$UNAME" = "Linux" ] && [ "$UNAME_ARCH" = "aarch64" ]; then
echo
echo "======================================================="
echo "./mach bootstrap on Linux/aarch64 likely failed to complete."
echo "Please follow the instructions here:"
echo "https://github.com/Betterbird/thunderbird-patches/blob/main/build/build-env-aarch64.MD"
echo "You only need to do all of these steps once or whenever the Betterbird build requires updated software versions."
exit 1
fi
fi
if [ "$UNAME" = "Linux" ]; then
if [ "$UNAME_ARCH" = "x86_64" ]; then
echo
echo "======================================================="
echo "Copying mozconfig-Linux"
cp ../thunderbird-patches/$VERSION/mozconfig-Linux mozconfig
elif [ "$UNAME_ARCH" = "aarch64" ]; then
echo
echo "======================================================="
echo "Copying mozconfig-Linux-aarch64"
cp ../thunderbird-patches/$VERSION/mozconfig-Linux-aarch64 mozconfig
fi
elif [ "$UNAME" = "Darwin" ]; then
echo
echo "======================================================="
echo "Copying mozconfig-Mac"
cp ../thunderbird-patches/$VERSION/mozconfig-Mac mozconfig
elif [ "$UNAME" = "Windows" ]; then
echo
echo "======================================================="
echo "Copying mozconfig for Windows"
cp ../thunderbird-patches/$VERSION/mozconfig mozconfig
fi
echo
echo "======================================================="
echo "Starting the build"
if [ "$UNAME" = "Windows" ] && [ -d obj-x86_64-pc-mingw32 ]; then
echo
echo "======================================================="
echo "Deleting .rc and .res files"
cd obj-x86_64-pc-mingw32
# del /s is much faster than find.
/C/Windows/system32/cmd.exe /C"del/s *.rc"
/C/Windows/system32/cmd.exe /C"del/s *.res"
cd ..
fi
if [ "$NOCLOBBER" = "noclobber" ]; then
echo
echo "======================================================="
echo "NOT running clobber."
if [ "$UNAME" = "Linux" ]; then
if [ "$UNAME_ARCH" = "x86_64" ] && [ -d obj-x86_64-pc-linux-gnu ]; then
touch obj-x86_64-pc-linux-gnu/CLOBBER
elif [ "$UNAME_ARCH" = "aarch64" ] && [ -d obj-aarch64-unknown-linux-gnu ]; then
touch obj-aarch64-unknown-linux-gnu/CLOBBER
fi
elif [ "$UNAME" = "Darwin" ] && [ -d obj-x86_64-apple-darwin ]; then
touch obj-x86_64-apple-darwin/CLOBBER
elif [ "$UNAME" = "Darwin" ] && [ -d obj-aarch64-apple-darwin ]; then
touch obj-aarch64-apple-darwin/CLOBBER
elif [ "$UNAME" = "Windows" ] && [ -d obj-x86_64-pc-mingw32 ]; then
touch obj-x86_64-pc-mingw32/CLOBBER
fi
else
echo
echo "======================================================="
echo "Running clobber."
./mach clobber
fi
./mach build
echo
echo "======================================================="
echo "Packaging"
./mach package
cd ..
if [ "$UNAME" = "Linux" ]; then
if [ "$UNAME_ARCH" = "x86_64" ]; then
echo
echo "======================================================="
echo "Find your archive here"
ls $MOZILLA_DIR/obj-x86_64-pc-linux-gnu/dist/*.tar.bz2
elif [ "$UNAME_ARCH" = "aarch64" ]; then
echo
echo "======================================================="
echo "Find your archive here"
ls $MOZILLA_DIR/obj-aarch64-unknown-linux-gnu/dist/*.tar.bz2
fi
elif [ "$UNAME" = "Darwin" ]; then
echo
echo "======================================================="
echo "Find your disk image here"
ls $MOZILLA_DIR/obj-x86_64-apple-darwin/dist/*.mac.dmg
elif [ "$UNAME" = "Windows" ]; then
echo
echo "======================================================="
echo "Find your disk image here"
ls $MOZILLA_DIR/obj-x86_64-pc-mingw32/dist/install/sea/*.installer.exe
fi