build 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. distdir=/var/tmp/dist/[% project %]
  12. mkdir -p /var/tmp/build
  13. mkdir -p [% dest_dir _ '/' _ c('filename') %]
  14. [% IF c("var/windows") -%]
  15. mingwdir=/var/tmp/dist/mingw-w64
  16. mkdir -p $mingwdir/helpers
  17. cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-g++ << 'EOF'
  18. #!/bin/sh
  19. /var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-g++ [% c("var/LDFLAGS") %] [% c("var/CFLAGS") %] "$@"
  20. EOF
  21. cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-gcc << 'EOF'
  22. #!/bin/sh
  23. /var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-gcc [% c("var/LDFLAGS") %] [% c("var/CFLAGS") %] "$@"
  24. EOF
  25. cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-ld << 'EOF'
  26. #!/bin/sh
  27. /var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-ld [% c("var/LDFLAGS") %] "$@"
  28. EOF
  29. chmod +x $mingwdir/helpers/*
  30. export PATH="$mingwdir/helpers:$PATH"
  31. [% END -%]
  32. [% IF c("var/windows") %]
  33. # Unpack fxc2.
  34. mkdir -p /var/tmp/dist
  35. tar -C /var/tmp/dist -xf [% c('input_files_by_name/fxc2') %]
  36. fxcdir=/var/tmp/dist/fxc2/bin
  37. cp $mingwdir/[% c("arch") %]-w64-mingw32/bin/libwinpthread-1.dll $fxcdir
  38. export PATH="$fxcdir:$PATH"
  39. # fxc2 requires Wine.
  40. [% IF c("var/windows-x86_64") %]
  41. export WINEARCH=win64
  42. [% END %]
  43. export HOME=/var/tmp/home
  44. mkdir -p $HOME
  45. WINEROOT=$HOME/.wine/drive_c
  46. wine wineboot -i
  47. [% END -%]
  48. [% IF c("var/linux") %]
  49. mkdir -p /var/tmp/dist
  50. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
  51. export PATH="/var/tmp/dist/binutils/bin:$PATH"
  52. [% END -%]
  53. [% IF c("var/selfrando") -%]
  54. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/selfrando') %]
  55. # Selfrando wrapper
  56. export PATH="/var/tmp/dist/selfrando/Tools/TorBrowser/tc-wrapper/:$PATH"
  57. # We need to avoid the shuffling while building as this breaks compilation
  58. export SELFRANDO_skip_shuffle=
  59. [% END -%]
  60. mkdir -p /var/tmp/dist
  61. tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
  62. export PATH="/var/tmp/dist/rust/bin:$PATH"
  63. [% IF c("var/linux") %]
  64. # Add llvm so stylo can build
  65. tar -C /var/tmp/dist -xf [% c('input_files_by_name/llvm') %]
  66. export LLVM_CONFIG="/var/tmp/dist/llvm/bin/llvm-config"
  67. [% END -%]
  68. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  69. [% IF c("var/osx") %]
  70. mkdir -p "$distdir/Tor Browser.app/Contents/MacOS"
  71. [% ELSE %]
  72. mkdir -p $distdir/Browser
  73. [% END %]
  74. [% IF c("var/linux") %]
  75. mkdir -p $distdir/Debug/Browser/
  76. [% END %]
  77. cd /var/tmp/build/[% project %]-[% c("version") %]
  78. mv -f $rootdir/[% c('input_files_by_name/mozconfig') %] .mozconfig
  79. [% IF c("var/asan") -%]
  80. mv -f .mozconfig-asan .mozconfig
  81. # Without disabling LSan our build is blowing up:
  82. # https://bugs.torproject.org/10599#comment:52
  83. export ASAN_OPTIONS="detect_leaks=0"
  84. [% END -%]
  85. [% IF c("var/android") %]
  86. export GRADLE_MAVEN_REPOSITORIES="file:///var/tmp/gradle-dependencies"
  87. gradle_repo=/var/tmp/gradle-dependencies
  88. # Move Gradle Repo to hard-coded location. This location is embedded in the file
  89. # chrome/toolkit/content/global/buildconfig.html so needs to be standard for reproducibility
  90. mv $rootdir/[% c('input_files_by_name/gradle-dependencies') %] $gradle_repo
  91. # The download script assumes the artifact package name is the complete URL path.
  92. # In some cases this is incorrect, so copy those artifacts to the correct location
  93. cp -r $gradle_repo/guardianproject/gpmaven/master/* $gradle_repo
  94. # Move orbot files so they will be included in the apk during the build
  95. cp $rootdir/[% c('input_files_by_name/orbot') %]/* mobile/android/app
  96. # Prepare building the multi-locale .apk
  97. mkdir -p /var/tmp/dist/locales
  98. tar -C /var/tmp/dist/locales -xf $rootdir/[% c('input_files_by_name/firefox-locale-bundle') %]
  99. [% END %]
  100. eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
  101. if [ -z $MOZ_BUILD_DATE ]
  102. then
  103. echo "MOZ_BUILD_DATE is not set"
  104. exit 1
  105. fi
  106. [% IF c("var/windows") %]
  107. # FIXME
  108. # Ideally, using LDFLAGS (and e.g. DLLFLAGS for NSS) would be enough to get
  109. # all Firefox libraries linked against msvcr100. Alas, this does not hold for
  110. # NSPR. Without patching it we get a "missing entry points for _strcmpi in
  111. # msvcr100.dll". Now, this should be fixed in rev>=6179 as the def file there
  112. # contains a proper patch according to the mingw-w64 developers.
  113. # However, even with this patch the _strcmpi issue is still popping up,
  114. # probably due to a bug in our current linking setup. The small patch below
  115. # is therefore just a workaround which should get fixed but is at least
  116. # justified as the signature of _strcmpi and _stricmp is the same, see:
  117. # http://msdn.microsoft.com/en-us/library/k59z8dwe.aspx.
  118. sed 's/strcmpi/stricmp/' -i nsprpub/pr/src/linking/prlink.c
  119. export HOST_LDFLAGS=" "
  120. export LDFLAGS="-specs=/var/tmp/dist/mingw-w64/msvcr100.spec"
  121. # Our flags don't get passed to NSS. We need to do that manually using an
  122. # obscure one.
  123. export DLLFLAGS="-specs=/var/tmp/dist/mingw-w64/msvcr100.spec"
  124. # Make sure widl is not inserting random timestamps, see #21837.
  125. export WIDL_TIME_OVERRIDE="0"
  126. [% END %]
  127. [% IF c("var/osname") == "linux-i686" -%]
  128. export LDFLAGS=-m32
  129. export CFLAGS=-m32
  130. export CC='gcc -m32'
  131. [% END -%]
  132. [% IF c("var/windows") %]
  133. patch -p1 < $rootdir/nsis-uninstall.patch
  134. [% END -%]
  135. rm -f configure
  136. rm -f js/src/configure
  137. ./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") %]
  138. ./mach build --verbose
  139. [% IF c("var/android") %]
  140. # Building a multi-locale .apk
  141. [% FOREACH lang = c('var/locales') %]
  142. [% SET lang = tmpl(lang) %]
  143. ./mach build chrome-[% lang %];
  144. [% END %]
  145. export MOZ_CHROME_MULTILOCALE='[% tmpl(c('var/locales').join(' ')) %]'
  146. AB_CD=multi ./mach package
  147. # Copy the result over and return. There is nothing more to do for mobile.
  148. cp obj-*/dist/*unsigned-unaligned.apk [% dest_dir _ '/' _ c('filename') %]/tor-browser-unsigned-unaligned.apk
  149. [% RETURN %]
  150. [% END %]
  151. ./mach build stage-package
  152. [% IF c("var/osx") %]
  153. cp -a obj-macos/dist/firefox/* $distdir
  154. # Remove firefox-bin (we don't use it, see ticket #10126)
  155. rm -f "$distdir/Tor Browser.app/Contents/MacOS/firefox-bin"
  156. # Adjust the Info.plist file
  157. INFO_PLIST="$distdir/Tor Browser.app/Contents/Info.plist"
  158. mv "$INFO_PLIST" tmp.plist
  159. python $rootdir/fix-info-plist.py '[% c("var/torbrowser_version") %]' '[% c("var/copyright_year") %]' < tmp.plist > "$INFO_PLIST"
  160. rm -f tmp.plist
  161. [% END %]
  162. [% IF c("var/linux") %]
  163. cp -a obj-*/dist/firefox/* $distdir/Browser/
  164. # Remove firefox-bin (we don't use it, see ticket #10126)
  165. rm -f $distdir/Browser/firefox-bin
  166. # TODO: There goes FIPS-140.. We could upload these somewhere unique and
  167. # subsequent builds could test to see if they've been uploaded before...
  168. # But let's find out if it actually matters first..
  169. rm -f $distdir/Browser/*.chk
  170. # Replace firefox by a wrapper script (#25485)
  171. mv $distdir/Browser/firefox $distdir/Browser/firefox.real
  172. mv $rootdir/start-firefox $distdir/Browser/firefox
  173. chmod 755 $distdir/Browser/firefox
  174. [% END %]
  175. [% IF c("var/windows-x86_64") -%]
  176. mv $rootdir/msvcr100-x86_64.dll $rootdir/msvcr100.dll
  177. [% END -%]
  178. [% IF c("var/windows") %]
  179. cp -a obj-*/dist/firefox/* $distdir/Browser/
  180. cp -a $rootdir/msvcr100.dll $distdir/Browser
  181. cp -a $gcclibs/libssp-0.dll $distdir/Browser
  182. cp -a $fxcdir/d3dcompiler_47.dll $distdir/Browser
  183. [% END %]
  184. # Make MAR-based update tools available for use during the bundle phase.
  185. # Note that mar and mbsdiff are standalone tools, compiled for the build
  186. # host's architecture. We also include signmar, certutil, and the libraries
  187. # they require; these utilities and libraries are built for the target
  188. # architecture.
  189. MARTOOLS=$distdir/mar-tools
  190. mkdir -p $MARTOOLS
  191. cp -p config/createprecomplete.py $MARTOOLS/
  192. cp -p tools/update-packaging/*.sh $MARTOOLS/
  193. cp -p obj-*/dist/host/bin/mar $MARTOOLS/
  194. cp -p obj-*/dist/host/bin/mbsdiff $MARTOOLS/
  195. [% IF c("var/linux") %]
  196. cp -p obj-*/modules/libmar/tool/signmar $MARTOOLS/
  197. cp -p obj-*/security/nss/cmd/certutil/certutil_certutil/certutil $MARTOOLS/
  198. cp -p obj-*/security/nss/cmd/modutil/modutil_modutil/modutil $MARTOOLS/
  199. cp -p obj-*/security/nss/cmd/pk12util/pk12util_pk12util/pk12util $MARTOOLS/
  200. cp -p obj-*/security/nss/cmd/shlibsign/shlibsign_shlibsign/shlibsign $MARTOOLS/
  201. NSS_LIBS="libfreeblpriv3.so libmozsqlite3.so libnss3.so libnssckbi.so libnssdbm3.so libnssutil3.so libsmime3.so libsoftokn3.so libssl3.so"
  202. NSPR_LIBS="libnspr4.so libplc4.so libplds4.so"
  203. for LIB in $NSS_LIBS $NSPR_LIBS; do
  204. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  205. done
  206. [% END %]
  207. [% IF c("var/osx") %]
  208. cp -p obj-*/modules/libmar/tool/signmar $MARTOOLS/
  209. cp -p obj-*/security/nss/cmd/certutil/certutil_certutil/certutil $MARTOOLS/
  210. cp -p obj-*/security/nss/cmd/modutil/modutil_modutil/modutil $MARTOOLS/
  211. cp -p obj-*/security/nss/cmd/pk12util/pk12util_pk12util/pk12util $MARTOOLS/
  212. cp -p obj-*/security/nss/cmd/shlibsign/shlibsign_shlibsign/shlibsign $MARTOOLS/
  213. NSS_LIBS="libfreebl3.dylib libmozglue.dylib libnss3.dylib libnssckbi.dylib libnssdbm3.dylib libsoftokn3.dylib"
  214. for LIB in $NSS_LIBS; do
  215. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  216. done
  217. [% END %]
  218. [% IF c("var/windows") %]
  219. cp -p obj-*/modules/libmar/tool/signmar.exe $MARTOOLS/
  220. cp -p obj-*/security/nss/cmd/certutil/certutil_certutil/certutil.exe $MARTOOLS/
  221. cp -p obj-*/security/nss/cmd/modutil/modutil_modutil/modutil.exe $MARTOOLS/
  222. cp -p obj-*/security/nss/cmd/pk12util/pk12util_pk12util/pk12util.exe $MARTOOLS/
  223. cp -p obj-*/security/nss/cmd/shlibsign/shlibsign_shlibsign/shlibsign.exe $MARTOOLS/
  224. NSS_LIBS="freebl3.dll mozglue.dll nss3.dll nssckbi.dll nssdbm3.dll softokn3.dll"
  225. for LIB in $NSS_LIBS; do
  226. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  227. done
  228. cp -a $rootdir/msvcr100.dll $MARTOOLS/
  229. [% END %]
  230. cd $distdir
  231. [% IF c("var/linux") %]
  232. # Strip and generate debuginfo for the firefox binary that we keep, all *.so
  233. # files, the plugin-container, and the updater (see ticket #10126)
  234. for LIB in Browser/*.so Browser/firefox.real Browser/plugin-container Browser/updater
  235. do
  236. objcopy --only-keep-debug $LIB Debug/$LIB
  237. strip $LIB
  238. objcopy --add-gnu-debuglink=./Debug/$LIB $LIB
  239. [% IF c("var/selfrando") -%]
  240. # remove RUNPATH added by selfrando (see #22242)
  241. chrpath -d $LIB
  242. [% END -%]
  243. done
  244. [% END %]
  245. # Re-zipping the omni.ja files is not needed to make them reproductible,
  246. # however if we don't re-zip them, the files become corrupt when we
  247. # update them using 'zip' and firefox will silently fail to load some
  248. # parts.
  249. [% IF c("var/windows") || c("var/linux") %]
  250. [% c("var/rezip", { rezip_file => 'Browser/omni.ja' }) %]
  251. [% c("var/rezip", { rezip_file => 'Browser/browser/omni.ja' }) %]
  252. [% ELSIF c("var/osx") %]
  253. [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/omni.ja"' }) %]
  254. [% c("var/rezip", { rezip_file => '"Tor Browser.app/Contents/Resources/browser/omni.ja"' }) %]
  255. [% END %]
  256. [%
  257. IF c("var/osx");
  258. SET browserdir='"Tor Browser.app/Contents"';
  259. ELSE;
  260. SET browserdir='Browser';
  261. END;
  262. %]
  263. [% IF c("var/linux") %]
  264. /var/tmp/dist/gcc/bin/g++ $rootdir/abicheck.cc -o Browser/abicheck
  265. [% END %]
  266. [% c('tar', {
  267. tar_src => [ browserdir ],
  268. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser.tar.gz',
  269. }) %]
  270. [% IF c("var/linux") %]
  271. [% c('tar', {
  272. tar_src => [ 'Debug' ],
  273. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser-debug.tar.xz',
  274. }) %]
  275. [% END %]
  276. [% c('zip', {
  277. zip_src => [ 'mar-tools' ],
  278. zip_args => dest_dir _ '/' _ c('filename') _ '/' _ c('var/martools_filename'),
  279. }) %]