Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 7 | |
David James | 0b1baf6 | 2012-03-15 09:26:23 -0700 | [diff] [blame] | 8 | . "$(dirname "$0")/common.sh" || exit 1 |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 9 | |
| 10 | # Script must run inside the chroot |
| 11 | assert_inside_chroot "$@" |
| 12 | |
Zdenek Behan | 308e9fd | 2011-05-12 22:25:47 +0200 | [diff] [blame] | 13 | # Do not run as root |
| 14 | assert_not_root_user |
| 15 | |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 16 | # Developer-visible flags. |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 17 | DEFINE_boolean usepkg $FLAGS_TRUE \ |
| 18 | "Use binary packages to bootstrap." |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 19 | |
| 20 | FLAGS_HELP="usage: $(basename $0) [flags] |
| 21 | Performs an update of the chroot. This script is called as part of |
| 22 | build_packages, so there is typically no need to call this script directly. |
| 23 | " |
| 24 | show_help_if_requested "$@" |
| 25 | |
| 26 | # The following options are advanced options, only available to those willing |
| 27 | # to read the source code. They are not shown in help output, since they are |
| 28 | # not needed for the typical developer workflow. |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 29 | DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel" |
David James | 184e390 | 2012-02-23 20:19:28 -0800 | [diff] [blame] | 30 | DEFINE_integer jobs -1 \ |
| 31 | "How many packages to build in parallel at maximum." |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 32 | |
| 33 | # Parse command line flags |
| 34 | FLAGS "$@" || exit 1 |
| 35 | eval set -- "${FLAGS_ARGV}" |
| 36 | |
| 37 | # Only now can we die on error. shflags functions leak non-zero error codes, |
| 38 | # so will die prematurely if 'set -e' is specified before now. |
| 39 | set -e |
| 40 | |
J. Richard Barnette | e80f6de | 2012-02-24 14:08:34 -0800 | [diff] [blame] | 41 | . ${SCRIPTS_DIR}/sdk_lib/make_conf_util.sh |
| 42 | |
Zdenek Behan | 308e9fd | 2011-05-12 22:25:47 +0200 | [diff] [blame] | 43 | # Run version hooks as pre-update |
| 44 | ${SCRIPTS_DIR}/run_chroot_version_hooks |
| 45 | |
J. Richard Barnette | e80f6de | 2012-02-24 14:08:34 -0800 | [diff] [blame] | 46 | # Create /etc/make.conf.host_setup. The file content is regenerated |
| 47 | # from scratch every update. There are various reasons to do this: |
| 48 | # + It's cheap, so this is an easy way to guarantee correct content |
| 49 | # after an upgrade. |
| 50 | # + Inside make_chroot.sh, we use a temporary version of the file |
| 51 | # which must be updated before the script completes; that final |
| 52 | # update happens here. |
| 53 | # + If the repositories change to add or remove the private |
| 54 | # overlay, the file may need to be regenerated. |
| 55 | create_host_setup |
David James | e996baa | 2011-11-02 16:11:27 -0700 | [diff] [blame] | 56 | |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 57 | info "Updating chroot" |
| 58 | |
Mike Frysinger | 650bf87 | 2012-02-27 11:05:26 -0500 | [diff] [blame] | 59 | EMERGE_FLAGS="-uNv --with-bdeps=y --select" |
Zdenek Behan | 9562620 | 2011-05-12 05:54:19 +0200 | [diff] [blame] | 60 | if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then |
| 61 | EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg" |
David James | 0dccff3 | 2011-06-09 13:03:47 -0700 | [diff] [blame] | 62 | |
| 63 | # Only update toolchain when binpkgs are available. Toolchain rollout |
| 64 | # process only takes place when the chromiumos sdk builder finishes |
| 65 | # a successful build. |
| 66 | EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/binutils" |
| 67 | EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/gcc" |
| 68 | EMERGE_FLAGS+=" --useoldpkg-atoms=sys-libs/glibc" |
Zdenek Behan | 9562620 | 2011-05-12 05:54:19 +0200 | [diff] [blame] | 69 | fi |
Zdenek Behan | a29fb20 | 2011-05-12 05:21:14 +0200 | [diff] [blame] | 70 | |
David James | 184e390 | 2012-02-23 20:19:28 -0800 | [diff] [blame] | 71 | if [[ "${FLAGS_jobs}" -ne -1 ]]; then |
| 72 | EMERGE_FLAGS+=" --jobs=${FLAGS_jobs}" |
| 73 | fi |
| 74 | |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 75 | # Perform an update of hard-host-depends and world in the chroot. |
| 76 | EMERGE_CMD="emerge" |
| 77 | if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then |
| 78 | EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge" |
| 79 | fi |
Zdenek Behan | 9562620 | 2011-05-12 05:54:19 +0200 | [diff] [blame] | 80 | |
Zdenek Behan | 4748e87 | 2011-10-11 03:23:11 +0200 | [diff] [blame] | 81 | # In first pass, update portage and toolchains. Lagged updates of both |
| 82 | # can cause serious issues later. |
Zdenek Behan | 26fe570 | 2012-05-03 15:05:33 -0700 | [diff] [blame^] | 83 | export CHOST="$(portageq envvar CHOST)" |
| 84 | LATEST=$(gcc-config -l | awk -v chost="${CHOST}" '$2 ~ chost { print $2 }' | \ |
| 85 | sort -V | tail -n 1) |
| 86 | CURRENT="$(gcc-config -c)" || true # This fails if current profile is invalid. |
| 87 | sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \ |
| 88 | sys-devel/gcc sys-devel/binutils sys-libs/glibc sys-apps/portage |
| 89 | # If the latest toolchain wasn't already selected before we updated, do nothing, |
| 90 | # otherwise autoselect the latest. Also fix if the current profile is invalid. |
| 91 | if [ "${LATEST}" != "${CURRENT}" ] || ! gcc-config -c &> /dev/null; then |
| 92 | LATEST=$(gcc-config -l | awk -v chost="${CHOST}" '$2 ~ chost { print $2 }' | \ |
| 93 | sort -V | tail -n 1 ) |
| 94 | sudo -E gcc-config "${LATEST}" |
Zdenek Behan | 4748e87 | 2011-10-11 03:23:11 +0200 | [diff] [blame] | 95 | fi |
| 96 | |
| 97 | # Second pass, update everything else. |
| 98 | EMERGE_FLAGS+=" --deep" |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 99 | sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \ |
Zdenek Behan | a29fb20 | 2011-05-12 05:21:14 +0200 | [diff] [blame] | 100 | chromeos-base/hard-host-depends world |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 101 | |
Zdenek Behan | 99fb742 | 2011-10-17 01:12:34 +0200 | [diff] [blame] | 102 | # Automatically discard all CONFIG_PROTECT'ed files. Those that are |
| 103 | # protected should not be overwritten until the variable is changed. |
| 104 | # Autodiscard is option "-9" followed by the "YES" confirmation. |
| 105 | printf '%s\nYES\n' -9 | sudo etc-update |
| 106 | |
David James | d899f8d | 2011-08-17 05:22:52 -0700 | [diff] [blame] | 107 | # If the user still has old perl modules installed, update them. |
| 108 | PERL_VERSIONS=$(find /usr/lib*/perl5/vendor_perl/ -maxdepth 1 -mindepth 1 \ |
| 109 | -type d -printf '%P\n' | sort -u | wc -w) |
| 110 | if [ "$PERL_VERSIONS" -gt 1 ] ; then |
Mike Frysinger | 43a7f69 | 2012-02-28 16:20:47 -0500 | [diff] [blame] | 111 | sudo perl-cleaner --all -- --quiet |
David James | d899f8d | 2011-08-17 05:22:52 -0700 | [diff] [blame] | 112 | fi |