blob: b0825391b32217391d8b9cf43f0bc55847c24af9 [file] [log] [blame]
Zdenek Behand7bfd862011-05-11 23:56:46 +02001#!/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
7# Performs an update of the chroot.
8
9# Load common CrOS utilities. Inside the chroot this file is installed in
10# /usr/lib/crosutils. Outside the chroot we find it relative to the script's
11# location.
Brian Harringd5d5dbf2011-07-11 16:36:21 -070012. "$(dirname $0)/common.sh" || { echo "Unable to load common.sh"; exit 1; }
Zdenek Behand7bfd862011-05-11 23:56:46 +020013
14# Script must run inside the chroot
15assert_inside_chroot "$@"
16
Zdenek Behan308e9fd2011-05-12 22:25:47 +020017# Do not run as root
18assert_not_root_user
19
Zdenek Behand7bfd862011-05-11 23:56:46 +020020# Flags
21DEFINE_boolean usepkg $FLAGS_TRUE \
22 "Use binary packages to bootstrap."
23DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel"
24DEFINE_integer retries -1 \
25 "On build failure, the number of times to retry."
David James184e3902012-02-23 20:19:28 -080026DEFINE_integer jobs -1 \
27 "How many packages to build in parallel at maximum."
Zdenek Behand7bfd862011-05-11 23:56:46 +020028
29# Parse command line flags
30FLAGS "$@" || exit 1
31eval set -- "${FLAGS_ARGV}"
32
33# Only now can we die on error. shflags functions leak non-zero error codes,
34# so will die prematurely if 'set -e' is specified before now.
35set -e
36
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080037. ${SCRIPTS_DIR}/sdk_lib/make_conf_util.sh
38
Zdenek Behan308e9fd2011-05-12 22:25:47 +020039# Run version hooks as pre-update
40${SCRIPTS_DIR}/run_chroot_version_hooks
41
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080042# Create /etc/make.conf.host_setup. The file content is regenerated
43# from scratch every update. There are various reasons to do this:
44# + It's cheap, so this is an easy way to guarantee correct content
45# after an upgrade.
46# + Inside make_chroot.sh, we use a temporary version of the file
47# which must be updated before the script completes; that final
48# update happens here.
49# + If the repositories change to add or remove the private
50# overlay, the file may need to be regenerated.
51create_host_setup
David Jamese996baa2011-11-02 16:11:27 -070052
Zdenek Behand7bfd862011-05-11 23:56:46 +020053info "Updating chroot"
54
Mike Frysinger650bf872012-02-27 11:05:26 -050055EMERGE_FLAGS="-uNv --with-bdeps=y --select"
Zdenek Behan95626202011-05-12 05:54:19 +020056if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
57 EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg"
David James0dccff32011-06-09 13:03:47 -070058
59 # Only update toolchain when binpkgs are available. Toolchain rollout
60 # process only takes place when the chromiumos sdk builder finishes
61 # a successful build.
62 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/binutils"
63 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/gcc"
64 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-libs/glibc"
Zdenek Behan95626202011-05-12 05:54:19 +020065fi
Zdenek Behana29fb202011-05-12 05:21:14 +020066
David James184e3902012-02-23 20:19:28 -080067if [[ "${FLAGS_jobs}" -ne -1 ]]; then
68 EMERGE_FLAGS+=" --jobs=${FLAGS_jobs}"
69fi
70
Zdenek Behand7bfd862011-05-11 23:56:46 +020071# Perform an update of hard-host-depends and world in the chroot.
72EMERGE_CMD="emerge"
73if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
74 EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge"
75fi
Zdenek Behan95626202011-05-12 05:54:19 +020076
Zdenek Behan4748e872011-10-11 03:23:11 +020077# In first pass, update portage and toolchains. Lagged updates of both
78# can cause serious issues later.
79CHOST="$(portageq envvar CHOST)"
80LATEST="$(gcc-config -l | grep "${CHOST}" | awk '{ print $2 }' | \
81 sort -V | tail -n 1 )"
82CURRENT="$(gcc-config -c)" || true # This fails if current profile is invalid.
83eretry sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \
84 sys-devel/gcc sys-devel/binutils sys-libs/glibc sys-apps/portage
85# If the latest toolchain wasn't already selected before we updated, do nothing,
86# otherwise autoselect the latest. Also fix if the current profile is invalid.
87if [ "${LATEST}" = "${CURRENT}" ] || ! gcc-config -c &> /dev/null; then
88 LATEST="$(gcc-config -l | grep "${CHOST}" | awk '{ print $2 }' | \
89 sort -V | tail -n 1 )"
90 sudo gcc-config "${LATEST}"
91fi
92
93# Second pass, update everything else.
94EMERGE_FLAGS+=" --deep"
Zdenek Behana29fb202011-05-12 05:21:14 +020095eretry sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \
96 chromeos-base/hard-host-depends world
Zdenek Behand7bfd862011-05-11 23:56:46 +020097
Zdenek Behan99fb7422011-10-17 01:12:34 +020098# Automatically discard all CONFIG_PROTECT'ed files. Those that are
99# protected should not be overwritten until the variable is changed.
100# Autodiscard is option "-9" followed by the "YES" confirmation.
101printf '%s\nYES\n' -9 | sudo etc-update
102
David Jamesd899f8d2011-08-17 05:22:52 -0700103# If the user still has old perl modules installed, update them.
104PERL_VERSIONS=$(find /usr/lib*/perl5/vendor_perl/ -maxdepth 1 -mindepth 1 \
105 -type d -printf '%P\n' | sort -u | wc -w)
106if [ "$PERL_VERSIONS" -gt 1 ] ; then
Mike Frysinger43a7f692012-02-28 16:20:47 -0500107 sudo perl-cleaner --all -- --quiet
David Jamesd899f8d2011-08-17 05:22:52 -0700108fi