build 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. #!/bin/bash
  2. [% c("var/setarch") -%]
  3. [% c("var/set_default_env") -%]
  4. [% IF c("var/windows") -%]
  5. [% pc('gcc', 'var/setup', { compiler_tarfile => c('input_files_by_name/gcc') }) %]
  6. # We need a link to our GCC, otherwise the system cc gets used which points to
  7. # /usr/bin/gcc.
  8. ln -s gcc /var/tmp/dist/gcc/bin/cc
  9. [% END -%]
  10. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  11. [% IF c("var/linux-cross") -%]
  12. [% pc('gcc', 'var/setup', {
  13. compiler_tarfile => c('input_files_by_name/' _ 'gcc-host'),
  14. target => [ c('var/channel'), 'torbrowser-linux-x86_64' ]
  15. }) %]
  16. # Work around missing libraries. Maybe there's a better way?
  17. crossdepsdir=/var/tmp/dist/cross-deps-chroot
  18. mkdir -p $crossdepsdir
  19. pushd $crossdepsdir
  20. apt-get --option "APT::Architecture=[% c("var/arch_debian") %]" download $(apt-rdepends libgtk2.0-dev:[% c("var/arch_debian") %] libgtk-3-dev:[% c("var/arch_debian") %] libdbus-glib-1-dev:[% c("var/arch_debian") %] libxt-dev:[% c("var/arch_debian") %] libpulse-dev:[% c("var/arch_debian") %] libgconf2-dev:[% c("var/arch_debian") %] libx11-xcb-dev:[% c("var/arch_debian") %] libmpc2:[% c("var/arch_debian") %]|grep -v "^ "|grep -v "debconf-2.0"|grep -v "gsettings-backend"|grep -v "libc-dev"|grep -v "libz-dev")
  21. for PACKAGE in ./*.deb; do
  22. dpkg -x $PACKAGE ./
  23. done
  24. popd
  25. cp --archive --no-clobber $crossdepsdir/usr/include/* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/include/
  26. cp --archive --no-clobber $crossdepsdir/usr/lib/[% c("var/crosstarget") %]/lib*.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  27. cp --archive --no-clobber $crossdepsdir/lib/[% c("var/crosstarget") %]/libuuid.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  28. cp --archive --no-clobber $crossdepsdir/lib/[% c("var/crosstarget") %]/libselinux.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  29. cp --archive --no-clobber $crossdepsdir/lib/[% c("var/crosstarget") %]/ld-linux.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  30. # Workaround for: /usr/bin/ld.gold.real: error: cannot open /var/tmp/dist/gcc-cross/lib/gcc/[% c("var/crosstarget") %]/6.4.0/../../../../[% c("var/crosstarget") %]/lib/libglib-2.0.so: No such file or directory
  31. cp --archive --no-clobber $crossdepsdir/lib/[% c("var/crosstarget") %]/libglib*.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  32. cp --archive $crossdepsdir/lib/[% c("var/crosstarget") %]/libglib-2.0.so.0 /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/libglib-2.0.so
  33. cp --archive --no-clobber $crossdepsdir/lib/[% c("var/crosstarget") %]/libdbus*.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  34. cp --archive $crossdepsdir/lib/[% c("var/crosstarget") %]/libdbus-1.so.3 /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/libdbus-1.so
  35. cp --archive --no-clobber $crossdepsdir/lib/[% c("var/crosstarget") %]/libz*.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  36. cp --archive $crossdepsdir/lib/[% c("var/crosstarget") %]/libz.so.1 /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/libz.so
  37. cp --archive --no-clobber $crossdepsdir/lib/[% c("var/crosstarget") %]/libpng12*.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  38. cp --archive $crossdepsdir/lib/[% c("var/crosstarget") %]/libpng12.so.0 /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/libpng12.so
  39. cp --archive --no-clobber $crossdepsdir/lib/[% c("var/crosstarget") %]/libpcre.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  40. cp --archive $crossdepsdir/lib/[% c("var/crosstarget") %]/libpcre.so.3 /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/libpcre.so
  41. cp --archive --no-clobber $crossdepsdir/lib/[% c("var/crosstarget") %]/libexpat.so* /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/
  42. cp --archive $crossdepsdir/lib/[% c("var/crosstarget") %]/libexpat.so.1 /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/libexpat.so
  43. [% END -%]
  44. distdir=/var/tmp/dist/[% project %]
  45. mkdir -p /var/tmp/build
  46. mkdir -p [% dest_dir _ '/' _ c('filename') %]
  47. [% IF c("var/windows") -%]
  48. mingwdir=/var/tmp/dist/mingw-w64
  49. mkdir -p $mingwdir/helpers
  50. cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-g++ << 'EOF'
  51. #!/bin/sh
  52. /var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-g++ [% c("var/LDFLAGS") %] [% c("var/CFLAGS") %] "$@"
  53. EOF
  54. cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-gcc << 'EOF'
  55. #!/bin/sh
  56. /var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-gcc [% c("var/LDFLAGS") %] [% c("var/CFLAGS") %] "$@"
  57. EOF
  58. cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-ld << 'EOF'
  59. #!/bin/sh
  60. /var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-ld [% c("var/LDFLAGS") %] "$@"
  61. EOF
  62. chmod +x $mingwdir/helpers/*
  63. export PATH="$mingwdir/helpers:$PATH"
  64. [% END -%]
  65. [% IF c("var/windows") %]
  66. # Unpack fxc2.
  67. mkdir -p /var/tmp/dist
  68. tar -C /var/tmp/dist -xf [% c('input_files_by_name/fxc2') %]
  69. fxcdir=/var/tmp/dist/fxc2/bin
  70. cp $mingwdir/[% c("arch") %]-w64-mingw32/bin/libwinpthread-1.dll $fxcdir
  71. export PATH="$fxcdir:$PATH"
  72. # fxc2 requires Wine.
  73. [% IF c("var/windows-x86_64") %]
  74. export WINEARCH=win64
  75. [% END %]
  76. export HOME=/var/tmp/home
  77. mkdir -p $HOME
  78. WINEROOT=$HOME/.wine/drive_c
  79. wine wineboot -i
  80. [% END -%]
  81. [% IF c("var/linux") %]
  82. mkdir -p /var/tmp/dist
  83. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
  84. export PATH="/var/tmp/dist/binutils/bin:$PATH"
  85. [% END -%]
  86. mkdir -p /var/tmp/dist
  87. tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
  88. export PATH="/var/tmp/dist/rust/bin:$PATH"
  89. [% IF c("var/linux") %]
  90. # Add llvm so stylo can build
  91. tar -C /var/tmp/dist -xf [% c('input_files_by_name/llvm') %]
  92. export LLVM_CONFIG="/var/tmp/dist/llvm/bin/llvm-config"
  93. [% END -%]
  94. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  95. [% IF c("var/osx") %]
  96. mkdir -p "$distdir/Tor Browser.app/Contents/MacOS"
  97. [% ELSE %]
  98. mkdir -p $distdir/Browser
  99. [% END %]
  100. cd /var/tmp/build/[% project %]-[% c("version") %]
  101. mv -f $rootdir/[% c('input_files_by_name/mozconfig') %] .mozconfig
  102. [% IF c("var/asan") -%]
  103. mv -f .mozconfig-asan .mozconfig
  104. # Without disabling LSan our build is blowing up:
  105. # https://bugs.torproject.org/10599#comment:52
  106. export ASAN_OPTIONS="detect_leaks=0"
  107. [% END -%]
  108. [% IF c("var/android") %]
  109. gradle_repo=/var/tmp/dist/gradle-dependencies
  110. export GRADLE_MAVEN_REPOSITORIES="file://$gradle_repo"
  111. # Move Gradle Repo to hard-coded location. This location is embedded in the file
  112. # chrome/toolkit/content/global/buildconfig.html so needs to be standard for reproducibility
  113. mv $rootdir/[% c('input_files_by_name/gradle-dependencies') %] $gradle_repo
  114. cp -r $gradle_repo/plugins-release/* $gradle_repo
  115. cp -r $gradle_repo/maven2/* $gradle_repo
  116. # Move Android library dependencies so they will be included in the apk during the build
  117. cp $rootdir/[% c('input_files_by_name/topl') %]/* mobile/android/app
  118. cp $rootdir/[% c('input_files_by_name/tor-android-service') %]/* mobile/android/app
  119. # Apply patches
  120. patch -p1 < $rootdir/android-dependencies.patch
  121. # Prepare building the multi-locale .apk including our own strings
  122. mkdir -p /var/tmp/dist/locales
  123. tar -C /var/tmp/dist/locales -xf $rootdir/[% c('input_files_by_name/firefox-locale-bundle') %]
  124. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/tba-translation') %]
  125. [% END %]
  126. eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
  127. if [ -z $MOZ_BUILD_DATE ]
  128. then
  129. echo "MOZ_BUILD_DATE is not set"
  130. exit 1
  131. fi
  132. [% IF c("var/windows") %]
  133. # FIXME
  134. # Ideally, using LDFLAGS (and e.g. DLLFLAGS for NSS) would be enough to get
  135. # all Firefox libraries linked against msvcr100. Alas, this does not hold for
  136. # NSPR. Without patching it we get a "missing entry points for _strcmpi in
  137. # msvcr100.dll". Now, this should be fixed in rev>=6179 as the def file there
  138. # contains a proper patch according to the mingw-w64 developers.
  139. # However, even with this patch the _strcmpi issue is still popping up,
  140. # probably due to a bug in our current linking setup. The small patch below
  141. # is therefore just a workaround which should get fixed but is at least
  142. # justified as the signature of _strcmpi and _stricmp is the same, see:
  143. # http://msdn.microsoft.com/en-us/library/k59z8dwe.aspx.
  144. sed 's/strcmpi/stricmp/' -i nsprpub/pr/src/linking/prlink.c
  145. export HOST_LDFLAGS=" "
  146. export LDFLAGS="-specs=/var/tmp/dist/mingw-w64/msvcr100.spec"
  147. # Our flags don't get passed to NSS. We need to do that manually using an
  148. # obscure one.
  149. export DLLFLAGS="-specs=/var/tmp/dist/mingw-w64/msvcr100.spec"
  150. # Make sure widl is not inserting random timestamps, see #21837.
  151. export WIDL_TIME_OVERRIDE="0"
  152. [% END %]
  153. [% IF c("var/osname") == "linux-i686" -%]
  154. export LDFLAGS=-m32
  155. export CFLAGS=-m32
  156. export CC='gcc -m32'
  157. [% END -%]
  158. [% IF c("var/windows") %]
  159. patch -p1 < $rootdir/nsis-uninstall.patch
  160. [% END -%]
  161. # Backporting a sec-high bugfix to ESR 60, but making sure it is only applied to
  162. # mobile, as desktop ESR has not seen any testing with this mobile-related patch
  163. [% IF c("var/android") %]
  164. patch -p1 < $rootdir/1527534.patch
  165. [% END -%]
  166. [% IF ! c("var/android") %]
  167. # Place a copy of the Tor Launcher sources under browser/extensions
  168. tar -C browser/extensions -xf $rootdir/[% c('input_files_by_name/tor-launcher') %]
  169. [% END -%]
  170. rm -f configure
  171. rm -f js/src/configure
  172. ./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 --with-branding=[% c("var/branding_directory") %]
  173. ./mach build --verbose
  174. [% IF c("var/android") %]
  175. # Building a multi-locale .apk
  176. [% FOREACH lang = c('var/locales');
  177. SET lang = tmpl(lang);
  178. # mk is unavailable on mobile.
  179. NEXT IF lang == 'mk'; %]
  180. # Copy our torbrowser_strings.dtd at the right place
  181. cp /var/tmp/dist/tba-translation/[% lang %]/torbrowser_strings.dtd /var/tmp/dist/locales/[% lang %]/mobile/android/base/
  182. ./mach build chrome-[% lang %];
  183. [% END %]
  184. export MOZ_CHROME_MULTILOCALE='[% tmpl(c('var/locales').join(' ')) %]'
  185. AB_CD=multi ./mach package
  186. # Copy the result over and return. There is nothing more to do for mobile.
  187. cp obj-*/dist/*unsigned-unaligned.apk [% dest_dir _ '/' _ c('filename') %]/tor-browser-unsigned-unaligned.apk
  188. [% RETURN %]
  189. [% END %]
  190. ./mach build stage-package
  191. [% IF c("var/osx") %]
  192. cp -a obj-macos/dist/firefox/* $distdir
  193. # Remove firefox-bin (we don't use it, see ticket #10126)
  194. rm -f "$distdir/Tor Browser.app/Contents/MacOS/firefox-bin"
  195. # Adjust the Info.plist file
  196. INFO_PLIST="$distdir/Tor Browser.app/Contents/Info.plist"
  197. mv "$INFO_PLIST" tmp.plist
  198. python $rootdir/fix-info-plist.py '[% c("var/torbrowser_version") %]' '[% c("var/copyright_year") %]' < tmp.plist > "$INFO_PLIST"
  199. rm -f tmp.plist
  200. [% END %]
  201. [% IF c("var/linux") %]
  202. cp -a obj-*/dist/firefox/* $distdir/Browser/
  203. # Remove firefox-bin (we don't use it, see ticket #10126)
  204. rm -f $distdir/Browser/firefox-bin
  205. # TODO: There goes FIPS-140.. We could upload these somewhere unique and
  206. # subsequent builds could test to see if they've been uploaded before...
  207. # But let's find out if it actually matters first..
  208. rm -f $distdir/Browser/*.chk
  209. # Replace firefox by a wrapper script (#25485)
  210. mv $distdir/Browser/firefox $distdir/Browser/firefox.real
  211. mv $rootdir/start-firefox $distdir/Browser/firefox
  212. chmod 755 $distdir/Browser/firefox
  213. [% END %]
  214. [% IF c("var/windows-x86_64") -%]
  215. mv $rootdir/msvcr100-x86_64.dll $rootdir/msvcr100.dll
  216. [% END -%]
  217. [% IF c("var/windows") %]
  218. cp -a obj-*/dist/firefox/* $distdir/Browser/
  219. cp -a $rootdir/msvcr100.dll $distdir/Browser
  220. cp -a $gcclibs/libssp-0.dll $distdir/Browser
  221. cp -a $fxcdir/d3dcompiler_47.dll $distdir/Browser
  222. [% END %]
  223. [% IF c("var/linux-cross") -%]
  224. cp -a /var/tmp/dist/gcc-cross/[% c("var/crosstarget") %]/lib/libssp.so* $distdir/Browser
  225. [% END %]
  226. # Make MAR-based update tools available for use during the bundle phase.
  227. # Note that mar and mbsdiff are standalone tools, compiled for the build
  228. # host's architecture. We also include signmar, certutil, and the libraries
  229. # they require; these utilities and libraries are built for the target
  230. # architecture.
  231. MARTOOLS=$distdir/mar-tools
  232. mkdir -p $MARTOOLS
  233. cp -p config/createprecomplete.py $MARTOOLS/
  234. cp -p tools/update-packaging/*.sh $MARTOOLS/
  235. cp -p obj-*/dist/host/bin/mar $MARTOOLS/
  236. cp -p obj-*/dist/host/bin/mbsdiff $MARTOOLS/
  237. [% IF c("var/linux") %]
  238. cp -p obj-*/modules/libmar/tool/signmar $MARTOOLS/
  239. cp -p obj-*/security/nss/cmd/certutil/certutil_certutil/certutil $MARTOOLS/
  240. cp -p obj-*/security/nss/cmd/modutil/modutil_modutil/modutil $MARTOOLS/
  241. cp -p obj-*/security/nss/cmd/pk12util/pk12util_pk12util/pk12util $MARTOOLS/
  242. cp -p obj-*/security/nss/cmd/shlibsign/shlibsign_shlibsign/shlibsign $MARTOOLS/
  243. NSS_LIBS="libfreeblpriv3.so libmozsqlite3.so libnss3.so libnssckbi.so libnssdbm3.so libnssutil3.so libsmime3.so libsoftokn3.so libssl3.so"
  244. NSPR_LIBS="libnspr4.so libplc4.so libplds4.so"
  245. for LIB in $NSS_LIBS $NSPR_LIBS; do
  246. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  247. done
  248. [% END %]
  249. [% IF c("var/osx") %]
  250. cp -p obj-*/modules/libmar/tool/signmar $MARTOOLS/
  251. cp -p obj-*/security/nss/cmd/certutil/certutil_certutil/certutil $MARTOOLS/
  252. cp -p obj-*/security/nss/cmd/modutil/modutil_modutil/modutil $MARTOOLS/
  253. cp -p obj-*/security/nss/cmd/pk12util/pk12util_pk12util/pk12util $MARTOOLS/
  254. cp -p obj-*/security/nss/cmd/shlibsign/shlibsign_shlibsign/shlibsign $MARTOOLS/
  255. NSS_LIBS="libfreebl3.dylib libmozglue.dylib libnss3.dylib libnssckbi.dylib libnssdbm3.dylib libsoftokn3.dylib"
  256. for LIB in $NSS_LIBS; do
  257. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  258. done
  259. [% END %]
  260. [% IF c("var/windows") %]
  261. cp -p obj-*/modules/libmar/tool/signmar.exe $MARTOOLS/
  262. cp -p obj-*/security/nss/cmd/certutil/certutil_certutil/certutil.exe $MARTOOLS/
  263. cp -p obj-*/security/nss/cmd/modutil/modutil_modutil/modutil.exe $MARTOOLS/
  264. cp -p obj-*/security/nss/cmd/pk12util/pk12util_pk12util/pk12util.exe $MARTOOLS/
  265. cp -p obj-*/security/nss/cmd/shlibsign/shlibsign_shlibsign/shlibsign.exe $MARTOOLS/
  266. NSS_LIBS="freebl3.dll mozglue.dll nss3.dll nssckbi.dll nssdbm3.dll softokn3.dll"
  267. for LIB in $NSS_LIBS; do
  268. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  269. done
  270. cp -a $rootdir/msvcr100.dll $MARTOOLS/
  271. [% END %]
  272. cd $distdir
  273. [% IF c("var/linux") %]
  274. mkdir -p $distdir/Debug/Browser/gtk2
  275. [% IF c("var/linux-cross") %]
  276. TARGET_OBJCOPY=[% c("var/crosstarget") %]-objcopy
  277. TARGET_STRIP=[% c("var/crosstarget") %]-strip
  278. [% ELSE %]
  279. TARGET_OBJCOPY=objcopy
  280. TARGET_STRIP=strip
  281. [% END %]
  282. # Strip and generate debuginfo for the firefox binary that we keep, all *.so
  283. # files, the plugin-container, and the updater (see ticket #10126)
  284. for LIB in Browser/*.so Browser/gtk2/*.so Browser/firefox.real Browser/plugin-container Browser/updater
  285. do
  286. $TARGET_OBJCOPY --only-keep-debug $LIB Debug/$LIB
  287. $TARGET_STRIP $LIB
  288. $TARGET_OBJCOPY --add-gnu-debuglink=./Debug/$LIB $LIB
  289. done
  290. [% END %]
  291. # Re-zipping the omni.ja files is not needed to make them reproductible,
  292. # however if we don't re-zip them, the files become corrupt when we
  293. # update them using 'zip' and firefox will silently fail to load some
  294. # parts.
  295. [% IF c("var/windows") || c("var/linux") %]
  296. [% c("var/rezip", { rezip_file => 'Browser/omni.ja' }) %]
  297. [% c("var/rezip", { rezip_file => 'Browser/browser/omni.ja' }) %]
  298. [% ELSIF c("var/osx") %]
  299. [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/omni.ja"' }) %]
  300. [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/browser/omni.ja"' }) %]
  301. [% END %]
  302. [%
  303. IF c("var/osx");
  304. SET browserdir='"Tor Browser.app/Contents"';
  305. ELSE;
  306. SET browserdir='Browser';
  307. END;
  308. %]
  309. [% IF c("var/linux") %]
  310. /var/tmp/dist/gcc/bin/g++ $rootdir/abicheck.cc -o Browser/abicheck
  311. [% END %]
  312. [% c('tar', {
  313. tar_src => [ browserdir ],
  314. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser.tar.gz',
  315. }) %]
  316. [% IF c("var/linux") %]
  317. [% c('tar', {
  318. tar_src => [ 'Debug' ],
  319. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser-debug.tar.xz',
  320. }) %]
  321. [% END %]
  322. [% c('zip', {
  323. zip_src => [ 'mar-tools' ],
  324. zip_args => dest_dir _ '/' _ c('filename') _ '/' _ c('var/martools_filename'),
  325. }) %]