build 12.4 KB
Newer Older
boklm's avatar
boklm committed
1
#!/bin/bash
2
[% c("var/set_default_env") -%]
boklm's avatar
boklm committed
3
4
5
[% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
distdir=/var/tmp/dist/[% project %]
mkdir -p /var/tmp/build
6
mkdir -p [% dest_dir _ '/' _ c('filename') %]
boklm's avatar
boklm committed
7

8
[% IF c("var/windows") %]
9
  # Setting up fxc2
10
  tar -C /var/tmp/dist -xf [% c('input_files_by_name/fxc2') %]
11
  export PATH="/var/tmp/dist/fxc2/bin:$PATH"
12
13
14
  # Setting up stack protector support
  tar -C /var/tmp/dist -xf [% c('input_files_by_name/mingw-w64') %]
  cp /var/tmp/dist/mingw-w64/gcclibs/{libssp.a,libssp_nonshared.a} /var/tmp/dist/mingw-w64-clang/[% c("arch") %]-w64-mingw32/lib/
15
16
[% END -%]

17
18
19
20
21
22
23
24
25
tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
tar -C /var/tmp/dist -xf [% c('input_files_by_name/cbindgen') %]
tar -C /var/tmp/dist -xf [% c('input_files_by_name/nasm') %]
tar -C /var/tmp/dist -xf [% c('input_files_by_name/python') %]
tar -C /var/tmp/dist -xf [% c('input_files_by_name/node') %]
export PATH="/var/tmp/dist/rust/bin:/var/tmp/dist/cbindgen:/var/tmp/dist/nasm/bin:/var/tmp/dist/python/bin:/var/tmp/dist/node/bin:$PATH"
tar -C /var/tmp/dist -xf [% c('input_files_by_name/clang') %]
export LLVM_CONFIG="/var/tmp/dist/clang/bin/llvm-config"

26
[% IF c("var/linux") || c("var/android") %]
boklm's avatar
boklm committed
27
  tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
28
  export PATH="/var/tmp/dist/binutils/bin:$PATH"
29
30
31
32
33
  # Use clang for everything on Linux and Android now if we don't build with
  # ASan.
  [% IF ! c("var/asan") -%]
    export PATH="/var/tmp/dist/clang/bin:$PATH"
  [% END -%]
boklm's avatar
boklm committed
34
35
[% END -%]

36
37
38
39
40
41
[% IF c("var/rlbox") -%]
  tar -C /var/tmp/dist -xf [% c('input_files_by_name/wasi-sysroot') %]
  # XXX: We need the libclang_rt.builtins-wasm32.a in our clang lib directory.
  # Copy it over.
  # https://searchfox.org/mozilla-central/source/build/build-clang/build-clang.py#890,
  # include it directly in our clang
42
43
44
45
46
47
  rtdir=/var/tmp/dist/clang/lib/clang/[% pc("clang", "version") %]/lib/wasi
  [% IF c("var/osx") -%]
    rtdir=/var/tmp/dist/macosx-toolchain/clang/lib/clang/[% pc("clang", "version") %]/lib/wasi
  [% END-%]
  mkdir -p $rtdir
  cp /var/tmp/dist/wasi-sysroot/lib/clang/9.0.0/lib/wasi/libclang_rt.builtins-wasm32.a $rtdir
48
49
50
51
52
53
  tar -C /var/tmp/dist -xf [% c('input_files_by_name/lucetc') %]
  export PATH="/var/tmp/dist/lucetc/bin:$PATH"
  export WASM_SANDBOXED_LIBRARIES=graphite,ogg
  export WASI_SYSROOT=/var/tmp/dist/wasi-sysroot/share/wasi-sysroot
[% END -%]

boklm's avatar
boklm committed
54
55
56
tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz

[% IF c("var/osx") %]
57
  mkdir -p "$distdir/Tor Browser.app/Contents/MacOS"
boklm's avatar
boklm committed
58
[% ELSE %]
boklm's avatar
boklm committed
59
  mkdir -p $distdir/Browser
boklm's avatar
boklm committed
60
61
62
63
[% END %]

cd /var/tmp/build/[% project %]-[% c("version") %]
mv -f $rootdir/[% c('input_files_by_name/mozconfig') %] .mozconfig
boklm's avatar
boklm committed
64
65
66
67
68
[% IF c("var/asan") -%]
  # Without disabling LSan our build is blowing up:
  # https://bugs.torproject.org/10599#comment:52
  export ASAN_OPTIONS="detect_leaks=0"
[% END -%]
boklm's avatar
boklm committed
69

70
[% IF c("var/android") %]
71
  export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
72
73
  gradle_repo=/var/tmp/dist/gradle-dependencies
  export GRADLE_MAVEN_REPOSITORIES="file://$gradle_repo"
74
  export GRADLE_FLAGS="--no-daemon --offline"
75
76
  # Move Gradle Repo to hard-coded location. This location is embedded in the file
  # chrome/toolkit/content/global/buildconfig.html so needs to be standard for reproducibility
77
  mv $rootdir/[% c('input_files_by_name/gradle-dependencies') %] $gradle_repo
78
  cp -r $gradle_repo/m2/* $gradle_repo
sisbell's avatar
sisbell committed
79
  # Move Android library dependencies so they will be included in the apk during the build
80
81
  cp $rootdir/[% c('input_files_by_name/topl') %]/* mobile/android/app
  cp $rootdir/[% c('input_files_by_name/tor-android-service') %]/* mobile/android/app
82
83
84
  # Move emulator to location that firefox build expects
  mkdir /var/tmp/dist/android-toolchain/android-sdk-linux/emulator
  cp /var/tmp/dist/android-toolchain/android-sdk-linux/tools/emulator /var/tmp/dist/android-toolchain/android-sdk-linux/emulator
85

86
  # Prepare building the multi-locale .apk including our own strings
87
88
  mkdir -p /var/tmp/dist/locales
  tar -C /var/tmp/dist/locales -xf $rootdir/[% c('input_files_by_name/firefox-locale-bundle') %]
89
  tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/tba-translation') %]
90
91
[% END %]

Georg Koppen's avatar
Georg Koppen committed
92
eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
93
94
95
96
97
if [ -z $MOZ_BUILD_DATE ]
then
    echo "MOZ_BUILD_DATE is not set"
    exit 1
fi
boklm's avatar
boklm committed
98
99

[% IF c("var/windows") %]
100
101
  # Make sure widl is not inserting random timestamps, see #21837.
  export WIDL_TIME_OVERRIDE="0"
102
  patch -p1 < $rootdir/nsis-uninstall.patch
103
104
  # Make sure we link without inserting timestamps in general.
  export LDFLAGS="-Wl,--no-insert-timestamp"
105
106
[% END -%]

107
108
109
110
[% IF c("var/namecoin") %]
  patch -p1 < $rootdir/namecoin-etld.patch
[% END -%]

111
112
113
114
115
[% IF ! c("var/android") %]
  # Place a copy of the Tor Launcher sources under browser/extensions
  tar -C browser/extensions -xf $rootdir/[% c('input_files_by_name/tor-launcher') %]
[% END -%]

116
117
118
119
120
121
[% IF c("var/namecoin") %]
  pushd toolkit/torproject/torbutton
  patch -p1 < $rootdir/namecoin-torbutton.patch
  popd
[% END %]

boklm's avatar
boklm committed
122
123
124
125
[% IF c("var/nightly") -%]
  # Add nightly mar signing key (#33403)
  cp $rootdir/nightly-marsigner.der toolkit/mozapps/update/updater/nightly_aurora_level3_primary.der
  cp $rootdir/nightly-marsigner.der toolkit/mozapps/update/updater/nightly_aurora_level3_secondary.der
boklm's avatar
boklm committed
126
127
  # Set update url for nightly (#33402 / #40033)
  sed -i 's|^URL=https://aus1\.torproject\.org/.*|URL=https://nightlies.tbb.torproject.org/nightly-updates/updates/nightly-[% c("var/osname") %]/%CHANNEL%/%BUILD_TARGET%/%VERSION%/%LOCALE%|' build/application.ini.in
boklm's avatar
boklm committed
128
129
[% END -%]

boklm's avatar
boklm committed
130
131
132
rm -f configure
rm -f js/src/configure

133
# Android does not support --enable-bundled-fonts option
134
./mach configure --with-tor-browser-version=[% c("var/torbrowser_version") %] --with-distribution-id=org.torproject --enable-update-channel=[% c("var/channel") %] [% IF ! c("var/android") %]--enable-bundled-fonts[% END -%] --with-branding=[% c("var/branding_directory") %]
135

136
./mach build --verbose
137
138

[% IF c("var/android") %]
139
  # Building a multi-locale .apk
140
141
142
143
  [% FOREACH lang = c('var/locales');
     SET lang = tmpl(lang);
     # mk is unavailable on mobile.
     NEXT IF lang == 'mk'; %]
144
145
    # Copy our torbrowser_strings.dtd at the right place
    cp /var/tmp/dist/tba-translation/[% lang %]/torbrowser_strings.dtd /var/tmp/dist/locales/[% lang %]/mobile/android/base/
146
147
    ./mach build chrome-[% lang %];
  [% END %]
148
149
150
  # Include localization for all available locales.
  # mk is excluded above because Mozilla does not provide mk localization.
  # mk is included here because we may have localization for torbutton.
151
  export MOZ_CHROME_MULTILOCALE='[% tmpl(c('var/locales').join(' ')) %]'
152
  ./mach android assemble-app
153
154
  AB_CD=multi ./mach package
  # Copy the result over and return. There is nothing more to do for mobile.
155
156
157
158
  cp obj-*/dist/*unsigned-unaligned.apk [% dest_dir _ '/' _ c('filename') %]/tor-browser-unsigned-unaligned.apk
  [% RETURN %]
[% END %]

159
./mach build stage-package
boklm's avatar
boklm committed
160
161

[% IF c("var/osx") %]
boklm's avatar
boklm committed
162
163
  cp -a obj-macos/dist/firefox/* $distdir
  # Remove firefox-bin (we don't use it, see ticket #10126)
164
  rm -f "$distdir/Tor Browser.app/Contents/MacOS/firefox-bin"
boklm's avatar
boklm committed
165
166

  # Adjust the Info.plist file
167
168
169
  INFO_PLIST="$distdir/Tor Browser.app/Contents/Info.plist"
  mv "$INFO_PLIST" tmp.plist
  python $rootdir/fix-info-plist.py '[% c("var/torbrowser_version") %]' '[% c("var/copyright_year") %]' < tmp.plist > "$INFO_PLIST"
boklm's avatar
boklm committed
170
  rm -f tmp.plist
boklm's avatar
boklm committed
171
172
173
[% END %]

[% IF c("var/linux") %]
174
  [% IF c("var/linux-x86_64") && !c("var/asan") %]
175
176
    cp obj-*/testing/geckodriver/x86_64-unknown-linux-gnu/release/geckodriver $distdir
  [% END %]
boklm's avatar
boklm committed
177
178
179
180
181
182
183
  cp -a obj-*/dist/firefox/* $distdir/Browser/
  # Remove firefox-bin (we don't use it, see ticket #10126)
  rm -f $distdir/Browser/firefox-bin
  # TODO: There goes FIPS-140.. We could upload these somewhere unique and
  # subsequent builds could test to see if they've been uploaded before...
  # But let's find out if it actually matters first..
  rm -f $distdir/Browser/*.chk
184
185
186
187
  # Replace firefox by a wrapper script (#25485)
  mv $distdir/Browser/firefox $distdir/Browser/firefox.real
  mv $rootdir/start-firefox $distdir/Browser/firefox
  chmod 755 $distdir/Browser/firefox
boklm's avatar
boklm committed
188
189
190
[% END %]

[% IF c("var/windows") %]
boklm's avatar
boklm committed
191
  cp -a obj-*/dist/firefox/* $distdir/Browser/
Georg Koppen's avatar
Georg Koppen committed
192
193
194
195
196
  [% IF c("var/windows-i686") %]
    cp -a /var/tmp/dist/fxc2/bin/d3dcompiler_47_32.dll $distdir/Browser/d3dcompiler_47.dll
  [% ELSE %]
    cp -a /var/tmp/dist/fxc2/bin/d3dcompiler_47.dll $distdir/Browser
  [% END %]
boklm's avatar
boklm committed
197
198
199
200
201
202
203
204
205
206
207
208
209
[% END %]

# Make MAR-based update tools available for use during the bundle phase.
# Note that mar and mbsdiff are standalone tools, compiled for the build
# host's architecture.  We also include signmar, certutil, and the libraries
# they require; these utilities and libraries are built for the target
# architecture.
MARTOOLS=$distdir/mar-tools
mkdir -p $MARTOOLS
cp -p config/createprecomplete.py $MARTOOLS/
cp -p tools/update-packaging/*.sh $MARTOOLS/
cp -p obj-*/dist/host/bin/mar $MARTOOLS/
cp -p obj-*/dist/host/bin/mbsdiff $MARTOOLS/
210
[% IF c("var/linux") || c("var/osx") %]
211
212
213
214
215
  cp -p obj-*/dist/bin/signmar $MARTOOLS/
  cp -p obj-*/dist/bin/certutil $MARTOOLS/
  cp -p obj-*/dist/bin/modutil $MARTOOLS/
  cp -p obj-*/dist/bin/pk12util $MARTOOLS/
  cp -p obj-*/dist/bin/shlibsign $MARTOOLS/
216
  [% IF c("var/linux") %]
217
    NSS_LIBS="libfreeblpriv3.so libmozsqlite3.so libnss3.so libnssckbi.so libnssutil3.so libsmime3.so libsoftokn3.so libssl3.so"
218
219
    NSPR_LIBS="libnspr4.so libplc4.so libplds4.so"
  [% ELSE %]
220
    NSS_LIBS="libfreebl3.dylib libmozglue.dylib libnss3.dylib libnssckbi.dylib libsoftokn3.dylib"
221
222
223
    # No NSPR_LIBS for macOS
    NSPR_LIBS=""
  [% END %]
boklm's avatar
boklm committed
224
  for LIB in $NSS_LIBS $NSPR_LIBS; do
225
    cp -p obj-*/dist/bin/$LIB $MARTOOLS/
226
227
  done
[% END %]
228
[% IF c("var/windows") %]
229
230
231
232
233
  cp -p obj-*/dist/bin/signmar.exe $MARTOOLS/
  cp -p obj-*/dist/bin/certutil.exe $MARTOOLS/
  cp -p obj-*/dist/bin/modutil.exe $MARTOOLS/
  cp -p obj-*/dist/bin/pk12util.exe $MARTOOLS/
  cp -p obj-*/dist/bin/shlibsign.exe $MARTOOLS/
234
  NSS_LIBS="freebl3.dll mozglue.dll nss3.dll nssckbi.dll softokn3.dll"
235
236
237
238
  for LIB in $NSS_LIBS; do
      cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  done
[% END %]
boklm's avatar
boklm committed
239
240
241

cd $distdir

242
[% IF c("var/linux-x86_64") %]
243
244
245
246
  [% IF !c("var/asan") %]
    # No need for an unstripped geckodriver
    strip geckodriver
  [% END %]
247
  mkdir -p $distdir/Debug/Browser/gtk2
boklm's avatar
boklm committed
248
249
  # Strip and generate debuginfo for the firefox binary that we keep, all *.so
  # files, the plugin-container, and the updater (see ticket #10126)
250
  for LIB in Browser/*.so Browser/gtk2/*.so Browser/firefox.real Browser/plugin-container Browser/updater
boklm's avatar
boklm committed
251
252
253
254
255
  do
      objcopy --only-keep-debug $LIB Debug/$LIB
      strip $LIB
      objcopy --add-gnu-debuglink=./Debug/$LIB $LIB
  done
boklm's avatar
boklm committed
256
257
[% END %]

boklm's avatar
boklm committed
258
259
260
261
262
263
264
265
# Re-zipping the omni.ja files is not needed to make them reproductible,
# however if we don't re-zip them, the files become corrupt when we
# update them using 'zip' and firefox will silently fail to load some
# parts.
[% IF c("var/windows") || c("var/linux") %]
  [% c("var/rezip", { rezip_file => 'Browser/omni.ja' }) %]
  [% c("var/rezip", { rezip_file => 'Browser/browser/omni.ja' }) %]
[% ELSIF c("var/osx") %]
266
267
  [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/omni.ja"' }) %]
  [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/browser/omni.ja"' }) %]
boklm's avatar
boklm committed
268
[% END %]
boklm's avatar
boklm committed
269
270
271

[%
IF c("var/osx");
272
  SET browserdir='"Tor Browser.app/Contents"';
boklm's avatar
boklm committed
273
274
275
276
277
ELSE;
  SET browserdir='Browser';
END;
%]

278
[% IF c("var/linux") %]
279
  /var/tmp/dist/gcc/bin/g++ $rootdir/abicheck.cc -o Browser/abicheck -std=c++17
280
281
[% END %]

boklm's avatar
boklm committed
282
283
284
285
286
[% c('tar', {
        tar_src => [ browserdir ],
        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser.tar.gz',
    }) %]

287
[% IF c("var/linux-x86_64") %]
boklm's avatar
boklm committed
288
289
[% c('tar', {
        tar_src => [ 'Debug' ],
290
        tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser-debug.tar.xz',
boklm's avatar
boklm committed
291
    }) %]
292
293
294
295
296
297
  [% IF !c("var/asan") %]
    [% c('tar', {
            tar_src => [ 'geckodriver' ],
            tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/geckodriver-linux64.tar.xz',
        }) %]
  [% END %]
boklm's avatar
boklm committed
298
299
300
301
302
303
[% END %]

[% c('zip', {
        zip_src => [ 'mar-tools' ],
        zip_args => dest_dir _ '/' _ c('filename') _ '/' _ c('var/martools_filename'),
    }) %]
304
305
306
307
308
309
310
311
312

[% IF c("var/build_infos_json") -%]
  cat > "[% dest_dir _ '/' _ c('filename') _ '/build-infos.json' %]" << EOF_BUILDINFOS
  {
      "firefox_platform_version" : "[% c("var/firefox_platform_version") %]",
      "firefox_buildid" : "$MOZ_BUILD_DATE"
  }
EOF_BUILDINFOS
[% END -%]