build 11 KB
Newer Older
boklm's avatar
boklm committed
1
#!/bin/bash
2
[% c("var/setarch") -%]
3
[% c("var/set_default_env") -%]
4
5
6
7
[% IF c("var/android") %]
  export GRADLE_MAVEN_REPOSITORIES="file://$rootdir/[% c('input_files_by_name/gradle-dependencies') %]"
[% END -%]

8
[% IF c("var/windows") -%]
9
  [% pc('gcc', 'var/setup', { compiler_tarfile => c('input_files_by_name/gcc') }) %]
10
11
  # We need a link to our GCC, otherwise the system cc gets used which points to
  # /usr/bin/gcc.
12
  ln -s gcc /var/tmp/dist/gcc/bin/cc
13
[% END -%]
boklm's avatar
boklm committed
14
15
16
[% 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
17
mkdir -p [% dest_dir _ '/' _ c('filename') %]
boklm's avatar
boklm committed
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[% IF c("var/windows") -%]
  mingwdir=/var/tmp/dist/mingw-w64
  mkdir -p $mingwdir/helpers

  cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-g++ << 'EOF'
#!/bin/sh
/var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-g++ [% c("var/LDFLAGS") %] [% c("var/CFLAGS") %] "$@"
EOF

  cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-gcc << 'EOF'
#!/bin/sh
/var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-gcc [% c("var/LDFLAGS") %] [% c("var/CFLAGS") %] "$@"
EOF

  cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-ld << 'EOF'
#!/bin/sh
/var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-ld [% c("var/LDFLAGS") %] "$@"
EOF

  chmod +x $mingwdir/helpers/*
  export PATH="$mingwdir/helpers:$PATH"
[% END -%]

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[% IF c("var/windows") %]
  # Unpack fxc2.
  mkdir -p /var/tmp/dist
  tar -C /var/tmp/dist -xf [% c('input_files_by_name/fxc2') %]
  fxcdir=/var/tmp/dist/fxc2/bin
  cp $mingwdir/[% c("arch") %]-w64-mingw32/bin/libwinpthread-1.dll $fxcdir
  export PATH="$fxcdir:$PATH"
  # fxc2 requires Wine.
  [% IF c("var/windows-x86_64") %]
    export WINEARCH=win64
  [% END %]
  export HOME=/var/tmp/home
  mkdir -p $HOME
  WINEROOT=$HOME/.wine/drive_c
  wine wineboot -i
[% END -%]

boklm's avatar
boklm committed
59
[% IF c("var/linux") %]
boklm's avatar
boklm committed
60
61
62
  mkdir -p /var/tmp/dist
  tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
  export PATH="/var/tmp/dist/binutils/bin:$PATH"
boklm's avatar
boklm committed
63
64
[% END -%]

65
[% IF c("var/selfrando") -%]
66
67
68
69
70
71
  tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/selfrando') %]
  # Selfrando wrapper
  export PATH="/var/tmp/dist/selfrando/Tools/TorBrowser/tc-wrapper/:$PATH"
  # We need to avoid the shuffling while building as this breaks compilation
  export SELFRANDO_skip_shuffle=
[% END -%]
72

73
74
75
mkdir -p /var/tmp/dist
tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
export PATH="/var/tmp/dist/rust/bin:$PATH"
76
77

[% IF c("var/linux") %]
78
79
80
81
82
  # Add llvm so stylo can build
  tar -C /var/tmp/dist -xf [% c('input_files_by_name/llvm') %]
  export LLVM_CONFIG="/var/tmp/dist/llvm/bin/llvm-config"
[% END -%]

boklm's avatar
boklm committed
83
84
85
tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz

[% IF c("var/osx") %]
86
  mkdir -p "$distdir/Tor Browser.app/Contents/MacOS"
boklm's avatar
boklm committed
87
[% ELSE %]
boklm's avatar
boklm committed
88
  mkdir -p $distdir/Browser
boklm's avatar
boklm committed
89
90
91
[% END %]

[% IF c("var/linux") %]
92
  mkdir -p $distdir/Debug/Browser/
boklm's avatar
boklm committed
93
94
95
96
[% END %]

cd /var/tmp/build/[% project %]-[% c("version") %]
mv -f $rootdir/[% c('input_files_by_name/mozconfig') %] .mozconfig
boklm's avatar
boklm committed
97
98
99
100
101
102
[% IF c("var/asan") -%]
  mv -f .mozconfig-asan .mozconfig
  # 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
103

104
105
106
107
[% IF c("var/android") %]
  cp $rootdir/[% c('input_files_by_name/orbot') %]/* mobile/android/app
[% END %]

108
109
110
111
112
113
eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] $(cat browser/config/version.txt))
if [ -z $MOZ_BUILD_DATE ]
then
    echo "MOZ_BUILD_DATE is not set"
    exit 1
fi
boklm's avatar
boklm committed
114
115

[% IF c("var/windows") %]
boklm's avatar
boklm committed
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  # FIXME
  # Ideally, using LDFLAGS (and e.g. DLLFLAGS for NSS) would be enough to get
  # all Firefox libraries linked against msvcr100. Alas, this does not hold for
  # NSPR. Without patching it we get a "missing entry points for _strcmpi in
  # msvcr100.dll". Now, this should be fixed in rev>=6179 as the def file there
  # contains a proper patch according to the mingw-w64 developers.
  # However, even with this patch the _strcmpi issue is still popping up,
  # probably due to a bug in our current linking setup. The small patch below
  # is therefore just a workaround which should get fixed but is at least
  # justified as the signature of _strcmpi and _stricmp is the same, see:
  # http://msdn.microsoft.com/en-us/library/k59z8dwe.aspx.
  sed 's/strcmpi/stricmp/' -i nsprpub/pr/src/linking/prlink.c
  export HOST_LDFLAGS=" "
  export LDFLAGS="-specs=/var/tmp/dist/mingw-w64/msvcr100.spec"
  # Our flags don't get passed to NSS. We need to do that manually using an
  # obscure one.
  export DLLFLAGS="-specs=/var/tmp/dist/mingw-w64/msvcr100.spec"
133
134
135

  # Make sure widl is not inserting random timestamps, see #21837.
  export WIDL_TIME_OVERRIDE="0"
boklm's avatar
boklm committed
136
137
138
[% END %]

[% IF c("var/osname") == "linux-i686" -%]
boklm's avatar
boklm committed
139
140
141
  export LDFLAGS=-m32
  export CFLAGS=-m32
  export CC='gcc -m32'
boklm's avatar
boklm committed
142
143
[% END -%]

144
145
[% IF c("var/windows") %]
  patch -p1 < $rootdir/nsis-uninstall.patch
146
147
  patch -p1 < $rootdir/1464084.patch
  patch -p1 < $rootdir/1467041.patch
148
149
[% END -%]

boklm's avatar
boklm committed
150
151
152
rm -f configure
rm -f js/src/configure

153
./mach configure --with-tor-browser-version=[% c("var/torbrowser_version") %] --with-distribution-id=org.torproject --enable-update-channel=[% c("var/torbrowser_update_channel") %] --enable-bundled-fonts
154
./mach build --verbose
155
156
157
158
159
160
161

[% IF c("var/android") %]
  ./mach package
  cp obj-*/dist/*unsigned-unaligned.apk [% dest_dir _ '/' _ c('filename') %]/tor-browser-unsigned-unaligned.apk
  [% RETURN %]
[% END %]

162
./mach build stage-package
boklm's avatar
boklm committed
163
164

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

  # Adjust the Info.plist file
170
171
172
  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
173
  rm -f tmp.plist
boklm's avatar
boklm committed
174
175
176
[% END %]

[% IF c("var/linux") %]
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
[% END %]

190
191
192
[% IF c("var/windows-x86_64") -%]
  mv $rootdir/msvcr100-x86_64.dll $rootdir/msvcr100.dll
[% END -%]
boklm's avatar
boklm committed
193
[% IF c("var/windows") %]
boklm's avatar
boklm committed
194
195
196
  cp -a obj-*/dist/firefox/* $distdir/Browser/
  cp -a $rootdir/msvcr100.dll $distdir/Browser
  cp -a $gcclibs/libssp-0.dll $distdir/Browser
197
  cp -a $fxcdir/d3dcompiler_47.dll $distdir/Browser
boklm's avatar
boklm committed
198
199
200
201
202
203
204
205
206
207
208
209
210
211
[% 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/
[% IF c("var/linux") %]
boklm's avatar
boklm committed
212
  cp -p obj-*/modules/libmar/tool/signmar $MARTOOLS/
213
  cp -p obj-*/security/nss/cmd/certutil/certutil_certutil/certutil $MARTOOLS/
214
215
216
  cp -p obj-*/security/nss/cmd/modutil/modutil_modutil/modutil $MARTOOLS/
  cp -p obj-*/security/nss/cmd/pk12util/pk12util_pk12util/pk12util $MARTOOLS/
  cp -p obj-*/security/nss/cmd/shlibsign/shlibsign_shlibsign/shlibsign $MARTOOLS/
217
  NSS_LIBS="libfreeblpriv3.so libmozsqlite3.so libnss3.so libnssckbi.so libnssdbm3.so libnssutil3.so libsmime3.so libsoftokn3.so libssl3.so"
boklm's avatar
boklm committed
218
219
220
221
  NSPR_LIBS="libnspr4.so libplc4.so libplds4.so"
  for LIB in $NSS_LIBS $NSPR_LIBS; do
      cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  done
boklm's avatar
boklm committed
222
[% END %]
223
224
225
[% IF c("var/osx") %]
  cp -p obj-*/modules/libmar/tool/signmar $MARTOOLS/
  cp -p obj-*/security/nss/cmd/certutil/certutil_certutil/certutil $MARTOOLS/
226
227
228
  cp -p obj-*/security/nss/cmd/modutil/modutil_modutil/modutil $MARTOOLS/
  cp -p obj-*/security/nss/cmd/pk12util/pk12util_pk12util/pk12util $MARTOOLS/
  cp -p obj-*/security/nss/cmd/shlibsign/shlibsign_shlibsign/shlibsign $MARTOOLS/
229
  NSS_LIBS="libfreebl3.dylib libmozglue.dylib libnss3.dylib libnssckbi.dylib libnssdbm3.dylib libsoftokn3.dylib"
230
231
232
233
  for LIB in $NSS_LIBS; do
      cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  done
[% END %]
234
235
236
[% IF c("var/windows") %]
  cp -p obj-*/modules/libmar/tool/signmar.exe $MARTOOLS/
  cp -p obj-*/security/nss/cmd/certutil/certutil_certutil/certutil.exe $MARTOOLS/
237
238
239
  cp -p obj-*/security/nss/cmd/modutil/modutil_modutil/modutil.exe $MARTOOLS/
  cp -p obj-*/security/nss/cmd/pk12util/pk12util_pk12util/pk12util.exe $MARTOOLS/
  cp -p obj-*/security/nss/cmd/shlibsign/shlibsign_shlibsign/shlibsign.exe $MARTOOLS/
240
  NSS_LIBS="freebl3.dll mozglue.dll nss3.dll nssckbi.dll nssdbm3.dll softokn3.dll"
241
242
243
244
245
  for LIB in $NSS_LIBS; do
      cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  done
  cp -a $rootdir/msvcr100.dll $MARTOOLS/
[% END %]
boklm's avatar
boklm committed
246
247
248

cd $distdir

249
[% IF c("var/linux-x86_64") %]
boklm's avatar
boklm committed
250
251
  # Strip and generate debuginfo for the firefox binary that we keep, all *.so
  # files, the plugin-container, and the updater (see ticket #10126)
252
  for LIB in Browser/*.so Browser/firefox.real Browser/plugin-container Browser/updater
boklm's avatar
boklm committed
253
254
255
256
  do
      objcopy --only-keep-debug $LIB Debug/$LIB
      strip $LIB
      objcopy --add-gnu-debuglink=./Debug/$LIB $LIB
257
258
259
260
      [% IF c("var/selfrando") -%]
        # remove RUNPATH added by selfrando (see #22242)
        chrpath -d $LIB
      [% END -%]
boklm's avatar
boklm committed
261
  done
boklm's avatar
boklm committed
262
263
[% END %]

boklm's avatar
boklm committed
264
265
266
267
268
269
270
271
# 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") %]
272
273
  [% 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
274
[% END %]
boklm's avatar
boklm committed
275
276
277

[%
IF c("var/osx");
278
  SET browserdir='"Tor Browser.app/Contents"';
boklm's avatar
boklm committed
279
280
281
282
283
ELSE;
  SET browserdir='Browser';
END;
%]

284
285
286
287
[% IF c("var/linux") %]
  /var/tmp/dist/gcc/bin/g++ $rootdir/abicheck.cc -o Browser/abicheck
[% END %]

boklm's avatar
boklm committed
288
289
290
291
292
[% c('tar', {
        tar_src => [ browserdir ],
        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser.tar.gz',
    }) %]

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

[% c('zip', {
        zip_src => [ 'mar-tools' ],
        zip_args => dest_dir _ '/' _ c('filename') _ '/' _ c('var/martools_filename'),
    }) %]