build 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. # Setting up stack protector support
  12. tar -C /var/tmp/dist -xf [% c('input_files_by_name/mingw-w64') %]
  13. cp /var/tmp/dist/mingw-w64/gcclibs/{libssp.a,libssp_nonshared.a} /var/tmp/dist/mingw-w64-clang/[% c("arch") %]-w64-mingw32/lib/
  14. [% END -%]
  15. tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
  16. tar -C /var/tmp/dist -xf [% c('input_files_by_name/cbindgen') %]
  17. tar -C /var/tmp/dist -xf [% c('input_files_by_name/nasm') %]
  18. tar -C /var/tmp/dist -xf [% c('input_files_by_name/python') %]
  19. tar -C /var/tmp/dist -xf [% c('input_files_by_name/node') %]
  20. 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"
  21. tar -C /var/tmp/dist -xf [% c('input_files_by_name/clang') %]
  22. export LLVM_CONFIG="/var/tmp/dist/clang/bin/llvm-config"
  23. [% IF c("var/linux") %]
  24. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
  25. export PATH="/var/tmp/dist/binutils/bin:$PATH"
  26. # Use clang for everything on Linux now if we don't build with ASan.
  27. [% IF ! c("var/asan") -%]
  28. export PATH="/var/tmp/dist/clang/bin:$PATH"
  29. [% END -%]
  30. [% IF c("var/linux-i686") %]
  31. # Exporting `PKG_CONFIG_PATH` in the mozconfig file is causing build
  32. # breakage in Rust code. It seems that environment variable is not passed
  33. # down properly in that case. Thus, we set it here in the build script.
  34. export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/lib/i386-linux-gnu/pkgconfig"
  35. [% END -%]
  36. [% END -%]
  37. [% IF c("var/rlbox") -%]
  38. tar -C /var/tmp/dist -xf [% c('input_files_by_name/wasi-sysroot') %]
  39. # XXX: We need the libclang_rt.builtins-wasm32.a in our clang lib directory.
  40. # Copy it over.
  41. # https://searchfox.org/mozilla-central/source/build/build-clang/build-clang.py#890,
  42. # include it directly in our clang
  43. rtdir=/var/tmp/dist/clang/lib/clang/[% pc("clang", "version") %]/lib/wasi
  44. [% IF c("var/osx") -%]
  45. rtdir=/var/tmp/dist/macosx-toolchain/clang/lib/clang/[% pc("clang", "version") %]/lib/wasi
  46. [% END-%]
  47. mkdir -p $rtdir
  48. cp /var/tmp/dist/wasi-sysroot/lib/clang/9.0.0/lib/wasi/libclang_rt.builtins-wasm32.a $rtdir
  49. tar -C /var/tmp/dist -xf [% c('input_files_by_name/lucetc') %]
  50. export PATH="/var/tmp/dist/lucetc/bin:$PATH"
  51. export WASM_SANDBOXED_LIBRARIES=graphite,ogg
  52. export WASI_SYSROOT=/var/tmp/dist/wasi-sysroot/share/wasi-sysroot
  53. [% END -%]
  54. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  55. [% IF c("var/osx") %]
  56. mkdir -p "$distdir/Tor Browser.app/Contents/MacOS"
  57. [% ELSE %]
  58. mkdir -p $distdir/Browser
  59. [% END %]
  60. cd /var/tmp/build/[% project %]-[% c("version") %]
  61. mv -f $rootdir/[% c('input_files_by_name/mozconfig') %] .mozconfig
  62. [% IF c("var/asan") -%]
  63. # Without disabling LSan our build is blowing up:
  64. # https://bugs.torproject.org/10599#comment:52
  65. export ASAN_OPTIONS="detect_leaks=0"
  66. [% END -%]
  67. eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
  68. if [ -z $MOZ_BUILD_DATE ]
  69. then
  70. echo "MOZ_BUILD_DATE is not set"
  71. exit 1
  72. fi
  73. [% IF c("var/osname") == "linux-armhf" -%]
  74. patch -p1 < $rootdir/1526653.patch
  75. [% END -%]
  76. [% IF c("var/windows") %]
  77. # Make sure widl is not inserting random timestamps, see #21837.
  78. export WIDL_TIME_OVERRIDE="0"
  79. patch -p1 < $rootdir/nsis-uninstall.patch
  80. # mingw-w64 does not support SEH on 32bit systems. Be explicit about that.
  81. export LDFLAGS="[% c('var/flag_noSEH') %]"
  82. [% END -%]
  83. [% IF c("var/namecoin") %]
  84. patch -p1 < $rootdir/namecoin-etld.patch
  85. [% END -%]
  86. # Place a copy of the Tor Launcher sources under browser/extensions
  87. tar -C browser/extensions -xf $rootdir/[% c('input_files_by_name/tor-launcher') %]
  88. [% IF c("var/namecoin") %]
  89. pushd toolkit/torproject/torbutton
  90. patch -p1 < $rootdir/namecoin-torbutton.patch
  91. popd
  92. [% END %]
  93. [% IF c("var/nightly") -%]
  94. # Set update url for nightly (#33402 / #40033)
  95. 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
  96. [% END -%]
  97. rm -f configure
  98. rm -f js/src/configure
  99. # Android does not support --enable-bundled-fonts option
  100. ./mach configure --with-tor-browser-version=[% c("var/torbrowser_version") %] --with-distribution-id=org.torproject --enable-update-channel=[% c("var/channel") %] --enable-bundled-fonts --with-branding=[% c("var/branding_directory") %]
  101. ./mach build --verbose
  102. ./mach build stage-package
  103. [% IF c("var/osx") %]
  104. cp -a obj-macos/dist/firefox/* $distdir
  105. # Remove firefox-bin (we don't use it, see ticket #10126)
  106. rm -f "$distdir/Tor Browser.app/Contents/MacOS/firefox-bin"
  107. # Adjust the Info.plist file
  108. INFO_PLIST="$distdir/Tor Browser.app/Contents/Info.plist"
  109. mv "$INFO_PLIST" tmp.plist
  110. python $rootdir/fix-info-plist.py '[% c("var/torbrowser_version") %]' '[% c("var/copyright_year") %]' < tmp.plist > "$INFO_PLIST"
  111. rm -f tmp.plist
  112. [% END %]
  113. [% IF c("var/linux") %]
  114. [% IF c("var/linux-x86_64") && !c("var/asan") %]
  115. cp obj-*/testing/geckodriver/x86_64-unknown-linux-gnu/release/geckodriver $distdir
  116. [% END %]
  117. cp -a obj-*/dist/firefox/* $distdir/Browser/
  118. # Remove firefox-bin (we don't use it, see ticket #10126)
  119. rm -f $distdir/Browser/firefox-bin
  120. # TODO: There goes FIPS-140.. We could upload these somewhere unique and
  121. # subsequent builds could test to see if they've been uploaded before...
  122. # But let's find out if it actually matters first..
  123. rm -f $distdir/Browser/*.chk
  124. # Replace firefox by a wrapper script (#25485)
  125. mv $distdir/Browser/firefox $distdir/Browser/firefox.real
  126. mv $rootdir/start-firefox $distdir/Browser/firefox
  127. chmod 755 $distdir/Browser/firefox
  128. [% END %]
  129. [% IF c("var/windows") %]
  130. cp -a obj-*/dist/firefox/* $distdir/Browser/
  131. [% IF c("var/windows-i686") %]
  132. cp -a /var/tmp/dist/fxc2/bin/d3dcompiler_47_32.dll $distdir/Browser/d3dcompiler_47.dll
  133. [% ELSE %]
  134. cp -a /var/tmp/dist/fxc2/bin/d3dcompiler_47.dll $distdir/Browser
  135. [% END %]
  136. [% END %]
  137. # Make MAR-based update tools available for use during the bundle phase.
  138. # Note that mar and mbsdiff are standalone tools, compiled for the build
  139. # host's architecture. We also include signmar, certutil, and the libraries
  140. # they require; these utilities and libraries are built for the target
  141. # architecture.
  142. MARTOOLS=$distdir/mar-tools
  143. mkdir -p $MARTOOLS
  144. cp -p config/createprecomplete.py $MARTOOLS/
  145. cp -p tools/update-packaging/*.sh $MARTOOLS/
  146. cp -p obj-*/dist/host/bin/mar $MARTOOLS/
  147. cp -p obj-*/dist/host/bin/mbsdiff $MARTOOLS/
  148. [% IF c("var/linux") || c("var/osx") %]
  149. cp -p obj-*/dist/bin/signmar $MARTOOLS/
  150. cp -p obj-*/dist/bin/certutil $MARTOOLS/
  151. cp -p obj-*/dist/bin/modutil $MARTOOLS/
  152. cp -p obj-*/dist/bin/pk12util $MARTOOLS/
  153. cp -p obj-*/dist/bin/shlibsign $MARTOOLS/
  154. [% IF c("var/linux") %]
  155. NSS_LIBS="libfreeblpriv3.so libmozsqlite3.so libnss3.so libnssckbi.so libnssutil3.so libsmime3.so libsoftokn3.so libssl3.so"
  156. NSPR_LIBS="libnspr4.so libplc4.so libplds4.so"
  157. [% ELSE %]
  158. NSS_LIBS="libfreebl3.dylib libmozglue.dylib libnss3.dylib libnssckbi.dylib libsoftokn3.dylib"
  159. # No NSPR_LIBS for macOS
  160. NSPR_LIBS=""
  161. [% END %]
  162. for LIB in $NSS_LIBS $NSPR_LIBS; do
  163. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  164. done
  165. [% END %]
  166. [% IF c("var/windows") %]
  167. cp -p obj-*/dist/bin/signmar.exe $MARTOOLS/
  168. cp -p obj-*/dist/bin/certutil.exe $MARTOOLS/
  169. cp -p obj-*/dist/bin/modutil.exe $MARTOOLS/
  170. cp -p obj-*/dist/bin/pk12util.exe $MARTOOLS/
  171. cp -p obj-*/dist/bin/shlibsign.exe $MARTOOLS/
  172. NSS_LIBS="freebl3.dll mozglue.dll nss3.dll nssckbi.dll softokn3.dll"
  173. for LIB in $NSS_LIBS; do
  174. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  175. done
  176. [% END %]
  177. cd $distdir
  178. [% IF c("var/linux-x86_64") %]
  179. [% IF !c("var/asan") %]
  180. # No need for an unstripped geckodriver
  181. strip geckodriver
  182. [% END %]
  183. mkdir -p $distdir/Debug/Browser/gtk2
  184. # Strip and generate debuginfo for the firefox binary that we keep, all *.so
  185. # files, the plugin-container, and the updater (see ticket #10126)
  186. for LIB in Browser/*.so Browser/gtk2/*.so Browser/firefox.real Browser/plugin-container Browser/updater
  187. do
  188. objcopy --only-keep-debug $LIB Debug/$LIB
  189. strip $LIB
  190. objcopy --add-gnu-debuglink=./Debug/$LIB $LIB
  191. done
  192. [% END %]
  193. # Re-zipping the omni.ja files is not needed to make them reproductible,
  194. # however if we don't re-zip them, the files become corrupt when we
  195. # update them using 'zip' and firefox will silently fail to load some
  196. # parts.
  197. [% IF c("var/windows") || c("var/linux") %]
  198. [% c("var/rezip", { rezip_file => 'Browser/omni.ja' }) %]
  199. [% c("var/rezip", { rezip_file => 'Browser/browser/omni.ja' }) %]
  200. [% ELSIF c("var/osx") %]
  201. [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/omni.ja"' }) %]
  202. [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/browser/omni.ja"' }) %]
  203. [% END %]
  204. [%
  205. IF c("var/osx");
  206. SET browserdir='"Tor Browser.app/Contents"';
  207. ELSE;
  208. SET browserdir='Browser';
  209. END;
  210. %]
  211. [% IF c("var/linux") %]
  212. /var/tmp/dist/gcc/bin/g++ $rootdir/abicheck.cc -o Browser/abicheck -std=c++17
  213. [% END %]
  214. [% c('tar', {
  215. tar_src => [ browserdir ],
  216. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser.tar.gz',
  217. }) %]
  218. [% IF c("var/linux-x86_64") %]
  219. [% c('tar', {
  220. tar_src => [ 'Debug' ],
  221. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser-debug.tar.xz',
  222. }) %]
  223. [% IF !c("var/asan") %]
  224. [% c('tar', {
  225. tar_src => [ 'geckodriver' ],
  226. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/geckodriver-linux64.tar.xz',
  227. }) %]
  228. [% END %]
  229. [% END %]
  230. [% c('zip', {
  231. zip_src => [ 'mar-tools' ],
  232. zip_args => dest_dir _ '/' _ c('filename') _ '/' _ c('var/martools_filename'),
  233. }) %]
  234. [% IF c("var/build_infos_json") -%]
  235. cat > "[% dest_dir _ '/' _ c('filename') _ '/build-infos.json' %]" << EOF_BUILDINFOS
  236. {
  237. "firefox_platform_version" : "[% c("var/firefox_platform_version") %]",
  238. "firefox_buildid" : "$MOZ_BUILD_DATE"
  239. }
  240. EOF_BUILDINFOS
  241. [% END -%]