sysroot-creator.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. # Copyright 2014 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. #
  5. # This script should not be run directly but sourced by the other
  6. # scripts (e.g. sysroot-creator-bullseye.sh). Its up to the parent scripts
  7. # to define certain environment variables: e.g.
  8. # DISTRO=debian
  9. # DIST=bullseye
  10. # # Similar in syntax to /etc/apt/sources.list
  11. # APT_SOURCES_LIST=( "http://ftp.us.debian.org/debian/ bullseye main" )
  12. # KEYRING_FILE=debian-archive-bullseye-stable.gpg
  13. # DEBIAN_PACKAGES="gcc libz libssl"
  14. #@ This script builds Debian/Ubuntu sysroot images for building Google Chrome.
  15. #@
  16. #@ Generally this script is invoked as:
  17. #@ sysroot-creator-<flavour>.sh <mode> <args>*
  18. #@ Available modes are shown below.
  19. #@
  20. #@ List of modes:
  21. ######################################################################
  22. # Config
  23. ######################################################################
  24. set -o nounset
  25. set -o errexit
  26. SCRIPT_DIR=$(cd $(dirname $0) && pwd)
  27. if [ -z "${DIST:-}" ]; then
  28. echo "error: DIST not defined"
  29. exit 1
  30. fi
  31. if [ -z "${KEYRING_FILE:-}" ]; then
  32. echo "error: KEYRING_FILE not defined"
  33. exit 1
  34. fi
  35. if [ -z "${DEBIAN_PACKAGES:-}" ]; then
  36. echo "error: DEBIAN_PACKAGES not defined"
  37. exit 1
  38. fi
  39. readonly HAS_ARCH_AMD64=${HAS_ARCH_AMD64:=0}
  40. readonly HAS_ARCH_I386=${HAS_ARCH_I386:=0}
  41. readonly HAS_ARCH_ARM=${HAS_ARCH_ARM:=0}
  42. readonly HAS_ARCH_ARM64=${HAS_ARCH_ARM64:=0}
  43. readonly HAS_ARCH_ARMEL=${HAS_ARCH_ARMEL:=0}
  44. readonly HAS_ARCH_MIPS=${HAS_ARCH_MIPS:=0}
  45. readonly HAS_ARCH_MIPS64EL=${HAS_ARCH_MIPS64EL:=0}
  46. readonly REQUIRED_TOOLS="curl xzcat"
  47. ######################################################################
  48. # Package Config
  49. ######################################################################
  50. readonly PACKAGES_EXT=xz
  51. readonly RELEASE_FILE="Release"
  52. readonly RELEASE_FILE_GPG="Release.gpg"
  53. readonly DEBIAN_DEP_LIST_AMD64="generated_package_lists/${DIST}.amd64"
  54. readonly DEBIAN_DEP_LIST_I386="generated_package_lists/${DIST}.i386"
  55. readonly DEBIAN_DEP_LIST_ARM="generated_package_lists/${DIST}.arm"
  56. readonly DEBIAN_DEP_LIST_ARM64="generated_package_lists/${DIST}.arm64"
  57. readonly DEBIAN_DEP_LIST_ARMEL="generated_package_lists/${DIST}.armel"
  58. readonly DEBIAN_DEP_LIST_MIPS="generated_package_lists/${DIST}.mipsel"
  59. readonly DEBIAN_DEP_LIST_MIPS64EL="generated_package_lists/${DIST}.mips64el"
  60. ######################################################################
  61. # Helper
  62. ######################################################################
  63. Banner() {
  64. echo "######################################################################"
  65. echo $*
  66. echo "######################################################################"
  67. }
  68. SubBanner() {
  69. echo "----------------------------------------------------------------------"
  70. echo $*
  71. echo "----------------------------------------------------------------------"
  72. }
  73. Usage() {
  74. egrep "^#@" "${BASH_SOURCE[0]}" | cut --bytes=3-
  75. }
  76. DownloadOrCopyNonUniqueFilename() {
  77. # Use this function instead of DownloadOrCopy when the url uniquely
  78. # identifies the file, but the filename (excluding the directory)
  79. # does not.
  80. local url="$1"
  81. local dest="$2"
  82. local hash="$(echo "$url" | sha256sum | cut -d' ' -f1)"
  83. DownloadOrCopy "${url}" "${dest}.${hash}"
  84. # cp the file to prevent having to redownload it, but mv it to the
  85. # final location so that it's atomic.
  86. cp "${dest}.${hash}" "${dest}.$$"
  87. mv "${dest}.$$" "${dest}"
  88. }
  89. DownloadOrCopy() {
  90. if [ -f "$2" ] ; then
  91. echo "$2 already in place"
  92. return
  93. fi
  94. HTTP=0
  95. echo "$1" | grep -Eqs '^https?://' && HTTP=1
  96. if [ "$HTTP" = "1" ]; then
  97. SubBanner "downloading from $1 -> $2"
  98. # Appending the "$$" shell pid is necessary here to prevent concurrent
  99. # instances of sysroot-creator.sh from trying to write to the same file.
  100. local temp_file="${2}.partial.$$"
  101. # curl --retry doesn't retry when the page gives a 4XX error, so we need to
  102. # manually rerun.
  103. for i in {1..10}; do
  104. # --create-dirs is added in case there are slashes in the filename, as can
  105. # happen with the "debian/security" release class.
  106. local http_code=$(curl -L "$1" --create-dirs -o "${temp_file}" \
  107. -w "%{http_code}")
  108. if [ ${http_code} -eq 200 ]; then
  109. break
  110. fi
  111. echo "Bad HTTP code ${http_code} when downloading $1"
  112. rm -f "${temp_file}"
  113. sleep $i
  114. done
  115. if [ ! -f "${temp_file}" ]; then
  116. exit 1
  117. fi
  118. mv "${temp_file}" $2
  119. else
  120. SubBanner "copying from $1"
  121. cp "$1" "$2"
  122. fi
  123. }
  124. SetEnvironmentVariables() {
  125. case $1 in
  126. *Amd64)
  127. ARCH=AMD64
  128. ;;
  129. *I386)
  130. ARCH=I386
  131. ;;
  132. *Mips64el)
  133. ARCH=MIPS64EL
  134. ;;
  135. *Mips)
  136. ARCH=MIPS
  137. ;;
  138. *ARM)
  139. ARCH=ARM
  140. ;;
  141. *ARM64)
  142. ARCH=ARM64
  143. ;;
  144. *ARMEL)
  145. ARCH=ARMEL
  146. ;;
  147. *)
  148. echo "ERROR: Unable to determine architecture based on: $1"
  149. exit 1
  150. ;;
  151. esac
  152. ARCH_LOWER=$(echo $ARCH | tr '[:upper:]' '[:lower:]')
  153. }
  154. # some sanity checks to make sure this script is run from the right place
  155. # with the right tools
  156. SanityCheck() {
  157. Banner "Sanity Checks"
  158. local chrome_dir=$(cd "${SCRIPT_DIR}/../../.." && pwd)
  159. BUILD_DIR="${chrome_dir}/out/sysroot-build/${DIST}"
  160. mkdir -p ${BUILD_DIR}
  161. echo "Using build directory: ${BUILD_DIR}"
  162. for tool in ${REQUIRED_TOOLS} ; do
  163. if ! which ${tool} > /dev/null ; then
  164. echo "Required binary $tool not found."
  165. echo "Exiting."
  166. exit 1
  167. fi
  168. done
  169. # This is where the staging sysroot is.
  170. INSTALL_ROOT="${BUILD_DIR}/${DIST}_${ARCH_LOWER}_staging"
  171. TARBALL="${BUILD_DIR}/${DISTRO}_${DIST}_${ARCH_LOWER}_sysroot.tar.xz"
  172. if ! mkdir -p "${INSTALL_ROOT}" ; then
  173. echo "ERROR: ${INSTALL_ROOT} can't be created."
  174. exit 1
  175. fi
  176. }
  177. ChangeDirectory() {
  178. # Change directory to where this script is.
  179. cd ${SCRIPT_DIR}
  180. }
  181. ClearInstallDir() {
  182. Banner "Clearing dirs in ${INSTALL_ROOT}"
  183. rm -rf ${INSTALL_ROOT}/*
  184. }
  185. CreateTarBall() {
  186. Banner "Creating tarball ${TARBALL}"
  187. tar -I "xz -9 -T0" -cf ${TARBALL} -C ${INSTALL_ROOT} .
  188. }
  189. ExtractPackageXz() {
  190. local src_file="$1"
  191. local dst_file="$2"
  192. local repo="$3"
  193. xzcat "${src_file}" | egrep '^(Package:|Filename:|SHA256:) ' |
  194. sed "s|Filename: |Filename: ${repo}|" > "${dst_file}"
  195. }
  196. GeneratePackageListDistRepo() {
  197. local arch="$1"
  198. local repo="$2"
  199. local dist="$3"
  200. local repo_name="$4"
  201. local tmp_package_list="${BUILD_DIR}/Packages.${dist}_${repo_name}_${arch}"
  202. local repo_basedir="${repo}/dists/${dist}"
  203. local package_list="${BUILD_DIR}/Packages.${dist}_${repo_name}_${arch}.${PACKAGES_EXT}"
  204. local package_file_arch="${repo_name}/binary-${arch}/Packages.${PACKAGES_EXT}"
  205. local package_list_arch="${repo_basedir}/${package_file_arch}"
  206. DownloadOrCopyNonUniqueFilename "${package_list_arch}" "${package_list}"
  207. VerifyPackageListing "${package_file_arch}" "${package_list}" ${repo} ${dist}
  208. ExtractPackageXz "${package_list}" "${tmp_package_list}" ${repo}
  209. cat "${tmp_package_list}" | ./merge-package-lists.py "${list_base}"
  210. }
  211. GeneratePackageListDist() {
  212. local arch="$1"
  213. set -- $2
  214. local repo="$1"
  215. local dist="$2"
  216. shift 2
  217. while (( "$#" )); do
  218. GeneratePackageListDistRepo "$arch" "$repo" "$dist" "$1"
  219. shift
  220. done
  221. }
  222. GeneratePackageListCommon() {
  223. local output_file="$1"
  224. local arch="$2"
  225. local packages="$3"
  226. local list_base="${BUILD_DIR}/Packages.${DIST}_${arch}"
  227. > "${list_base}" # Create (or truncate) a zero-length file.
  228. printf '%s\n' "${APT_SOURCES_LIST[@]}" | while read source; do
  229. GeneratePackageListDist "${arch}" "${source}"
  230. done
  231. GeneratePackageList "${list_base}" "${output_file}" "${packages}"
  232. }
  233. GeneratePackageListAmd64() {
  234. GeneratePackageListCommon "$1" amd64 "${DEBIAN_PACKAGES}
  235. ${DEBIAN_PACKAGES_X86:=} ${DEBIAN_PACKAGES_AMD64:=}"
  236. }
  237. GeneratePackageListI386() {
  238. GeneratePackageListCommon "$1" i386 "${DEBIAN_PACKAGES}
  239. ${DEBIAN_PACKAGES_X86:=}"
  240. }
  241. GeneratePackageListARM() {
  242. GeneratePackageListCommon "$1" armhf "${DEBIAN_PACKAGES}
  243. ${DEBIAN_PACKAGES_ARM:=}"
  244. }
  245. GeneratePackageListARM64() {
  246. GeneratePackageListCommon "$1" arm64 "${DEBIAN_PACKAGES}
  247. ${DEBIAN_PACKAGES_ARM64:=}"
  248. }
  249. GeneratePackageListARMEL() {
  250. GeneratePackageListCommon "$1" armel "${DEBIAN_PACKAGES}
  251. ${DEBIAN_PACKAGES_ARMEL:=}"
  252. }
  253. GeneratePackageListMips() {
  254. GeneratePackageListCommon "$1" mipsel "${DEBIAN_PACKAGES}"
  255. }
  256. GeneratePackageListMips64el() {
  257. GeneratePackageListCommon "$1" mips64el "${DEBIAN_PACKAGES}
  258. ${DEBIAN_PACKAGES_MIPS64EL:=}"
  259. }
  260. StripChecksumsFromPackageList() {
  261. local package_file="$1"
  262. sed -i 's/ [a-f0-9]\{64\}$//' "$package_file"
  263. }
  264. ######################################################################
  265. #
  266. ######################################################################
  267. HacksAndPatchesCommon() {
  268. local arch=$1
  269. local os=$2
  270. local strip=$3
  271. Banner "Misc Hacks & Patches"
  272. # Remove an unnecessary dependency on qtchooser.
  273. rm "${INSTALL_ROOT}/usr/lib/${arch}-${os}/qt-default/qtchooser/default.conf"
  274. # Unversion libdbus and libxkbcommon symbols. This is required because
  275. # libdbus-1-3 and libxkbcommon0 switched from unversioned symbols to versioned
  276. # ones, and we must still support distros using the unversioned library. This
  277. # hack can be removed once support for Ubuntu Trusty and Debian Jessie are
  278. # dropped.
  279. ${strip} -R .gnu.version_d -R .gnu.version \
  280. "${INSTALL_ROOT}/lib/${arch}-${os}/libdbus-1.so.3"
  281. cp "${SCRIPT_DIR}/libdbus-1-3-symbols" \
  282. "${INSTALL_ROOT}/debian/libdbus-1-3/DEBIAN/symbols"
  283. ${strip} -R .gnu.version_d -R .gnu.version \
  284. "${INSTALL_ROOT}/usr/lib/${arch}-${os}/libxkbcommon.so.0.0.0"
  285. cp "${SCRIPT_DIR}/libxkbcommon0-symbols" \
  286. "${INSTALL_ROOT}/debian/libxkbcommon0/DEBIAN/symbols"
  287. # libxcomposite1 is missing a symbols file.
  288. cp "${SCRIPT_DIR}/libxcomposite1-symbols" \
  289. "${INSTALL_ROOT}/debian/libxcomposite1/DEBIAN/symbols"
  290. # Shared objects depending on libdbus-1.so.3 have unsatisfied undefined
  291. # versioned symbols. To avoid LLD --no-allow-shlib-undefined errors, rewrite
  292. # DT_NEEDED entries from libdbus-1.so.3 to a different string. LLD will
  293. # suppress --no-allow-shlib-undefined diagnostics for such shared objects.
  294. set +e
  295. for f in "${INSTALL_ROOT}/lib/${arch}-${os}"/*.so \
  296. "${INSTALL_ROOT}/usr/lib/${arch}-${os}"/*.so; do
  297. echo "$f" | grep -q 'libdbus-1.so$' && continue
  298. # In a dependent shared object, the only occurrence of "libdbus-1.so.3" is
  299. # the string referenced by the DT_NEEDED entry.
  300. offset=$(LANG=C grep -abo libdbus-1.so.3 "$f")
  301. [ -n "$offset" ] || continue
  302. echo -n 'libdbus-1.so.0' | dd of="$f" conv=notrunc bs=1 \
  303. seek="$(echo -n "$offset" | cut -d : -f 1)" status=none
  304. done
  305. set -e
  306. # fcntl64() was introduced in glibc 2.28. Make sure to use fcntl() instead.
  307. local fcntl_h="${INSTALL_ROOT}/usr/include/fcntl.h"
  308. sed -i '{N; s/#ifndef __USE_FILE_OFFSET64\(\nextern int fcntl\)/#if 1\1/}' \
  309. "${fcntl_h}"
  310. # __GLIBC_MINOR__ is used as a feature test macro. Replace it with the
  311. # earliest supported version of glibc (2.17, https://crbug.com/376567).
  312. local usr_include="${INSTALL_ROOT}/usr/include"
  313. local features_h="${usr_include}/features.h"
  314. sed -i 's|\(#define\s\+__GLIBC_MINOR__\)|\1 17 //|' "${features_h}"
  315. # Do not use pthread_cond_clockwait as it was introduced in glibc 2.30.
  316. local cppconfig_h="${usr_include}/${arch}-${os}/c++/10/bits/c++config.h"
  317. sed -i 's|\(#define\s\+_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT\)|// \1|' \
  318. "${cppconfig_h}"
  319. # This is for chrome's ./build/linux/pkg-config-wrapper
  320. # which overwrites PKG_CONFIG_LIBDIR internally
  321. SubBanner "Move pkgconfig scripts"
  322. mkdir -p ${INSTALL_ROOT}/usr/lib/pkgconfig
  323. mv ${INSTALL_ROOT}/usr/lib/${arch}-${os}/pkgconfig/* \
  324. ${INSTALL_ROOT}/usr/lib/pkgconfig
  325. }
  326. ReversionGlibc() {
  327. local arch=$1
  328. local os=$2
  329. # Avoid requiring unsupported glibc versions.
  330. "${SCRIPT_DIR}/reversion_glibc.py" \
  331. "${INSTALL_ROOT}/lib/${arch}-${os}/libc.so.6"
  332. "${SCRIPT_DIR}/reversion_glibc.py" \
  333. "${INSTALL_ROOT}/lib/${arch}-${os}/libm.so.6"
  334. "${SCRIPT_DIR}/reversion_glibc.py" \
  335. "${INSTALL_ROOT}/lib/${arch}-${os}/libcrypt.so.1"
  336. }
  337. HacksAndPatchesAmd64() {
  338. HacksAndPatchesCommon x86_64 linux-gnu strip
  339. ReversionGlibc x86_64 linux-gnu
  340. }
  341. HacksAndPatchesI386() {
  342. HacksAndPatchesCommon i386 linux-gnu strip
  343. ReversionGlibc i386 linux-gnu
  344. }
  345. HacksAndPatchesARM() {
  346. HacksAndPatchesCommon arm linux-gnueabihf arm-linux-gnueabihf-strip
  347. ReversionGlibc arm linux-gnueabihf
  348. }
  349. HacksAndPatchesARM64() {
  350. # Use the unstripped libdbus for arm64 to prevent linker errors.
  351. # https://bugs.chromium.org/p/webrtc/issues/detail?id=8535
  352. HacksAndPatchesCommon aarch64 linux-gnu true
  353. # Skip reversion_glibc.py. Glibc is compiled in a way where many libm math
  354. # functions do not have compatibility symbols for versions <= 2.17.
  355. # ReversionGlibc aarch64 linux-gnu
  356. }
  357. HacksAndPatchesARMEL() {
  358. HacksAndPatchesCommon arm linux-gnueabi arm-linux-gnueabi-strip
  359. ReversionGlibc arm linux-gnueabi
  360. }
  361. HacksAndPatchesMips() {
  362. HacksAndPatchesCommon mipsel linux-gnu mipsel-linux-gnu-strip
  363. ReversionGlibc mipsel linux-gnu
  364. }
  365. HacksAndPatchesMips64el() {
  366. HacksAndPatchesCommon mips64el linux-gnuabi64 mips64el-linux-gnuabi64-strip
  367. ReversionGlibc mips64el linux-gnuabi64
  368. }
  369. InstallIntoSysroot() {
  370. Banner "Install Libs And Headers Into Jail"
  371. mkdir -p ${BUILD_DIR}/debian-packages
  372. # The /debian directory is an implementation detail that's used to cd into
  373. # when running dpkg-shlibdeps.
  374. mkdir -p ${INSTALL_ROOT}/debian
  375. # An empty control file is necessary to run dpkg-shlibdeps.
  376. touch ${INSTALL_ROOT}/debian/control
  377. while (( "$#" )); do
  378. local file="$1"
  379. local package="${BUILD_DIR}/debian-packages/${file##*/}"
  380. shift
  381. local sha256sum="$1"
  382. shift
  383. if [ "${#sha256sum}" -ne "64" ]; then
  384. echo "Bad sha256sum from package list"
  385. exit 1
  386. fi
  387. Banner "Installing $(basename ${file})"
  388. DownloadOrCopy ${file} ${package}
  389. if [ ! -s "${package}" ] ; then
  390. echo
  391. echo "ERROR: bad package ${package}"
  392. exit 1
  393. fi
  394. echo "${sha256sum} ${package}" | sha256sum --quiet -c
  395. SubBanner "Extracting to ${INSTALL_ROOT}"
  396. dpkg-deb -x ${package} ${INSTALL_ROOT}
  397. base_package=$(dpkg-deb --field ${package} Package)
  398. mkdir -p ${INSTALL_ROOT}/debian/${base_package}/DEBIAN
  399. dpkg-deb -e ${package} ${INSTALL_ROOT}/debian/${base_package}/DEBIAN
  400. done
  401. # Prune /usr/share, leaving only pkgconfig.
  402. ls -d ${INSTALL_ROOT}/usr/share/* | grep -v "/pkgconfig$" | xargs rm -r
  403. }
  404. CleanupJailSymlinks() {
  405. Banner "Jail symlink cleanup"
  406. SAVEDPWD=$(pwd)
  407. cd ${INSTALL_ROOT}
  408. local libdirs="lib usr/lib"
  409. if [ "${ARCH}" != "MIPS" ]; then
  410. libdirs="${libdirs} lib64"
  411. fi
  412. find $libdirs -type l -printf '%p %l\n' | while read link target; do
  413. # skip links with non-absolute paths
  414. echo "${target}" | grep -qs ^/ || continue
  415. echo "${link}: ${target}"
  416. # Relativize the symlink.
  417. prefix=$(echo "${link}" | sed -e 's/[^/]//g' | sed -e 's|/|../|g')
  418. ln -snfv "${prefix}${target}" "${link}"
  419. done
  420. failed=0
  421. while read link target; do
  422. # Make sure we catch new bad links.
  423. if [ ! -r "${link}" ]; then
  424. echo "ERROR: FOUND BAD LINK ${link}"
  425. ls -l ${link}
  426. failed=1
  427. fi
  428. done < <(find $libdirs -type l -printf '%p %l\n')
  429. if [ $failed -eq 1 ]; then
  430. exit 1
  431. fi
  432. cd "$SAVEDPWD"
  433. }
  434. VerifyLibraryDepsCommon() {
  435. local arch=$1
  436. local os=$2
  437. local find_dirs=(
  438. "${INSTALL_ROOT}/lib/"
  439. "${INSTALL_ROOT}/lib/${arch}-${os}/"
  440. "${INSTALL_ROOT}/usr/lib/${arch}-${os}/"
  441. )
  442. local needed_libs="$(
  443. find ${find_dirs[*]} -name "*\.so*" -type f -exec file {} \; | \
  444. grep ': ELF' | sed 's/^\(.*\): .*$/\1/' | xargs readelf -d | \
  445. grep NEEDED | sort | uniq | sed 's/^.*Shared library: \[\(.*\)\]$/\1/g')"
  446. local all_libs="$(find ${find_dirs[*]} -printf '%f\n')"
  447. # Ignore missing libdbus-1.so.0
  448. all_libs+="$(echo -e '\nlibdbus-1.so.0')"
  449. local missing_libs="$(grep -vFxf <(echo "${all_libs}") \
  450. <(echo "${needed_libs}"))"
  451. if [ ! -z "${missing_libs}" ]; then
  452. echo "Missing libraries:"
  453. echo "${missing_libs}"
  454. exit 1
  455. fi
  456. }
  457. VerifyLibraryDepsAmd64() {
  458. VerifyLibraryDepsCommon x86_64 linux-gnu
  459. }
  460. VerifyLibraryDepsI386() {
  461. VerifyLibraryDepsCommon i386 linux-gnu
  462. }
  463. VerifyLibraryDepsARM() {
  464. VerifyLibraryDepsCommon arm linux-gnueabihf
  465. }
  466. VerifyLibraryDepsARM64() {
  467. VerifyLibraryDepsCommon aarch64 linux-gnu
  468. }
  469. VerifyLibraryDepsARMEL() {
  470. VerifyLibraryDepsCommon arm linux-gnueabi
  471. }
  472. VerifyLibraryDepsMips() {
  473. VerifyLibraryDepsCommon mipsel linux-gnu
  474. }
  475. VerifyLibraryDepsMips64el() {
  476. VerifyLibraryDepsCommon mips64el linux-gnuabi64
  477. }
  478. #@
  479. #@ BuildSysrootAmd64
  480. #@
  481. #@ Build everything and package it
  482. BuildSysrootAmd64() {
  483. if [ "$HAS_ARCH_AMD64" = "0" ]; then
  484. return
  485. fi
  486. ClearInstallDir
  487. local package_file="${DEBIAN_DEP_LIST_AMD64}"
  488. GeneratePackageListAmd64 "$package_file"
  489. local files_and_sha256sums="$(cat ${package_file})"
  490. StripChecksumsFromPackageList "$package_file"
  491. InstallIntoSysroot ${files_and_sha256sums}
  492. HacksAndPatchesAmd64
  493. CleanupJailSymlinks
  494. VerifyLibraryDepsAmd64
  495. CreateTarBall
  496. }
  497. #@
  498. #@ BuildSysrootI386
  499. #@
  500. #@ Build everything and package it
  501. BuildSysrootI386() {
  502. if [ "$HAS_ARCH_I386" = "0" ]; then
  503. return
  504. fi
  505. ClearInstallDir
  506. local package_file="${DEBIAN_DEP_LIST_I386}"
  507. GeneratePackageListI386 "$package_file"
  508. local files_and_sha256sums="$(cat ${package_file})"
  509. StripChecksumsFromPackageList "$package_file"
  510. InstallIntoSysroot ${files_and_sha256sums}
  511. HacksAndPatchesI386
  512. CleanupJailSymlinks
  513. VerifyLibraryDepsI386
  514. CreateTarBall
  515. }
  516. #@
  517. #@ BuildSysrootARM
  518. #@
  519. #@ Build everything and package it
  520. BuildSysrootARM() {
  521. if [ "$HAS_ARCH_ARM" = "0" ]; then
  522. return
  523. fi
  524. ClearInstallDir
  525. local package_file="${DEBIAN_DEP_LIST_ARM}"
  526. GeneratePackageListARM "$package_file"
  527. local files_and_sha256sums="$(cat ${package_file})"
  528. StripChecksumsFromPackageList "$package_file"
  529. InstallIntoSysroot ${files_and_sha256sums}
  530. HacksAndPatchesARM
  531. CleanupJailSymlinks
  532. VerifyLibraryDepsARM
  533. CreateTarBall
  534. }
  535. #@
  536. #@ BuildSysrootARM64
  537. #@
  538. #@ Build everything and package it
  539. BuildSysrootARM64() {
  540. if [ "$HAS_ARCH_ARM64" = "0" ]; then
  541. return
  542. fi
  543. ClearInstallDir
  544. local package_file="${DEBIAN_DEP_LIST_ARM64}"
  545. GeneratePackageListARM64 "$package_file"
  546. local files_and_sha256sums="$(cat ${package_file})"
  547. StripChecksumsFromPackageList "$package_file"
  548. InstallIntoSysroot ${files_and_sha256sums}
  549. HacksAndPatchesARM64
  550. CleanupJailSymlinks
  551. VerifyLibraryDepsARM64
  552. CreateTarBall
  553. }
  554. #@
  555. #@ BuildSysrootARMEL
  556. #@
  557. #@ Build everything and package it
  558. BuildSysrootARMEL() {
  559. if [ "$HAS_ARCH_ARMEL" = "0" ]; then
  560. return
  561. fi
  562. ClearInstallDir
  563. local package_file="${DEBIAN_DEP_LIST_ARMEL}"
  564. GeneratePackageListARMEL "$package_file"
  565. local files_and_sha256sums="$(cat ${package_file})"
  566. StripChecksumsFromPackageList "$package_file"
  567. InstallIntoSysroot ${files_and_sha256sums}
  568. HacksAndPatchesARMEL
  569. CleanupJailSymlinks
  570. VerifyLibraryDepsARMEL
  571. CreateTarBall
  572. }
  573. #@
  574. #@ BuildSysrootMips
  575. #@
  576. #@ Build everything and package it
  577. BuildSysrootMips() {
  578. if [ "$HAS_ARCH_MIPS" = "0" ]; then
  579. return
  580. fi
  581. ClearInstallDir
  582. local package_file="${DEBIAN_DEP_LIST_MIPS}"
  583. GeneratePackageListMips "$package_file"
  584. local files_and_sha256sums="$(cat ${package_file})"
  585. StripChecksumsFromPackageList "$package_file"
  586. InstallIntoSysroot ${files_and_sha256sums}
  587. HacksAndPatchesMips
  588. CleanupJailSymlinks
  589. VerifyLibraryDepsMips
  590. CreateTarBall
  591. }
  592. #@
  593. #@ BuildSysrootMips64el
  594. #@
  595. #@ Build everything and package it
  596. BuildSysrootMips64el() {
  597. if [ "$HAS_ARCH_MIPS64EL" = "0" ]; then
  598. return
  599. fi
  600. ClearInstallDir
  601. local package_file="${DEBIAN_DEP_LIST_MIPS64EL}"
  602. GeneratePackageListMips64el "$package_file"
  603. local files_and_sha256sums="$(cat ${package_file})"
  604. StripChecksumsFromPackageList "$package_file"
  605. InstallIntoSysroot ${files_and_sha256sums}
  606. HacksAndPatchesMips64el
  607. CleanupJailSymlinks
  608. VerifyLibraryDepsMips64el
  609. CreateTarBall
  610. }
  611. #@
  612. #@ BuildSysrootAll
  613. #@
  614. #@ Build sysroot images for all architectures
  615. BuildSysrootAll() {
  616. RunCommand BuildSysrootAmd64
  617. RunCommand BuildSysrootI386
  618. RunCommand BuildSysrootARM
  619. RunCommand BuildSysrootARM64
  620. RunCommand BuildSysrootARMEL
  621. RunCommand BuildSysrootMips
  622. RunCommand BuildSysrootMips64el
  623. }
  624. UploadSysroot() {
  625. local sha=$(sha1sum "${TARBALL}" | awk '{print $1;}')
  626. set -x
  627. gsutil.py cp -a public-read "${TARBALL}" \
  628. "gs://chrome-linux-sysroot/toolchain/$sha/"
  629. set +x
  630. }
  631. #@
  632. #@ UploadSysrootAmd64
  633. #@
  634. UploadSysrootAmd64() {
  635. if [ "$HAS_ARCH_AMD64" = "0" ]; then
  636. return
  637. fi
  638. UploadSysroot "$@"
  639. }
  640. #@
  641. #@ UploadSysrootI386
  642. #@
  643. UploadSysrootI386() {
  644. if [ "$HAS_ARCH_I386" = "0" ]; then
  645. return
  646. fi
  647. UploadSysroot "$@"
  648. }
  649. #@
  650. #@ UploadSysrootARM
  651. #@
  652. UploadSysrootARM() {
  653. if [ "$HAS_ARCH_ARM" = "0" ]; then
  654. return
  655. fi
  656. UploadSysroot "$@"
  657. }
  658. #@
  659. #@ UploadSysrootARM64
  660. #@
  661. UploadSysrootARM64() {
  662. if [ "$HAS_ARCH_ARM64" = "0" ]; then
  663. return
  664. fi
  665. UploadSysroot "$@"
  666. }
  667. #@
  668. #@ UploadSysrootARMEL
  669. #@
  670. UploadSysrootARMEL() {
  671. if [ "$HAS_ARCH_ARMEL" = "0" ]; then
  672. return
  673. fi
  674. UploadSysroot "$@"
  675. }
  676. #@
  677. #@ UploadSysrootMips
  678. #@
  679. UploadSysrootMips() {
  680. if [ "$HAS_ARCH_MIPS" = "0" ]; then
  681. return
  682. fi
  683. UploadSysroot "$@"
  684. }
  685. #@
  686. #@ UploadSysrootMips64el
  687. #@
  688. UploadSysrootMips64el() {
  689. if [ "$HAS_ARCH_MIPS64EL" = "0" ]; then
  690. return
  691. fi
  692. UploadSysroot "$@"
  693. }
  694. #@
  695. #@ UploadSysrootAll
  696. #@
  697. #@ Upload sysroot image for all architectures
  698. UploadSysrootAll() {
  699. RunCommand UploadSysrootAmd64 "$@"
  700. RunCommand UploadSysrootI386 "$@"
  701. RunCommand UploadSysrootARM "$@"
  702. RunCommand UploadSysrootARM64 "$@"
  703. RunCommand UploadSysrootARMEL "$@"
  704. RunCommand UploadSysrootMips "$@"
  705. RunCommand UploadSysrootMips64el "$@"
  706. }
  707. #
  708. # CheckForDebianGPGKeyring
  709. #
  710. # Make sure the Debian GPG keys exist. Otherwise print a helpful message.
  711. #
  712. CheckForDebianGPGKeyring() {
  713. if [ ! -e "$KEYRING_FILE" ]; then
  714. echo "KEYRING_FILE not found: ${KEYRING_FILE}"
  715. echo "Debian GPG keys missing. Install the debian-archive-keyring package."
  716. exit 1
  717. fi
  718. }
  719. #
  720. # VerifyPackageListing
  721. #
  722. # Verifies the downloaded Packages.xz file has the right checksums.
  723. #
  724. VerifyPackageListing() {
  725. local file_path="$1"
  726. local output_file="$2"
  727. local repo="$3"
  728. local dist="$4"
  729. local repo_basedir="${repo}/dists/${dist}"
  730. local release_list="${repo_basedir}/${RELEASE_FILE}"
  731. local release_list_gpg="${repo_basedir}/${RELEASE_FILE_GPG}"
  732. local release_file="${BUILD_DIR}/${dist}-${RELEASE_FILE}"
  733. local release_file_gpg="${BUILD_DIR}/${dist}-${RELEASE_FILE_GPG}"
  734. CheckForDebianGPGKeyring
  735. DownloadOrCopyNonUniqueFilename ${release_list} ${release_file}
  736. DownloadOrCopyNonUniqueFilename ${release_list_gpg} ${release_file_gpg}
  737. echo "Verifying: ${release_file} with ${release_file_gpg}"
  738. set -x
  739. gpgv --keyring "${KEYRING_FILE}" "${release_file_gpg}" "${release_file}"
  740. set +x
  741. echo "Verifying: ${output_file}"
  742. local sha256sum=$(grep -E "${file_path}\$|:\$" "${release_file}" | \
  743. grep "SHA256:" -A 1 | xargs echo | awk '{print $2;}')
  744. if [ "${#sha256sum}" -ne "64" ]; then
  745. echo "Bad sha256sum from ${release_list}"
  746. exit 1
  747. fi
  748. echo "${sha256sum} ${output_file}" | sha256sum --quiet -c
  749. }
  750. #
  751. # GeneratePackageList
  752. #
  753. # Looks up package names in ${BUILD_DIR}/Packages and write list of URLs
  754. # to output file.
  755. #
  756. GeneratePackageList() {
  757. local input_file="$1"
  758. local output_file="$2"
  759. echo "Updating: ${output_file} from ${input_file}"
  760. /bin/rm -f "${output_file}"
  761. shift
  762. shift
  763. local failed=0
  764. for pkg in $@ ; do
  765. local pkg_full=$(grep -A 1 " ${pkg}\$" "$input_file" | \
  766. egrep "pool/.*" | sed 's/.*Filename: //')
  767. if [ -z "${pkg_full}" ]; then
  768. echo "ERROR: missing package: $pkg"
  769. local failed=1
  770. else
  771. local sha256sum=$(grep -A 4 " ${pkg}\$" "$input_file" | \
  772. grep ^SHA256: | sed 's/^SHA256: //')
  773. if [ "${#sha256sum}" -ne "64" ]; then
  774. echo "Bad sha256sum from Packages"
  775. local failed=1
  776. fi
  777. echo $pkg_full $sha256sum >> "$output_file"
  778. fi
  779. done
  780. if [ $failed -eq 1 ]; then
  781. exit 1
  782. fi
  783. # sort -o does an in-place sort of this file
  784. sort "$output_file" -o "$output_file"
  785. }
  786. #@
  787. #@ PrintArchitectures
  788. #@
  789. #@ Prints supported architectures.
  790. PrintArchitectures() {
  791. if [ "$HAS_ARCH_AMD64" = "1" ]; then
  792. echo Amd64
  793. fi
  794. if [ "$HAS_ARCH_I386" = "1" ]; then
  795. echo I386
  796. fi
  797. if [ "$HAS_ARCH_ARM" = "1" ]; then
  798. echo ARM
  799. fi
  800. if [ "$HAS_ARCH_ARM64" = "1" ]; then
  801. echo ARM64
  802. fi
  803. if [ "$HAS_ARCH_ARMEL" = "1" ]; then
  804. echo ARMEL
  805. fi
  806. if [ "$HAS_ARCH_MIPS" = "1" ]; then
  807. echo Mips
  808. fi
  809. if [ "$HAS_ARCH_MIPS64EL" = "1" ]; then
  810. echo Mips64el
  811. fi
  812. }
  813. #@
  814. #@ PrintDistro
  815. #@
  816. #@ Prints distro. eg: ubuntu
  817. PrintDistro() {
  818. echo ${DISTRO}
  819. }
  820. #@
  821. #@ DumpRelease
  822. #@
  823. #@ Prints disto release. eg: jessie
  824. PrintRelease() {
  825. echo ${DIST}
  826. }
  827. RunCommand() {
  828. SetEnvironmentVariables "$1"
  829. SanityCheck
  830. "$@"
  831. }
  832. if [ $# -eq 0 ] ; then
  833. echo "ERROR: you must specify a mode on the commandline"
  834. echo
  835. Usage
  836. exit 1
  837. elif [ "$(type -t $1)" != "function" ]; then
  838. echo "ERROR: unknown function '$1'." >&2
  839. echo "For help, try:"
  840. echo " $0 help"
  841. exit 1
  842. else
  843. ChangeDirectory
  844. if echo $1 | grep -qs --regexp='\(^Print\)\|\(All$\)'; then
  845. "$@"
  846. else
  847. RunCommand "$@"
  848. fi
  849. fi