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.
5 # This script should not be run directly but sourced by the other
6 # scripts (e.g. sysroot-creator-trusty.sh). Its up to the parent scripts
7 # to define certain environment variables: e.g.
10 # APT_REPO=http://archive.ubuntu.com/ubuntu
11 # KEYRING_FILE=/usr/share/keyrings/ubuntu-archive-keyring.gpg
12 # DEBIAN_PACKAGES="gcc libz libssl"
14 #@ This script builds a Debian sysroot images for building Google Chrome.
16 #@ Generally this script is invoked as:
17 #@ sysroot-creator-<flavour>.sh <mode> <args>*
18 #@ Available modes are shown below.
22 ######################################################################
24 ######################################################################
29 SCRIPT_DIR
=$
(cd $
(dirname $0) && pwd)
31 if [ -z "${DIST:-}" ]; then
32 echo "error: DIST not defined"
36 if [ -z "${APT_REPO:-}" ]; then
37 echo "error: APT_REPO not defined"
41 if [ -z "${KEYRING_FILE:-}" ]; then
42 echo "error: KEYRING_FILE not defined"
46 if [ -z "${DEBIAN_PACKAGES:-}" ]; then
47 echo "error: DEBIAN_PACKAGES not defined"
51 readonly REPO_BASEDIR
="${APT_REPO}/dists/${DIST}"
53 readonly REQUIRED_TOOLS
="wget"
55 ######################################################################
57 ######################################################################
59 readonly RELEASE_FILE
="Release"
60 readonly RELEASE_FILE_GPG
="Release.gpg"
61 readonly RELEASE_LIST
="${REPO_BASEDIR}/${RELEASE_FILE}"
62 readonly RELEASE_LIST_GPG
="${REPO_BASEDIR}/${RELEASE_FILE_GPG}"
63 readonly PACKAGE_FILE_AMD64
="main/binary-amd64/Packages.bz2"
64 readonly PACKAGE_FILE_I386
="main/binary-i386/Packages.bz2"
65 readonly PACKAGE_FILE_ARM
="main/binary-armhf/Packages.bz2"
66 readonly PACKAGE_FILE_MIPS
="main/binary-mipsel/Packages.bz2"
67 readonly PACKAGE_LIST_AMD64
="${REPO_BASEDIR}/${PACKAGE_FILE_AMD64}"
68 readonly PACKAGE_LIST_I386
="${REPO_BASEDIR}/${PACKAGE_FILE_I386}"
69 readonly PACKAGE_LIST_ARM
="${REPO_BASEDIR}/${PACKAGE_FILE_ARM}"
70 readonly PACKAGE_LIST_MIPS
="${REPO_BASEDIR}/${PACKAGE_FILE_MIPS}"
72 readonly DEBIAN_DEP_LIST_AMD64
="packagelist.${DIST}.amd64"
73 readonly DEBIAN_DEP_LIST_I386
="packagelist.${DIST}.i386"
74 readonly DEBIAN_DEP_LIST_ARM
="packagelist.${DIST}.arm"
75 readonly DEBIAN_DEP_LIST_MIPS
="packagelist.${DIST}.mipsel"
77 ######################################################################
79 ######################################################################
82 echo "######################################################################"
84 echo "######################################################################"
89 echo "----------------------------------------------------------------------"
91 echo "----------------------------------------------------------------------"
96 egrep "^#@" "${BASH_SOURCE[0]}" | cut
--bytes=3-
101 if [ -f "$2" ] ; then
102 echo "$2 already in place"
107 echo "$1" |
grep -qs ^http
:// && HTTP
=1
108 if [ "$HTTP" = "1" ]; then
109 SubBanner
"downloading from $1 -> $2"
110 wget
"$1" -O "${2}.partial"
113 SubBanner
"copying from $1"
119 SetEnvironmentVariables
() {
121 echo $1 |
grep -qs Amd64$
&& ARCH
=AMD64
122 if [ -z "$ARCH" ]; then
123 echo $1 |
grep -qs I386$
&& ARCH
=I386
125 if [ -z "$ARCH" ]; then
126 echo $1 |
grep -qs Mips$
&& ARCH
=MIPS
128 if [ -z "$ARCH" ]; then
129 echo $1 |
grep -qs ARM$
&& ARCH
=ARM
131 if [ -z "${ARCH}" ]; then
132 echo "ERROR: Unable to determine architecture based on: $1"
135 ARCH_LOWER
=$
(echo $ARCH |
tr '[:upper:]' '[:lower:]')
139 # some sanity checks to make sure this script is run from the right place
140 # with the right tools
142 Banner
"Sanity Checks"
144 local chrome_dir
=$
(cd "${SCRIPT_DIR}/../../../.." && pwd)
145 BUILD_DIR
="${chrome_dir}/out/sysroot-build/${DIST}"
146 mkdir
-p ${BUILD_DIR}
147 echo "Using build directory: ${BUILD_DIR}"
149 for tool
in ${REQUIRED_TOOLS} ; do
150 if ! which ${tool} > /dev
/null
; then
151 echo "Required binary $tool not found."
157 # This is where the staging sysroot is.
158 INSTALL_ROOT
="${BUILD_DIR}/${DIST}_${ARCH_LOWER}_staging"
159 TARBALL
="${BUILD_DIR}/${DISTRO}_${DIST}_${ARCH_LOWER}_sysroot.tgz"
161 if ! mkdir
-p "${INSTALL_ROOT}" ; then
162 echo "ERROR: ${INSTALL_ROOT} can't be created."
169 # Change directory to where this script is.
175 Banner
"Clearing dirs in ${INSTALL_ROOT}"
176 rm -rf ${INSTALL_ROOT}/*
181 Banner
"Creating tarball ${TARBALL}"
182 tar zcf
${TARBALL} -C ${INSTALL_ROOT} .
185 ExtractPackageBz2
() {
186 bzcat
"$1" |
egrep '^(Package:|Filename:|SHA256:) ' > "$2"
189 GeneratePackageListAmd64
() {
190 local output_file
="$1"
191 local package_list
="${BUILD_DIR}/Packages.${DIST}_amd64.bz2"
192 local tmp_package_list
="${BUILD_DIR}/Packages.${DIST}_amd64"
193 DownloadOrCopy
"${PACKAGE_LIST_AMD64}" "${package_list}"
194 VerifyPackageListing
"${PACKAGE_FILE_AMD64}" "${package_list}"
195 ExtractPackageBz2
"$package_list" "$tmp_package_list"
196 GeneratePackageList
"$tmp_package_list" "$output_file" "${DEBIAN_PACKAGES}
197 ${DEBIAN_PACKAGES_X86}"
200 GeneratePackageListI386
() {
201 local output_file
="$1"
202 local package_list
="${BUILD_DIR}/Packages.${DIST}_i386.bz2"
203 local tmp_package_list
="${BUILD_DIR}/Packages.${DIST}_amd64"
204 DownloadOrCopy
"${PACKAGE_LIST_I386}" "${package_list}"
205 VerifyPackageListing
"${PACKAGE_FILE_I386}" "${package_list}"
206 ExtractPackageBz2
"$package_list" "$tmp_package_list"
207 GeneratePackageList
"$tmp_package_list" "$output_file" "${DEBIAN_PACKAGES}
208 ${DEBIAN_PACKAGES_X86}"
211 GeneratePackageListARM
() {
212 local output_file
="$1"
213 local package_list
="${BUILD_DIR}/Packages.${DIST}_arm.bz2"
214 local tmp_package_list
="${BUILD_DIR}/Packages.${DIST}_arm"
215 DownloadOrCopy
"${PACKAGE_LIST_ARM}" "${package_list}"
216 VerifyPackageListing
"${PACKAGE_FILE_ARM}" "${package_list}"
217 ExtractPackageBz2
"$package_list" "$tmp_package_list"
218 GeneratePackageList
"$tmp_package_list" "$output_file" "${DEBIAN_PACKAGES}"
221 GeneratePackageListMips
() {
222 local output_file
="$1"
223 local package_list
="${BUILD_DIR}/Packages.${DIST}_mips.bz2"
224 local tmp_package_list
="${BUILD_DIR}/Packages.${DIST}_mips"
225 DownloadOrCopy
"${PACKAGE_LIST_MIPS}" "${package_list}"
226 VerifyPackageListing
"${PACKAGE_FILE_MIPS}" "${package_list}"
227 ExtractPackageBz2
"$package_list" "$tmp_package_list"
228 GeneratePackageList
"$tmp_package_list" "$output_file" "${DEBIAN_PACKAGES}"
231 StripChecksumsFromPackageList
() {
232 local package_file
="$1"
233 sed -i 's/ [a-f0-9]\{64\}$//' "$package_file"
236 VerifyPackageFilesMatch
() {
237 local downloaded_package_file
="$1"
238 local stored_package_file
="$2"
239 diff -u "$downloaded_package_file" "$stored_package_file"
240 if [ "$?" -ne "0" ]; then
241 echo "ERROR: downloaded package files does not match $2."
242 echo "You may need to run UpdatePackageLists."
247 ######################################################################
249 ######################################################################
251 HacksAndPatchesAmd64
() {
252 Banner
"Misc Hacks & Patches"
253 # these are linker scripts with absolute pathnames in them
254 # which we rewrite here
255 lscripts
="${INSTALL_ROOT}/usr/lib/x86_64-linux-gnu/libpthread.so \
256 ${INSTALL_ROOT}/usr/lib/x86_64-linux-gnu/libc.so"
258 # Rewrite linker scripts
259 sed -i -e 's|/usr/lib/x86_64-linux-gnu/||g' ${lscripts}
260 sed -i -e 's|/lib/x86_64-linux-gnu/||g' ${lscripts}
262 # This is for chrome's ./build/linux/pkg-config-wrapper
263 # which overwrites PKG_CONFIG_PATH internally
264 SubBanner
"Package Configs Symlink"
265 mkdir
-p ${INSTALL_ROOT}/usr
/share
266 ln -s ..
/lib
/x86_64-linux-gnu
/pkgconfig
${INSTALL_ROOT}/usr
/share
/pkgconfig
268 SubBanner
"Adding an additional ld.conf include"
269 LD_SO_HACK_CONF
="${INSTALL_ROOT}/etc/ld.so.conf.d/zz_hack.conf"
270 echo /usr
/lib
/gcc
/x86_64-linux-gnu
/4.6 > "$LD_SO_HACK_CONF"
271 echo /usr
/lib
>> "$LD_SO_HACK_CONF"
275 HacksAndPatchesI386
() {
276 Banner
"Misc Hacks & Patches"
277 # these are linker scripts with absolute pathnames in them
278 # which we rewrite here
279 lscripts
="${INSTALL_ROOT}/usr/lib/i386-linux-gnu/libpthread.so \
280 ${INSTALL_ROOT}/usr/lib/i386-linux-gnu/libc.so"
282 # Rewrite linker scripts
283 sed -i -e 's|/usr/lib/i386-linux-gnu/||g' ${lscripts}
284 sed -i -e 's|/lib/i386-linux-gnu/||g' ${lscripts}
286 # This is for chrome's ./build/linux/pkg-config-wrapper
287 # which overwrites PKG_CONFIG_PATH internally
288 SubBanner
"Package Configs Symlink"
289 mkdir
-p ${INSTALL_ROOT}/usr
/share
290 ln -s ..
/lib
/i386-linux-gnu
/pkgconfig
${INSTALL_ROOT}/usr
/share
/pkgconfig
292 SubBanner
"Adding an additional ld.conf include"
293 LD_SO_HACK_CONF
="${INSTALL_ROOT}/etc/ld.so.conf.d/zz_hack.conf"
294 echo /usr
/lib
/gcc
/i486-linux-gnu
/4.6 > "$LD_SO_HACK_CONF"
295 echo /usr
/lib
>> "$LD_SO_HACK_CONF"
299 HacksAndPatchesARM
() {
300 Banner
"Misc Hacks & Patches"
301 # these are linker scripts with absolute pathnames in them
302 # which we rewrite here
303 lscripts
="${INSTALL_ROOT}/usr/lib/arm-linux-gnueabihf/libpthread.so \
304 ${INSTALL_ROOT}/usr/lib/arm-linux-gnueabihf/libc.so"
306 # Rewrite linker scripts
307 sed -i -e 's|/usr/lib/arm-linux-gnueabihf/||g' ${lscripts}
308 sed -i -e 's|/lib/arm-linux-gnueabihf/||g' ${lscripts}
310 # This is for chrome's ./build/linux/pkg-config-wrapper
311 # which overwrites PKG_CONFIG_PATH internally
312 SubBanner
"Package Configs Symlink"
313 mkdir
-p ${INSTALL_ROOT}/usr
/share
314 ln -s ..
/lib
/arm-linux-gnueabihf
/pkgconfig
${INSTALL_ROOT}/usr
/share
/pkgconfig
318 HacksAndPatchesMips
() {
319 Banner
"Misc Hacks & Patches"
320 # these are linker scripts with absolute pathnames in them
321 # which we rewrite here
322 lscripts
="${INSTALL_ROOT}/usr/lib/mipsel-linux-gnu/libpthread.so \
323 ${INSTALL_ROOT}/usr/lib/mipsel-linux-gnu/libc.so"
325 # Rewrite linker scripts
326 sed -i -e 's|/usr/lib/mipsel-linux-gnu/||g' ${lscripts}
327 sed -i -e 's|/lib/mipsel-linux-gnu/||g' ${lscripts}
329 # This is for chrome's ./build/linux/pkg-config-wrapper
330 # which overwrites PKG_CONFIG_PATH internally
331 SubBanner
"Package Configs Symlink"
332 mkdir
-p ${INSTALL_ROOT}/usr
/share
333 ln -s ..
/lib
/mipsel-linux-gnu
/pkgconfig
${INSTALL_ROOT}/usr
/share
/pkgconfig
337 InstallIntoSysroot
() {
338 Banner
"Install Libs And Headers Into Jail"
340 mkdir
-p ${BUILD_DIR}/debian-packages
341 mkdir
-p ${INSTALL_ROOT}
344 local package
="${BUILD_DIR}/debian-packages/${file##*/}"
348 if [ "${#sha256sum}" -ne "64" ]; then
349 echo "Bad sha256sum from package list"
353 Banner
"Installing ${file}"
354 DownloadOrCopy
${APT_REPO}/pool/${file} ${package}
355 if [ ! -s "${package}" ] ; then
357 echo "ERROR: bad package ${package}"
360 echo "${sha256sum} ${package}" | sha256sum
--quiet -c
362 SubBanner
"Extracting to ${INSTALL_ROOT}"
363 dpkg
--fsys-tarfile ${package}\
364 |
tar -xf - --exclude=.
/usr
/share
-C ${INSTALL_ROOT}
369 CleanupJailSymlinks
() {
370 Banner
"Jail symlink cleanup"
374 local libdirs
="lib usr/lib"
375 if [ "${ARCH}" != "MIPS" ]; then
378 find $libdirs -type l
-printf '%p %l\n' |
while read link target
; do
379 # skip links with non-absolute paths
380 echo "${target}" |
grep -qs ^
/ ||
continue
381 echo "${link}: ${target}"
383 usr
/lib
/gcc
/x86_64-linux-gnu
/4.
*/* | usr
/lib
/gcc
/i486-linux-gnu
/4.
*/* | \
384 usr
/lib
/gcc
/arm-linux-gnueabihf
/4.
*/* | \
385 usr
/lib
/gcc
/mipsel-linux-gnu
/4.
*/*)
386 # Relativize the symlink.
387 ln -snfv "../../../../..${target}" "${link}"
389 usr
/lib
/x86_64-linux-gnu
/* | usr
/lib
/i386-linux-gnu
/* | \
390 usr
/lib
/arm-linux-gnueabihf
/* | usr
/lib
/mipsel-linux-gnu
/* )
391 # Relativize the symlink.
392 ln -snfv "../../..${target}" "${link}"
395 # Relativize the symlink.
396 ln -snfv "../..${target}" "${link}"
399 # Relativize the symlink.
400 ln -snfv "..${target}" "${link}"
405 find $libdirs -type l
-printf '%p %l\n' |
while read link target
; do
406 # Make sure we catch new bad links.
407 if [ ! -r "${link}" ]; then
408 echo "ERROR: FOUND BAD LINK ${link}"
419 #@ Build everything and package it
420 BuildSysrootAmd64
() {
422 local package_file
="$BUILD_DIR/package_with_sha256sum_amd64"
423 GeneratePackageListAmd64
"$package_file"
424 local files_and_sha256sums
="$(cat ${package_file})"
425 StripChecksumsFromPackageList
"$package_file"
426 VerifyPackageFilesMatch
"$package_file" "$DEBIAN_DEP_LIST_AMD64"
427 InstallIntoSysroot
${files_and_sha256sums}
436 #@ Build everything and package it
439 local package_file
="$BUILD_DIR/package_with_sha256sum_i386"
440 GeneratePackageListI386
"$package_file"
441 local files_and_sha256sums
="$(cat ${package_file})"
442 StripChecksumsFromPackageList
"$package_file"
443 VerifyPackageFilesMatch
"$package_file" "$DEBIAN_DEP_LIST_I386"
444 InstallIntoSysroot
${files_and_sha256sums}
453 #@ Build everything and package it
456 local package_file
="$BUILD_DIR/package_with_sha256sum_arm"
457 GeneratePackageListARM
"$package_file"
458 local files_and_sha256sums
="$(cat ${package_file})"
459 StripChecksumsFromPackageList
"$package_file"
460 VerifyPackageFilesMatch
"$package_file" "$DEBIAN_DEP_LIST_ARM"
461 APT_REPO
=${APR_REPO_ARM:=$APT_REPO}
462 InstallIntoSysroot
${files_and_sha256sums}
471 #@ Build everything and package it
474 local package_file
="$BUILD_DIR/package_with_sha256sum_arm"
475 GeneratePackageListMips
"$package_file"
476 local files_and_sha256sums
="$(cat ${package_file})"
477 StripChecksumsFromPackageList
"$package_file"
478 VerifyPackageFilesMatch
"$package_file" "$DEBIAN_DEP_LIST_MIPS"
479 APT_REPO
=${APR_REPO_MIPS:=$APT_REPO}
480 InstallIntoSysroot
${files_and_sha256sums}
489 #@ Build sysroot images for all architectures
491 RunCommand BuildSysrootAmd64
492 RunCommand BuildSysrootI386
493 RunCommand BuildSysrootARM
494 RunCommand BuildSysrootMips
499 if [ -z "${rev}" ]; then
500 echo "Please specify a revision to upload at."
504 gsutil
cp -a public-read
"${TARBALL}" \
505 "gs://chrome-linux-sysroot/toolchain/$rev/"
510 #@ UploadSysrootAmd64 <revision>
512 UploadSysrootAmd64
() {
517 #@ UploadSysrootI386 <revision>
519 UploadSysrootI386
() {
524 #@ UploadSysrootARM <revision>
531 #@ UploadSysrootMips <revision>
533 UploadSysrootMips
() {
538 #@ UploadSysrootAll <revision>
540 #@ Upload sysroot image for all architectures
542 RunCommand UploadSysrootAmd64
"$@"
543 RunCommand UploadSysrootI386
"$@"
544 RunCommand UploadSysrootARM
"$@"
545 RunCommand UploadSysrootMips
"$@"
549 # CheckForDebianGPGKeyring
551 # Make sure the Debian GPG keys exist. Otherwise print a helpful message.
553 CheckForDebianGPGKeyring
() {
554 if [ ! -e "$KEYRING_FILE" ]; then
555 echo "Debian GPG keys missing. Install the debian-archive-keyring package."
561 # VerifyPackageListing
563 # Verifies the downloaded Packages.bz2 file has the right checksums.
565 VerifyPackageListing
() {
568 local release_file
="${BUILD_DIR}/${RELEASE_FILE}"
569 local release_file_gpg
="${BUILD_DIR}/${RELEASE_FILE_GPG}"
570 local tmp_keyring_file
="${BUILD_DIR}/keyring.gpg"
572 CheckForDebianGPGKeyring
574 DownloadOrCopy
${RELEASE_LIST} ${release_file}
575 DownloadOrCopy
${RELEASE_LIST_GPG} ${release_file_gpg}
576 echo "Verifying: ${release_file} with ${release_file_gpg}"
577 cp "${KEYRING_FILE}" "${tmp_keyring_file}"
578 gpg
--primary-keyring "${tmp_keyring_file}" --recv-keys 2B90D010
579 gpgv
--keyring "${tmp_keyring_file}" "${release_file_gpg}" "${release_file}"
581 echo "Verifying: ${output_file}"
582 local checksums
=$
(grep ${file_path} ${release_file} | cut
-d " " -f 2)
583 local sha256sum
=$
(echo ${checksums} | cut
-d " " -f 3)
585 if [ "${#sha256sum}" -ne "64" ]; then
586 echo "Bad sha256sum from ${RELEASE_LIST}"
590 echo "${sha256sum} ${output_file}" | sha256sum
--quiet -c
594 # GeneratePackageList
596 # Looks up package names in ${BUILD_DIR}/Packages and write list of URLs
599 GeneratePackageList
() {
600 local input_file
="$1"
601 local output_file
="$2"
602 echo "Updating: ${output_file} from ${input_file}"
603 /bin
/rm -f "${output_file}"
607 local pkg_full
=$
(grep -A 1 " ${pkg}\$" "$input_file" | \
609 if [ -z "${pkg_full}" ]; then
610 echo "ERROR: missing package: $pkg"
613 local pkg_nopool
=$
(echo "$pkg_full" |
sed "s/^pool\///")
614 local sha256sum
=$
(grep -A 4 " ${pkg}\$" "$input_file" | \
615 grep ^SHA256
: |
sed 's/^SHA256: //')
616 if [ "${#sha256sum}" -ne "64" ]; then
617 echo "Bad sha256sum from Packages"
620 echo $pkg_nopool $sha256sum >> "$output_file"
622 # sort -o does an in-place sort of this file
623 sort "$output_file" -o "$output_file"
627 #@ UpdatePackageListsAmd64
629 #@ Regenerate the package lists such that they contain an up-to-date
630 #@ list of URLs within the Debian archive. (For amd64)
631 UpdatePackageListsAmd64
() {
632 GeneratePackageListAmd64
"$DEBIAN_DEP_LIST_AMD64"
633 StripChecksumsFromPackageList
"$DEBIAN_DEP_LIST_AMD64"
637 #@ UpdatePackageListsI386
639 #@ Regenerate the package lists such that they contain an up-to-date
640 #@ list of URLs within the Debian archive. (For i386)
641 UpdatePackageListsI386
() {
642 GeneratePackageListI386
"$DEBIAN_DEP_LIST_I386"
643 StripChecksumsFromPackageList
"$DEBIAN_DEP_LIST_I386"
647 #@ UpdatePackageListsARM
649 #@ Regenerate the package lists such that they contain an up-to-date
650 #@ list of URLs within the Debian archive. (For arm)
651 UpdatePackageListsARM
() {
652 GeneratePackageListARM
"$DEBIAN_DEP_LIST_ARM"
653 StripChecksumsFromPackageList
"$DEBIAN_DEP_LIST_ARM"
657 #@ UpdatePackageListsMips
659 #@ Regenerate the package lists such that they contain an up-to-date
660 #@ list of URLs within the Debian archive. (For arm)
661 UpdatePackageListsMips
() {
662 GeneratePackageListMips
"$DEBIAN_DEP_LIST_MIPS"
663 StripChecksumsFromPackageList
"$DEBIAN_DEP_LIST_MIPS"
667 #@ UpdatePackageListsAll
669 #@ Regenerate the package lists for all architectures.
670 UpdatePackageListsAll
() {
671 RunCommand UpdatePackageListsAmd64
672 RunCommand UpdatePackageListsI386
673 RunCommand UpdatePackageListsARM
674 RunCommand UpdatePackageListsMips
678 SetEnvironmentVariables
"$1"
683 if [ $# -eq 0 ] ; then
684 echo "ERROR: you must specify a mode on the commandline"
688 elif [ "$(type -t $1)" != "function" ]; then
689 echo "ERROR: unknown function '$1'." >&2
690 echo "For help, try:"
695 if echo $1 |
grep -qs "All$"; then