build 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  4. distdir=/var/tmp/dist/[% project %]
  5. mkdir -p /var/tmp/build
  6. mkdir -p [% dest_dir _ '/' _ c('filename') %]
  7. [% IF c("var/windows") %]
  8. # Setting up fxc2
  9. tar -C /var/tmp/dist -xf [% c('input_files_by_name/fxc2') %]
  10. export PATH="/var/tmp/dist/fxc2/bin:$PATH"
  11. # fxc2 requires Wine.
  12. export WINEARCH=[% IF c("var/windows-x86_64") %]win64[% ELSE %]win32[% END %]
  13. export HOME=/var/tmp/home
  14. mkdir -p $HOME
  15. WINEROOT=$HOME/.wine/drive_c
  16. wine wineboot -i
  17. # Setting up stack protector support
  18. tar -C /var/tmp/dist -xf [% c('input_files_by_name/mingw-w64') %]
  19. cp /var/tmp/dist/mingw-w64/gcclibs/{libssp.a,libssp_nonshared.a} /var/tmp/dist/mingw-w64-clang/[% c("arch") %]-w64-mingw32/lib/
  20. [% END -%]
  21. tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
  22. tar -C /var/tmp/dist -xf [% c('input_files_by_name/cbindgen') %]
  23. tar -C /var/tmp/dist -xf [% c('input_files_by_name/nasm') %]
  24. tar -C /var/tmp/dist -xf [% c('input_files_by_name/python') %]
  25. tar -C /var/tmp/dist -xf [% c('input_files_by_name/node') %]
  26. 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"
  27. tar -C /var/tmp/dist -xf [% c('input_files_by_name/clang') %]
  28. export LLVM_CONFIG="/var/tmp/dist/clang/bin/llvm-config"
  29. [% IF c("var/linux") || c("var/android") %]
  30. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
  31. export PATH="/var/tmp/dist/binutils/bin:$PATH"
  32. # Use clang for everything on Linux and Android now if we don't build with
  33. # ASan.
  34. [% IF ! c("var/asan") -%]
  35. export PATH="/var/tmp/dist/clang/bin:$PATH"
  36. [% END -%]
  37. [% END -%]
  38. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  39. [% IF c("var/osx") %]
  40. mkdir -p "$distdir/Tor Browser.app/Contents/MacOS"
  41. [% ELSE %]
  42. mkdir -p $distdir/Browser
  43. [% END %]
  44. cd /var/tmp/build/[% project %]-[% c("version") %]
  45. mv -f $rootdir/[% c('input_files_by_name/mozconfig') %] .mozconfig
  46. [% IF c("var/asan") -%]
  47. mv -f .mozconfig-asan .mozconfig
  48. # Without disabling LSan our build is blowing up:
  49. # https://bugs.torproject.org/10599#comment:52
  50. export ASAN_OPTIONS="detect_leaks=0"
  51. [% END -%]
  52. [% IF c("var/android") %]
  53. gradle_repo=/var/tmp/dist/gradle-dependencies
  54. export GRADLE_MAVEN_REPOSITORIES="file://$gradle_repo"
  55. export GRADLE_FLAGS="--no-daemon --offline"
  56. # Move Gradle Repo to hard-coded location. This location is embedded in the file
  57. # chrome/toolkit/content/global/buildconfig.html so needs to be standard for reproducibility
  58. mv $rootdir/[% c('input_files_by_name/gradle-dependencies') %] $gradle_repo
  59. cp -r $gradle_repo/m2/* $gradle_repo
  60. # Move Android library dependencies so they will be included in the apk during the build
  61. cp $rootdir/[% c('input_files_by_name/topl') %]/* mobile/android/app
  62. cp $rootdir/[% c('input_files_by_name/tor-android-service') %]/* mobile/android/app
  63. # Move emulator to location that firefox build expects
  64. mkdir /var/tmp/dist/android-toolchain/android-sdk-linux/emulator
  65. cp /var/tmp/dist/android-toolchain/android-sdk-linux/tools/emulator /var/tmp/dist/android-toolchain/android-sdk-linux/emulator
  66. # Prepare building the multi-locale .apk including our own strings
  67. mkdir -p /var/tmp/dist/locales
  68. tar -C /var/tmp/dist/locales -xf $rootdir/[% c('input_files_by_name/firefox-locale-bundle') %]
  69. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/tba-translation') %]
  70. [% END %]
  71. eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
  72. if [ -z $MOZ_BUILD_DATE ]
  73. then
  74. echo "MOZ_BUILD_DATE is not set"
  75. exit 1
  76. fi
  77. [% IF c("var/osname") == "linux-armhf" -%]
  78. patch -p1 < $rootdir/1526653.patch
  79. [% END -%]
  80. [% IF c("var/windows") %]
  81. # Make sure widl is not inserting random timestamps, see #21837.
  82. export WIDL_TIME_OVERRIDE="0"
  83. patch -p1 < $rootdir/nsis-uninstall.patch
  84. # Make sure we link without inserting timestamps in general.
  85. export LDFLAGS="-Wl,--no-insert-timestamp"
  86. [% END -%]
  87. [% IF ! c("var/android") %]
  88. # Place a copy of the Tor Launcher sources under browser/extensions
  89. tar -C browser/extensions -xf $rootdir/[% c('input_files_by_name/tor-launcher') %]
  90. [% END -%]
  91. rm -f configure
  92. rm -f js/src/configure
  93. # Android does not support --enable-bundled-fonts option
  94. ./mach configure --with-tor-browser-version=[% c("var/torbrowser_version") %] --with-distribution-id=org.torproject --enable-update-channel=[% c("var/torbrowser_update_channel") %] [% IF ! c("var/android") %]--enable-bundled-fonts[% END -%] --with-branding=[% c("var/branding_directory") %]
  95. ./mach build --verbose
  96. [% IF c("var/android") %]
  97. # Building a multi-locale .apk
  98. [% FOREACH lang = c('var/locales');
  99. SET lang = tmpl(lang);
  100. # mk is unavailable on mobile.
  101. NEXT IF lang == 'mk'; %]
  102. # Copy our torbrowser_strings.dtd at the right place
  103. cp /var/tmp/dist/tba-translation/[% lang %]/torbrowser_strings.dtd /var/tmp/dist/locales/[% lang %]/mobile/android/base/
  104. ./mach build chrome-[% lang %];
  105. [% END %]
  106. # Include localization for all available locales.
  107. # mk is excluded above because Mozilla does not provide mk localization.
  108. # mk is included here because we may have localization for torbutton.
  109. export MOZ_CHROME_MULTILOCALE='[% tmpl(c('var/locales').join(' ')) %]'
  110. ./mach android assemble-app
  111. AB_CD=multi ./mach package
  112. # Copy the result over and return. There is nothing more to do for mobile.
  113. cp obj-*/dist/*unsigned-unaligned.apk [% dest_dir _ '/' _ c('filename') %]/tor-browser-unsigned-unaligned.apk
  114. [% RETURN %]
  115. [% END %]
  116. ./mach build stage-package
  117. [% IF c("var/osx") %]
  118. cp -a obj-macos/dist/firefox/* $distdir
  119. # Remove firefox-bin (we don't use it, see ticket #10126)
  120. rm -f "$distdir/Tor Browser.app/Contents/MacOS/firefox-bin"
  121. # Adjust the Info.plist file
  122. INFO_PLIST="$distdir/Tor Browser.app/Contents/Info.plist"
  123. mv "$INFO_PLIST" tmp.plist
  124. python $rootdir/fix-info-plist.py '[% c("var/torbrowser_version") %]' '[% c("var/copyright_year") %]' < tmp.plist > "$INFO_PLIST"
  125. rm -f tmp.plist
  126. [% END %]
  127. [% IF c("var/linux") %]
  128. cp -a obj-*/dist/firefox/* $distdir/Browser/
  129. # Remove firefox-bin (we don't use it, see ticket #10126)
  130. rm -f $distdir/Browser/firefox-bin
  131. # TODO: There goes FIPS-140.. We could upload these somewhere unique and
  132. # subsequent builds could test to see if they've been uploaded before...
  133. # But let's find out if it actually matters first..
  134. rm -f $distdir/Browser/*.chk
  135. # Replace firefox by a wrapper script (#25485)
  136. mv $distdir/Browser/firefox $distdir/Browser/firefox.real
  137. mv $rootdir/start-firefox $distdir/Browser/firefox
  138. chmod 755 $distdir/Browser/firefox
  139. [% END %]
  140. [% IF c("var/windows") %]
  141. cp -a obj-*/dist/firefox/* $distdir/Browser/
  142. cp -a /var/tmp/dist/fxc2/bin/d3dcompiler_47.dll $distdir/Browser
  143. [% END %]
  144. # Make MAR-based update tools available for use during the bundle phase.
  145. # Note that mar and mbsdiff are standalone tools, compiled for the build
  146. # host's architecture. We also include signmar, certutil, and the libraries
  147. # they require; these utilities and libraries are built for the target
  148. # architecture.
  149. MARTOOLS=$distdir/mar-tools
  150. mkdir -p $MARTOOLS
  151. cp -p config/createprecomplete.py $MARTOOLS/
  152. cp -p tools/update-packaging/*.sh $MARTOOLS/
  153. cp -p obj-*/dist/host/bin/mar $MARTOOLS/
  154. cp -p obj-*/dist/host/bin/mbsdiff $MARTOOLS/
  155. [% IF c("var/linux") || c("var/osx") %]
  156. cp -p obj-*/dist/bin/signmar $MARTOOLS/
  157. cp -p obj-*/dist/bin/certutil $MARTOOLS/
  158. cp -p obj-*/dist/bin/modutil $MARTOOLS/
  159. cp -p obj-*/dist/bin/pk12util $MARTOOLS/
  160. cp -p obj-*/dist/bin/shlibsign $MARTOOLS/
  161. [% IF c("var/linux") %]
  162. NSS_LIBS="libfreeblpriv3.so libmozsqlite3.so libnss3.so libnssckbi.so libnssdbm3.so libnssutil3.so libsmime3.so libsoftokn3.so libssl3.so"
  163. NSPR_LIBS="libnspr4.so libplc4.so libplds4.so"
  164. [% ELSE %]
  165. NSS_LIBS="libfreebl3.dylib libmozglue.dylib libnss3.dylib libnssckbi.dylib libnssdbm3.dylib libsoftokn3.dylib"
  166. # No NSPR_LIBS for macOS
  167. NSPR_LIBS=""
  168. [% END %]
  169. for LIB in $NSS_LIBS $NSPR_LIBS; do
  170. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  171. done
  172. [% END %]
  173. [% IF c("var/windows") %]
  174. cp -p obj-*/dist/bin/signmar.exe $MARTOOLS/
  175. cp -p obj-*/dist/bin/certutil.exe $MARTOOLS/
  176. cp -p obj-*/dist/bin/modutil.exe $MARTOOLS/
  177. cp -p obj-*/dist/bin/pk12util.exe $MARTOOLS/
  178. cp -p obj-*/dist/bin/shlibsign.exe $MARTOOLS/
  179. NSS_LIBS="freebl3.dll mozglue.dll nss3.dll nssckbi.dll nssdbm3.dll softokn3.dll"
  180. for LIB in $NSS_LIBS; do
  181. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  182. done
  183. [% END %]
  184. cd $distdir
  185. [% IF c("var/linux-x86_64") %]
  186. mkdir -p $distdir/Debug/Browser/gtk2
  187. # Strip and generate debuginfo for the firefox binary that we keep, all *.so
  188. # files, the plugin-container, and the updater (see ticket #10126)
  189. for LIB in Browser/*.so Browser/gtk2/*.so Browser/firefox.real Browser/plugin-container Browser/updater
  190. do
  191. objcopy --only-keep-debug $LIB Debug/$LIB
  192. strip $LIB
  193. objcopy --add-gnu-debuglink=./Debug/$LIB $LIB
  194. done
  195. [% END %]
  196. # Re-zipping the omni.ja files is not needed to make them reproductible,
  197. # however if we don't re-zip them, the files become corrupt when we
  198. # update them using 'zip' and firefox will silently fail to load some
  199. # parts.
  200. [% IF c("var/windows") || c("var/linux") %]
  201. [% c("var/rezip", { rezip_file => 'Browser/omni.ja' }) %]
  202. [% c("var/rezip", { rezip_file => 'Browser/browser/omni.ja' }) %]
  203. [% ELSIF c("var/osx") %]
  204. [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/omni.ja"' }) %]
  205. [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/browser/omni.ja"' }) %]
  206. [% END %]
  207. [%
  208. IF c("var/osx");
  209. SET browserdir='"Tor Browser.app/Contents"';
  210. ELSE;
  211. SET browserdir='Browser';
  212. END;
  213. %]
  214. [% IF c("var/linux") %]
  215. /var/tmp/dist/gcc/bin/g++ $rootdir/abicheck.cc -o Browser/abicheck
  216. [% END %]
  217. [% c('tar', {
  218. tar_src => [ browserdir ],
  219. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser.tar.gz',
  220. }) %]
  221. [% IF c("var/linux-x86_64") %]
  222. [% c('tar', {
  223. tar_src => [ 'Debug' ],
  224. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser-debug.tar.xz',
  225. }) %]
  226. [% END %]
  227. [% c('zip', {
  228. zip_src => [ 'mar-tools' ],
  229. zip_args => dest_dir _ '/' _ c('filename') _ '/' _ c('var/martools_filename'),
  230. }) %]