build 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. #!/bin/bash
  2. [% c("var/setarch") -%]
  3. [% c("var/set_default_env") -%]
  4. [% IF c("var/windows") -%]
  5. mkdir -p /var/tmp/dist
  6. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/gcc') %]
  7. hgccdir=/var/tmp/dist/gcc
  8. # We need a link to our GCC, otherwise the system cc gets used which points to
  9. # /usr/bin/gcc.
  10. ln -s gcc $hgccdir/bin/cc
  11. # Make sure our GCC (as host compiler) get used. We do that before
  12. # compiler setup so that mingw is first in the PATH.
  13. export LD_LIBRARY_PATH=$hgccdir/lib64
  14. export PATH=$hgccdir/bin:$PATH
  15. [% END -%]
  16. [% IF c("var/linux-arm") -%]
  17. [% pc('gcc-cross', 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ 'gcc-cross') }) %]
  18. # Work around missing libraries. Maybe there's a better way?
  19. #ln -s -T /usr/include/fontconfig /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/include/fontconfig
  20. #ln -s -T /usr/include/ft2build.h /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/include/ft2build.h
  21. #ln -s -T /usr/include/X11 /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/include/X11
  22. # Work around try2
  23. #crossdepsdir=/var/tmp/dist/cross-deps-chroot
  24. #mkdir -p $crossdepsdir
  25. #fakeroot /usr/sbin/qemu-debootstrap --arch=armhf --variant=minbase --include=libgtk2.0-dev,libdbus-glib-1-dev,libxt-dev,libpulse-dev,libgconf2-dev,libx11-xcb-dev,libmpc2 wheezy $crossdepsdir
  26. #cp --archive --no-clobber $crossdepsdir/usr/include/* /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/include/
  27. #cp --archive --no-clobber $crossdepsdir/usr/lib/arm-linux-gnueabihf/lib*.so* /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/lib/
  28. # Work around try3
  29. crossdepsdir=/var/tmp/dist/cross-deps-chroot
  30. mkdir -p $crossdepsdir
  31. pushd $crossdepsdir
  32. apt-get --option "APT::Architecture=armhf" download $(apt-rdepends libgtk2.0-dev:armhf libdbus-glib-1-dev:armhf libxt-dev:armhf libpulse-dev:armhf libgconf2-dev:armhf libx11-xcb-dev:armhf libmpc2:armhf|grep -v "^ "|grep -v "debconf-2.0"|grep -v "libc-dev"|grep -v "libz-dev")
  33. #apt-get download $(apt-rdepends libgtk2.0-dev:armhf libdbus-glib-1-dev:armhf libxt-dev:armhf libpulse-dev:armhf libgconf2-dev:armhf libx11-xcb-dev:armhf libmpc2:armhf|grep -v "^ "|grep -v "debconf-2.0"|grep -v "libc-dev"|grep -v "libz-dev"|sed 's/:armhf//'|sed 's/$/:armhf/')
  34. #apt-get download $(apt-rdepends libgtk2.0-dev:armhf libdbus-glib-1-dev:armhf libxt-dev:armhf libpulse-dev:armhf libgconf2-dev:armhf libx11-xcb-dev:armhf libmpc2:armhf|grep -v "^ "|grep -v "debconf-2.0"|grep -v "libc-dev"|grep -v "libz-dev"|sed 's/:armhf//'|sed 's/$/:all/')
  35. #apt-get download libdbus-glib-1-dev:armhf libgconf2-dev:armhf libgtk2.0-dev:armhf libmpc2:armhf libpulse-dev:armhf libx11-6:armhf libx11-xcb-dev:armhf libx11-xcb1:armhf libxcb1:armhf libxcb-shm0:armhf libxext6:armhf libxt-dev:armhf libxt6:armhf
  36. for PACKAGE in ./*.deb; do
  37. dpkg -x $PACKAGE ./
  38. done
  39. popd
  40. cp --archive --no-clobber $crossdepsdir/usr/include/* /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/include/
  41. cp --archive --no-clobber $crossdepsdir/usr/lib/arm-linux-gnueabihf/lib*.so* /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/lib/
  42. # Workaround for: /usr/bin/ld.gold.real: error: cannot open /var/tmp/dist/gcc-cross/lib/gcc/arm-linux-gnueabihf/6.4.0/../../../../arm-linux-gnueabihf/lib/libglib-2.0.so: No such file or directory
  43. cp --archive --no-clobber $crossdepsdir/lib/arm-linux-gnueabihf/libglib*.so* /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/lib/
  44. cp --archive $crossdepsdir/lib/arm-linux-gnueabihf/libglib-2.0.so.0 /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/lib/libglib-2.0.so
  45. cp --archive --no-clobber $crossdepsdir/lib/arm-linux-gnueabihf/libdbus*.so* /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/lib/
  46. cp --archive $crossdepsdir/lib/arm-linux-gnueabihf/libdbus-1.so.3 /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/lib/libdbus-1.so
  47. [% END -%]
  48. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  49. distdir=/var/tmp/dist/[% project %]
  50. mkdir -p /var/tmp/build
  51. [% IF c("var/windows") -%]
  52. mingwdir=/var/tmp/dist/mingw-w64
  53. mkdir -p $mingwdir/helpers
  54. cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-g++ << 'EOF'
  55. #!/bin/sh
  56. /var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-g++ [% c("var/LDFLAGS") %] [% c("var/CFLAGS") %] "$@"
  57. EOF
  58. cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-gcc << 'EOF'
  59. #!/bin/sh
  60. /var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-gcc [% c("var/LDFLAGS") %] [% c("var/CFLAGS") %] "$@"
  61. EOF
  62. cat > $mingwdir/helpers/[% c("arch") %]-w64-mingw32-ld << 'EOF'
  63. #!/bin/sh
  64. /var/tmp/dist/mingw-w64/bin/[% c("arch") %]-w64-mingw32-ld [% c("var/LDFLAGS") %] "$@"
  65. EOF
  66. chmod +x $mingwdir/helpers/*
  67. export PATH="$mingwdir/helpers:$PATH"
  68. [% END -%]
  69. [% IF c("var/linux") %]
  70. mkdir -p /var/tmp/dist
  71. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/binutils') %]
  72. export PATH="/var/tmp/dist/binutils/bin:$PATH"
  73. [% END -%]
  74. [% IF c("var/linux") && ! c("var/release") -%]
  75. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/selfrando') %]
  76. # Selfrando wrapper
  77. export PATH="/var/tmp/dist/selfrando/Tools/TorBrowser/tc-wrapper/:$PATH"
  78. # We need to avoid the shuffling while building as this breaks compilation
  79. export SELFRANDO_skip_shuffle=
  80. [% END -%]
  81. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  82. [% IF c("var/osx") %]
  83. mkdir -p $distdir/TorBrowser.app/Contents/MacOS
  84. [% ELSE %]
  85. mkdir -p $distdir/Browser
  86. [% END %]
  87. [% IF c("var/linux") %]
  88. mkdir -p $distdir/Debug/Browser/
  89. [% END %]
  90. cd /var/tmp/build/[% project %]-[% c("version") %]
  91. mv -f $rootdir/[% c('input_files_by_name/mozconfig') %] .mozconfig
  92. [% IF c("var/asan") -%]
  93. mv -f .mozconfig-asan .mozconfig
  94. # Without disabling LSan our build is blowing up:
  95. # https://bugs.torproject.org/10599#comment:52
  96. export ASAN_OPTIONS="detect_leaks=0"
  97. [% END -%]
  98. eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] $(cat browser/config/version.txt))
  99. if [ -z $MOZ_BUILD_DATE ]
  100. then
  101. echo "MOZ_BUILD_DATE is not set"
  102. exit 1
  103. fi
  104. [% IF c("var/windows") %]
  105. # FIXME
  106. # Ideally, using LDFLAGS (and e.g. DLLFLAGS for NSS) would be enough to get
  107. # all Firefox libraries linked against msvcr100. Alas, this does not hold for
  108. # NSPR. Without patching it we get a "missing entry points for _strcmpi in
  109. # msvcr100.dll". Now, this should be fixed in rev>=6179 as the def file there
  110. # contains a proper patch according to the mingw-w64 developers.
  111. # However, even with this patch the _strcmpi issue is still popping up,
  112. # probably due to a bug in our current linking setup. The small patch below
  113. # is therefore just a workaround which should get fixed but is at least
  114. # justified as the signature of _strcmpi and _stricmp is the same, see:
  115. # http://msdn.microsoft.com/en-us/library/k59z8dwe.aspx.
  116. sed 's/strcmpi/stricmp/' -i nsprpub/pr/src/linking/prlink.c
  117. export HOST_LDFLAGS=" "
  118. export LDFLAGS="-specs=/var/tmp/dist/mingw-w64/msvcr100.spec"
  119. # Our flags don't get passed to NSS. We need to do that manually using an
  120. # obscure one.
  121. export DLLFLAGS="-specs=/var/tmp/dist/mingw-w64/msvcr100.spec"
  122. # Make sure widl is not inserting random timestamps, see #21837.
  123. export WIDL_TIME_OVERRIDE="0"
  124. [% END %]
  125. [% IF c("var/osname") == "linux-i686" -%]
  126. export LDFLAGS=-m32
  127. export CFLAGS=-m32
  128. export CC='gcc -m32'
  129. [% END -%]
  130. [% IF c("var/windows-x86_64") %]
  131. patch -p1 < $rootdir/STL_win64.patch
  132. [% END -%]
  133. [% IF c("var/linux-arm") %]
  134. patch -p1 < $rootdir/jsnativestack_unistd_armhf.patch
  135. [% END -%]
  136. rm -f configure
  137. rm -f js/src/configure
  138. make -f client.mk configure CONFIGURE_ARGS="--with-tor-browser-version=[% c("var/torbrowser_version") %] --with-distribution-id=org.torproject --enable-update-channel=[% c("var/torbrowser_update_channel") %] --enable-bundled-fonts"
  139. make -j[% c("buildconf/num_procs") %] -f client.mk build
  140. make -C obj-* package INNER_MAKE_PACKAGE=true
  141. [% IF c("var/osx") %]
  142. cp -a obj-macos/dist/firefox/* $distdir
  143. # Remove firefox-bin (we don't use it, see ticket #10126)
  144. rm -f $distdir/TorBrowser.app/Contents/MacOS/firefox-bin
  145. # Adjust the Info.plist file
  146. INFO_PLIST=$distdir/TorBrowser.app/Contents/Info.plist
  147. mv $INFO_PLIST tmp.plist
  148. python $rootdir/fix-info-plist.py '[% c("var/torbrowser_version") %]' '[% c("var/copyright_year") %]' < tmp.plist > $INFO_PLIST
  149. rm -f tmp.plist
  150. [% END %]
  151. [% IF c("var/linux") %]
  152. cp -a obj-*/dist/firefox/* $distdir/Browser/
  153. # Remove firefox-bin (we don't use it, see ticket #10126)
  154. rm -f $distdir/Browser/firefox-bin
  155. # TODO: There goes FIPS-140.. We could upload these somewhere unique and
  156. # subsequent builds could test to see if they've been uploaded before...
  157. # But let's find out if it actually matters first..
  158. rm -f $distdir/Browser/*.chk
  159. [% END %]
  160. [% IF c("var/windows-x86_64") -%]
  161. mv $rootdir/msvcr100-x86_64.dll $rootdir/msvcr100.dll
  162. [% END -%]
  163. [% IF c("var/windows") %]
  164. cp -a obj-*/dist/firefox/* $distdir/Browser/
  165. cp -a $rootdir/msvcr100.dll $distdir/Browser
  166. cp -a $gcclibs/libssp-0.dll $distdir/Browser
  167. [% END %]
  168. [% IF c("var/linux-arm") -%]
  169. cp -a /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/lib/libssp.so* $distdir/Browser
  170. [% END %]
  171. # Make MAR-based update tools available for use during the bundle phase.
  172. # Note that mar and mbsdiff are standalone tools, compiled for the build
  173. # host's architecture. We also include signmar, certutil, and the libraries
  174. # they require; these utilities and libraries are built for the target
  175. # architecture.
  176. MARTOOLS=$distdir/mar-tools
  177. mkdir -p $MARTOOLS
  178. cp -p config/createprecomplete.py $MARTOOLS/
  179. cp -p tools/update-packaging/*.sh $MARTOOLS/
  180. cp -p obj-*/dist/host/bin/mar $MARTOOLS/
  181. cp -p obj-*/dist/host/bin/mbsdiff $MARTOOLS/
  182. [% IF c("var/linux") %]
  183. cp -p obj-*/modules/libmar/tool/signmar $MARTOOLS/
  184. cp -p obj-*/security/nss/cmd/certutil/certutil $MARTOOLS/
  185. NSS_LIBS="libfreeblpriv3.so libmozsqlite3.so libnss3.so libnssdbm3.so libnssutil3.so libsmime3.so libsoftokn3.so libssl3.so"
  186. NSPR_LIBS="libnspr4.so libplc4.so libplds4.so"
  187. for LIB in $NSS_LIBS $NSPR_LIBS; do
  188. cp -p obj-*/dist/bin/$LIB $MARTOOLS/
  189. done
  190. [% END %]
  191. cd $distdir
  192. [% IF c("var/linux") %]
  193. # If cross-compiling, use the target objcopy/strip
  194. [% IF c("var/linux-arm") -%]
  195. TARGET_OBJCOPY="/var/tmp/dist/gcc-cross/bin/arm-linux-gnueabihf-objcopy"
  196. TARGET_STRIP="/var/tmp/dist/gcc-cross/bin/arm-linux-gnueabihf-strip"
  197. [% ELSE %]
  198. TARGET_OBJCOPY="objcopy"
  199. TARGET_STRIP="strip"
  200. [% END %]
  201. # Strip and generate debuginfo for the firefox binary that we keep, all *.so
  202. # files, the plugin-container, and the updater (see ticket #10126)
  203. for LIB in Browser/*.so Browser/firefox Browser/plugin-container Browser/updater
  204. do
  205. $TARGET_OBJCOPY --only-keep-debug $LIB Debug/$LIB
  206. $TARGET_STRIP $LIB
  207. $TARGET_OBJCOPY --add-gnu-debuglink=./Debug/$LIB $LIB
  208. done
  209. [% END %]
  210. # Re-zipping the omni.ja files is not needed to make them reproductible,
  211. # however if we don't re-zip them, the files become corrupt when we
  212. # update them using 'zip' and firefox will silently fail to load some
  213. # parts.
  214. [% IF c("var/windows") || c("var/linux") %]
  215. [% c("var/rezip", { rezip_file => 'Browser/omni.ja' }) %]
  216. [% c("var/rezip", { rezip_file => 'Browser/browser/omni.ja' }) %]
  217. [% ELSIF c("var/osx") %]
  218. [% c("var/rezip", { rezip_file => 'TorBrowser.app/Contents/Resources/omni.ja' }) %]
  219. [% c("var/rezip", { rezip_file => 'TorBrowser.app/Contents/Resources/browser/omni.ja' }) %]
  220. [% END %]
  221. [% IF c("var/windows") %]
  222. cp $rootdir/msvcr100.dll Browser/
  223. cp $gcclibs/libssp-0.dll Browser/
  224. [% END %]
  225. [% IF c("var/linux-arm") -%]
  226. cp /var/tmp/dist/gcc-cross/arm-linux-gnueabihf/lib/libssp.so* Browser/
  227. [% END %]
  228. mkdir -p [% dest_dir _ '/' _ c('filename') %]
  229. [%
  230. IF c("var/osx");
  231. SET browserdir='TorBrowser.app/Contents';
  232. ELSE;
  233. SET browserdir='Browser';
  234. END;
  235. %]
  236. [% c('tar', {
  237. tar_src => [ browserdir ],
  238. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser.tar.gz',
  239. }) %]
  240. [% IF c("var/linux") %]
  241. [% c('tar', {
  242. tar_src => [ 'Debug' ],
  243. tar_args => '-cJf ' _ dest_dir _ '/' _ c('filename') _ '/tor-browser-debug.tar.xz',
  244. }) %]
  245. [% END %]
  246. [% c('zip', {
  247. zip_src => [ 'mar-tools' ],
  248. zip_args => dest_dir _ '/' _ c('filename') _ '/' _ c('var/martools_filename'),
  249. }) %]