blob: 265704342a50e8dbcbc099ea9d46b1de42b4c300 [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
Zdenek Behand7bfd862011-05-11 23:56:46 +02007
David James0b1baf62012-03-15 09:26:23 -07008. "$(dirname "$0")/common.sh" || exit 1
Zdenek Behand7bfd862011-05-11 23:56:46 +02009
10# Script must run inside the chroot
11assert_inside_chroot "$@"
12
Zdenek Behan308e9fd2011-05-12 22:25:47 +020013# Do not run as root
14assert_not_root_user
15
David James855afb72012-03-14 20:04:59 -070016# Developer-visible flags.
Zdenek Behand7bfd862011-05-11 23:56:46 +020017DEFINE_boolean usepkg $FLAGS_TRUE \
18 "Use binary packages to bootstrap."
David James855afb72012-03-14 20:04:59 -070019
20FLAGS_HELP="usage: $(basename $0) [flags]
21Performs an update of the chroot. This script is called as part of
22build_packages, so there is typically no need to call this script directly.
23"
24show_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 Behand7bfd862011-05-11 23:56:46 +020029DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel"
David James184e3902012-02-23 20:19:28 -080030DEFINE_integer jobs -1 \
31 "How many packages to build in parallel at maximum."
Zdenek Behan95fadc62012-03-12 19:38:50 +010032DEFINE_boolean skip_toolchain_update $FLAGS_FALSE \
33 "Don't update the toolchains."
Zdenek Behand7bfd862011-05-11 23:56:46 +020034
35# Parse command line flags
36FLAGS "$@" || exit 1
37eval set -- "${FLAGS_ARGV}"
38
39# Only now can we die on error. shflags functions leak non-zero error codes,
40# so will die prematurely if 'set -e' is specified before now.
41set -e
42
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080043. ${SCRIPTS_DIR}/sdk_lib/make_conf_util.sh
44
Zdenek Behan308e9fd2011-05-12 22:25:47 +020045# Run version hooks as pre-update
46${SCRIPTS_DIR}/run_chroot_version_hooks
47
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080048# Create /etc/make.conf.host_setup. The file content is regenerated
49# from scratch every update. There are various reasons to do this:
50# + It's cheap, so this is an easy way to guarantee correct content
51# after an upgrade.
52# + Inside make_chroot.sh, we use a temporary version of the file
53# which must be updated before the script completes; that final
54# update happens here.
55# + If the repositories change to add or remove the private
56# overlay, the file may need to be regenerated.
57create_host_setup
David Jamese996baa2011-11-02 16:11:27 -070058
Zdenek Behand7bfd862011-05-11 23:56:46 +020059info "Updating chroot"
60
Mike Frysinger650bf872012-02-27 11:05:26 -050061EMERGE_FLAGS="-uNv --with-bdeps=y --select"
Zdenek Behan95626202011-05-12 05:54:19 +020062if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
63 EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg"
David James0dccff32011-06-09 13:03:47 -070064
65 # Only update toolchain when binpkgs are available. Toolchain rollout
66 # process only takes place when the chromiumos sdk builder finishes
67 # a successful build.
68 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/binutils"
69 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/gcc"
70 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-libs/glibc"
Zdenek Behan95626202011-05-12 05:54:19 +020071fi
Zdenek Behana29fb202011-05-12 05:21:14 +020072
David James184e3902012-02-23 20:19:28 -080073if [[ "${FLAGS_jobs}" -ne -1 ]]; then
74 EMERGE_FLAGS+=" --jobs=${FLAGS_jobs}"
75fi
76
Zdenek Behand7bfd862011-05-11 23:56:46 +020077# Perform an update of hard-host-depends and world in the chroot.
78EMERGE_CMD="emerge"
79if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
80 EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge"
81fi
Zdenek Behan95626202011-05-12 05:54:19 +020082
Zdenek Behan4748e872011-10-11 03:23:11 +020083# In first pass, update portage and toolchains. Lagged updates of both
84# can cause serious issues later.
Zdenek Behan95fadc62012-03-12 19:38:50 +010085if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_FALSE}" ]; then
86 TOOLCHAIN_FLAGS=""
87 # This should really only be skipped while bootstrapping.
88 if [ "${FLAGS_usepkg}" -eq "${FLAGS_FALSE}" ]; then
89 TOOLCHAIN_FLAGS="--nousepkg"
90 fi
91 # Expand the path before sudo, as root doesn't have the same path magic.
92 sudo $(type -p cros_setup_toolchains) ${TOOLCHAIN_FLAGS}
Zdenek Behan4748e872011-10-11 03:23:11 +020093fi
94
95# Second pass, update everything else.
96EMERGE_FLAGS+=" --deep"
David James855afb72012-03-14 20:04:59 -070097sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \
Zdenek Behana29fb202011-05-12 05:21:14 +020098 chromeos-base/hard-host-depends world
Zdenek Behand7bfd862011-05-11 23:56:46 +020099
Zdenek Behan99fb7422011-10-17 01:12:34 +0200100# Automatically discard all CONFIG_PROTECT'ed files. Those that are
101# protected should not be overwritten until the variable is changed.
102# Autodiscard is option "-9" followed by the "YES" confirmation.
103printf '%s\nYES\n' -9 | sudo etc-update
104
David Jamesd899f8d2011-08-17 05:22:52 -0700105# If the user still has old perl modules installed, update them.
106PERL_VERSIONS=$(find /usr/lib*/perl5/vendor_perl/ -maxdepth 1 -mindepth 1 \
107 -type d -printf '%P\n' | sort -u | wc -w)
108if [ "$PERL_VERSIONS" -gt 1 ] ; then
Mike Frysinger43a7f692012-02-28 16:20:47 -0500109 sudo perl-cleaner --all -- --quiet
David Jamesd899f8d2011-08-17 05:22:52 -0700110fi