build 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. [% END -%]
  12. tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
  13. tar -C /var/tmp/dist -xf [% c('input_files_by_name/cbindgen') %]
  14. tar -C /var/tmp/dist -xf [% c('input_files_by_name/nasm') %]
  15. tar -C /var/tmp/dist -xf [% c('input_files_by_name/node') %]
  16. export PATH="/var/tmp/dist/rust/bin:/var/tmp/dist/cbindgen:/var/tmp/dist/nasm/bin:/var/tmp/dist/node/bin:$PATH"
  17. [% IF c("var/linux") %]
  18. tar -C /var/tmp/dist -xf [% c('input_files_by_name/clang') %]
  19. tar -C /var/tmp/dist -xf [% c('input_files_by_name/python') %]
  20. export PATH="/var/tmp/dist/python/bin:$PATH"
  21. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
  22. export PATH="/var/tmp/dist/binutils/bin:$PATH"
  23. # Use clang for everything on Linux now if we don't build with ASan.
  24. [% IF ! c("var/asan") -%]
  25. export PATH="/var/tmp/dist/clang/bin:$PATH"
  26. [% END -%]
  27. [% IF c("var/linux-i686") %]
  28. # Exporting `PKG_CONFIG_PATH` in the mozconfig file is causing build
  29. # breakage in Rust code. It seems that environment variable is not passed
  30. # down properly in that case. Thus, we set it here in the build script.
  31. export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/lib/i386-linux-gnu/pkgconfig"
  32. [% END -%]
  33. [% END -%]
  34. [% IF c("var/rlbox") -%]
  35. tar -C /var/tmp/dist -xf [% c('input_files_by_name/wasi-sysroot') %]
  36. # XXX: We need the libclang_rt.builtins-wasm32.a in our clang lib directory.
  37. # Copy it over.
  38. # https://searchfox.org/mozilla-central/source/build/build-clang/build-clang.py#890,
  39. # include it directly in our clang
  40. [% IF c("var/macos") -%]
  41. rtdir=/var/tmp/dist/macosx-toolchain/clang/lib/clang/[% pc("clang", "version") %]/lib/wasi
  42. [% ELSIF c("var/windows") -%]
  43. rtdir=/var/tmp/dist/mingw-w64-clang/lib/clang/[% pc("clang", "version") %]/lib/wasi
  44. [% ELSE -%]
  45. rtdir=/var/tmp/dist/clang/lib/clang/[% pc("clang", "version") %]/lib/wasi
  46. [% END -%]
  47. mkdir -p $rtdir
  48. cp /var/tmp/dist/wasi-sysroot/lib/clang/*/lib/wasi/libclang_rt.builtins-wasm32.a $rtdir
  49. export WASI_SYSROOT=/var/tmp/dist/wasi-sysroot/share/wasi-sysroot
  50. [% END -%]
  51. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  52. mkdir -p $distdir/[% IF ! c("var/macos") %]Browser[% END %]
  53. cd /var/tmp/build/[% project %]-[% c("version") %]
  54. cat > .mozconfig << 'MOZCONFIG_EOF'
  55. [% INCLUDE mozconfig %]
  56. MOZCONFIG_EOF
  57. [% IF c("var/asan") -%]
  58. # Without disabling LSan our build is blowing up:
  59. # https://bugs.torproject.org/10599#comment:52
  60. export ASAN_OPTIONS="detect_leaks=0"
  61. [% END -%]
  62. eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
  63. if [ -z $MOZ_BUILD_DATE ]
  64. then
  65. echo "MOZ_BUILD_DATE is not set"
  66. exit 1
  67. fi
  68. [% IF c("var/windows") %]
  69. # Make sure widl is not inserting random timestamps, see #21837.
  70. export WIDL_TIME_OVERRIDE="0"
  71. patch -p1 < $rootdir/nsis-uninstall.patch
  72. # mingw-w64 does not support SEH on 32bit systems. Be explicit about that.
  73. export LDFLAGS="[% c('var/flag_noSEH') %]"
  74. [% END -%]
  75. [% IF c("var/namecoin") %]
  76. patch -p1 < $rootdir/namecoin-etld.patch
  77. [% END -%]
  78. [% IF c("var/namecoin") %]
  79. pushd toolkit/torbutton
  80. patch -p1 < $rootdir/namecoin-torbutton.patch
  81. popd
  82. [% END %]
  83. [% IF c("var/nightly") && ! c("var/privacy-browser") -%]
  84. # Set update url for nightly (#33402 / #40033)
  85. sed -i 's|^URL=https://aus1\.torproject\.org/.*|URL=https://nightlies.tbb.torproject.org/nightly-updates/updates/nightly-[% c("var/nightly_updates_publish_dir") %]/%CHANNEL%/%BUILD_TARGET%/%VERSION%/ALL|' build/application.ini.in
  86. [% END -%]
  87. rm -f configure
  88. rm -f js/src/configure
  89. export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=system
  90. # Create .mozbuild to avoid interactive prompt in configure
  91. mkdir "$HOME/.mozbuild"
  92. [% IF c("var/has_l10n") -%]
  93. supported_locales="[% tmpl(c('var/locales').join(' ')) %]"
  94. l10ncentral="$HOME/.mozbuild/l10n-central"
  95. mkdir "$l10ncentral"
  96. for tarball in $rootdir/[% c('input_files_by_name/firefox-l10n') %]/*; do
  97. tar -C "$l10ncentral" -xf "$tarball"
  98. done
  99. tar -C "$rootdir" -xf "$rootdir/[% c('input_files_by_name/translation-base-browser') %]"
  100. pushd "$rootdir/translation-base-browser"
  101. ln -s ja ja-JP-mac
  102. for lang in $supported_locales; do
  103. # Please notice that Fluent and DTDs use different directories in
  104. # l10n-central! This is something we have to keep in mind when we will join
  105. # the two branches!
  106. mv $lang/* "$l10ncentral/$lang/browser/chrome/browser/"
  107. done
  108. popd
  109. tar -C "$rootdir" -xf "$rootdir/[% c('input_files_by_name/translation-base-browser-fluent') %]"
  110. pushd "$rootdir/translation-base-browser-fluent"
  111. ln -s ja ja-JP-mac
  112. # TODO: These two sources will be unified eventually; at that point, this link
  113. # will go away, too.
  114. ln -s es es-ES
  115. for lang in $supported_locales; do
  116. mv $lang/languageNotification.ftl "$l10ncentral/$lang/browser/browser/"
  117. done
  118. popd
  119. [% IF c("var/tor-browser") -%]
  120. # We will have to keep the torbutton.jar until we stop using dtds, because
  121. # if we move them to the browser locale directory, browser.xhtml is not
  122. # loaded.
  123. tar -C "$rootdir" -xf "$rootdir/[% c('input_files_by_name/translation-tor-browser') %]"
  124. transl_tor_browser="$rootdir/translation-tor-browser"
  125. torbutton_locales="toolkit/torbutton/chrome/locale/"
  126. torbutton_jar="toolkit/torbutton/jar.mn"
  127. for lang in $supported_locales; do
  128. central_lang=$lang
  129. [% IF c("var/macos") -%]
  130. if [ "$lang" == "ja-JP-mac" ]; then
  131. lang="ja"
  132. fi
  133. [% END -%]
  134. mv "$transl_tor_browser/$lang/cryptoSafetyPrompt.properties" "$l10ncentral/$central_lang/browser/chrome/browser/"
  135. mv "$transl_tor_browser/$lang" "$torbutton_locales/"
  136. echo "% locale torbutton $lang %locale/$lang/" >> "$torbutton_jar"
  137. echo " locale/$lang (chrome/locale/$lang/*)" >> "$torbutton_jar"
  138. done
  139. [% END -%]
  140. [% ELSE -%]
  141. supported_locales=""
  142. [% END -%]
  143. # PyYAML tries to read files as ASCII, otherwise
  144. export LC_ALL=C.UTF-8
  145. export LANG=C.UTF-8
  146. ./mach configure \
  147. --with-distribution-id=org.torproject \
  148. --with-base-browser-version=[% c("var/torbrowser_version") %] \
  149. [% IF c("var/tor-browser") -%]
  150. --enable-update-channel=[% c("var/channel") %] \
  151. [% END %] \
  152. [% IF !c("var/base-browser") -%]--with-branding=browser/branding/[% c("var/branding_directory_prefix") %]-[% c("var/channel") %][% END %] \
  153. [% IF !c("var/rlbox") -%]--without-wasm-sandboxed-libraries[% END %]
  154. ./mach build --verbose
  155. [% IF c("var/has_l10n") %]
  156. export MOZ_CHROME_MULTILOCALE="$supported_locales"
  157. # No quotes on purpose, see https://firefox-source-docs.mozilla.org/build/buildsystem/locales.html#instructions-for-multi-locale-builds
  158. ./mach package-multi-locale --locales en-US $MOZ_CHROME_MULTILOCALE
  159. AB_CD=multi ./mach build stage-package
  160. [% ELSE %]
  161. ./mach build stage-package
  162. [% END %]
  163. [% IF c("var/macos") %]
  164. cp -a obj-*/dist/[% c('var/exe_name') %]/* $distdir
  165. [% IF c("var/base-browser") -%]
  166. mv "$distdir/Firefox.app" "$distdir/[% c('var/Project_Name') %].app"
  167. [% END -%]
  168. # Remove firefox-bin (we don't use it, see ticket #10126)
  169. rm -f "$distdir/[% c('var/Project_Name') %].app/Contents/MacOS/[% c('var/exe_name') %]-bin"
  170. # Adjust the Info.plist file
  171. INFO_PLIST="$distdir/[% c('var/Project_Name') %].app/Contents/Info.plist"
  172. mv "$INFO_PLIST" tmp.plist
  173. python3 $rootdir/fix-info-plist.py '[% c("var/torbrowser_version") %]' '[% c("var/copyright_year") %]' < tmp.plist > "$INFO_PLIST"
  174. rm -f tmp.plist
  175. [% END %]
  176. [% IF c("var/linux") %]
  177. [% IF c("var/linux-x86_64") && !c("var/asan") %]
  178. cp obj-*/testing/geckodriver/x86_64-unknown-linux-gnu/release/geckodriver $distdir
  179. [% END %]
  180. cp -a obj-*/dist/[% c('var/exe_name') %]/* $distdir/Browser/
  181. # Remove firefox-bin (we don't use it, see ticket #10126)
  182. rm -f "$distdir/Browser/[% c('var/exe_name') %]-bin"
  183. # TODO: There goes FIPS-140.. We could upload these somewhere unique and
  184. # subsequent builds could test to see if they've been uploaded before...
  185. # But let's find out if it actually matters first..
  186. rm -f $distdir/Browser/*.chk
  187. # Replace $exe_name by a wrapper script (#25485)
  188. mv "$distdir/Browser/[% c('var/exe_name') %]" "$distdir/Browser/[% c('var/exe_name') %].real"
  189. cat > "$distdir/Browser/[% c('var/exe_name') %]" << 'RBM_TB_EOF'
  190. [% INCLUDE 'start-firefox' -%]
  191. RBM_TB_EOF
  192. chmod 755 "$distdir/Browser/[% c('var/exe_name') %]"
  193. [% END %]
  194. [% IF c("var/windows") %]
  195. cp -a obj-*/dist/[% c('var/exe_name') %]/* $distdir/Browser/
  196. [% IF c("var/windows-i686") %]
  197. cp -a /var/tmp/dist/fxc2/bin/d3dcompiler_47_32.dll $distdir/Browser/d3dcompiler_47.dll
  198. [% ELSE %]
  199. cp -a /var/tmp/dist/fxc2/bin/d3dcompiler_47.dll $distdir/Browser
  200. [% END %]
  201. [% END %]
  202. [% IF c("var/updater_enabled") -%]
  203. # Make MAR-based update tools available for use during the bundle phase.
  204. # Note that mar and mbsdiff are standalone tools, compiled for the build
  205. # host's architecture. We also include signmar, certutil, and the libraries
  206. # they require; these utilities and libraries are built for the target
  207. # architecture.
  208. MARTOOLS=$distdir/mar-tools
  209. mkdir -p $MARTOOLS
  210. cp -p config/createprecomplete.py $MARTOOLS/
  211. cp -p tools/update-packaging/*.sh $MARTOOLS/
  212. cp -p obj-*/dist/host/bin/mar $MARTOOLS/
  213. cp -p obj-*/dist/host/bin/mbsdiff $MARTOOLS/
  214. [% IF c("var/linux") || c("var/macos") %]
  215. cp -p obj-*/dist/bin/signmar $MARTOOLS/
  216. cp -p obj-*/dist/bin/certutil $MARTOOLS/
  217. cp -p obj-*/dist/bin/modutil $MARTOOLS/
  218. cp -p obj-*/dist/bin/pk12util $MARTOOLS/
  219. cp -p obj-*/dist/bin/shlibsign $MARTOOLS/
  220. [% IF c("var/linux") %]
  221. NSS_LIBS="libfreeblpriv3.so libmozsqlite3.so libnss3.so libnssckbi.so libnssutil3.so libsmime3.so libsoftokn3.so libssl3.so"
  222. NSPR_LIBS="libnspr4.so libplc4.so libplds4.so"
  223. [% ELSE %]
  224. NSS_LIBS="libfreebl3.dylib libmozglue.dylib libnss3.dylib libnssckbi.dylib libsoftokn3.dylib"
  225. # No NSPR_LIBS for macOS
  226. NSPR_LIBS=""
  227. [% END %]
  228. for LIB in $NSS_LIBS $NSPR_LIBS; do
  229. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  230. done
  231. [% END %]
  232. [% IF c("var/windows") %]
  233. cp -p obj-*/dist/bin/signmar.exe $MARTOOLS/
  234. cp -p obj-*/dist/bin/certutil.exe $MARTOOLS/
  235. cp -p obj-*/dist/bin/modutil.exe $MARTOOLS/
  236. cp -p obj-*/dist/bin/pk12util.exe $MARTOOLS/
  237. cp -p obj-*/dist/bin/shlibsign.exe $MARTOOLS/
  238. NSS_LIBS="freebl3.dll mozglue.dll nss3.dll nssckbi.dll softokn3.dll"
  239. for LIB in $NSS_LIBS; do
  240. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  241. done
  242. [% END %]
  243. [% END -%]
  244. cd $distdir
  245. [% IF c("var/linux-x86_64") %]
  246. [% IF !c("var/asan") %]
  247. # No need for an unstripped geckodriver
  248. strip geckodriver
  249. [% END %]
  250. mkdir -p $distdir/Debug/Browser
  251. # Strip and generate debuginfo for the firefox binary that we keep, all *.so
  252. # files, the plugin-container, and the updater (see ticket #10126)
  253. for LIB in Browser/*.so "Browser/[% c('var/exe_name') %].real" Browser/plugin-container [% IF c("var/updater_enabled") -%]Browser/updater[% END %]
  254. do
  255. objcopy --only-keep-debug $LIB Debug/$LIB
  256. strip $LIB
  257. objcopy --add-gnu-debuglink=./Debug/$LIB $LIB
  258. done
  259. [% END %]
  260. # Re-zipping the omni.ja files is not needed to make them reproductible,
  261. # however if we don't re-zip them, the files become corrupt when we
  262. # update them using 'zip' and firefox will silently fail to load some
  263. # parts.
  264. [% IF c("var/windows") || c("var/linux") %]
  265. [% c("var/rezip", { rezip_file => 'Browser/omni.ja' }) %]
  266. [% c("var/rezip", { rezip_file => 'Browser/browser/omni.ja' }) %]
  267. [% ELSIF c("var/macos") %]
  268. [% c("var/rezip", { rezip_file => '"' _ c("var/Project_Name") _ '.app/Contents/Resources/omni.ja"' }) %]
  269. [% c("var/rezip", { rezip_file => '"' _ c("var/Project_Name") _ '.app/Contents/Resources/browser/omni.ja"' }) %]
  270. [% END %]
  271. [%
  272. IF c("var/macos");
  273. SET browserdir='"' _ c("var/Project_Name") _ '.app/Contents"';
  274. ELSE;
  275. SET browserdir='Browser';
  276. END;
  277. %]
  278. [% IF c("var/linux") %]
  279. /var/tmp/dist/gcc/bin/g++ $rootdir/abicheck.cc -o Browser/abicheck -std=c++17
  280. [% IF !c("var/torbrowser") %]
  281. libdest=Browser/libstdc++
  282. mkdir -p "$libdest"
  283. # FIXME: tor-browser-build#40749
  284. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libstdc++.so.* "$libdest"
  285. [% IF c("var/asan") -%]
  286. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libasan.so.* "$libdest"
  287. cp /var/tmp/dist/gcc/[% c("var/libdir") %]/libubsan.so.* "$libdest"
  288. [% END -%]
  289. [% END %]
  290. [% END %]
  291. [% c('tar', {
  292. tar_src => [ browserdir ],
  293. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/browser.tar.gz',
  294. }) %]
  295. [% IF c("var/linux-x86_64") %]
  296. [% c('tar', {
  297. tar_src => [ 'Debug' ],
  298. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/browser-debug.tar.xz',
  299. }) %]
  300. [% IF !c("var/asan") %]
  301. [% c('tar', {
  302. tar_src => [ 'geckodriver' ],
  303. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/geckodriver-linux64.tar.xz',
  304. }) %]
  305. [% END %]
  306. [% END %]
  307. [% IF c("var/updater_enabled") -%]
  308. [% c('zip', {
  309. zip_src => [ 'mar-tools' ],
  310. zip_args => dest_dir _ '/' _ c('filename') _ '/' _ c('var/martools_filename'),
  311. }) %]
  312. [% END -%]
  313. [% IF c("var/build_infos_json") -%]
  314. cat > "[% dest_dir _ '/' _ c('filename') _ '/build-infos.json' %]" << EOF_BUILDINFOS
  315. {
  316. "firefox_platform_version" : "[% c("var/firefox_platform_version") %]",
  317. "firefox_buildid" : "$MOZ_BUILD_DATE"
  318. }
  319. EOF_BUILDINFOS
  320. [% END -%]