blob: fa518e5b310c961917b938ff2ddfba2ac4b2dd34 [file] [log] [blame]
Zdenek Behand7bfd862011-05-11 23:56:46 +02001#!/bin/bash
2
Matt Tennant0a9d32d2012-07-30 16:51:37 -07003# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Zdenek Behand7bfd862011-05-11 23:56:46 +02004# 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 Behan2fbd5af2012-03-12 19:38:50 +010032DEFINE_boolean skip_toolchain_update $FLAGS_FALSE \
33 "Don't update the toolchains."
Mike Frysinger7f2ebbd2012-06-01 21:41:27 -040034DEFINE_string toolchain_boards "" \
35 "Extra toolchains to setup for the specified boards."
Zdenek Behand7bfd862011-05-11 23:56:46 +020036
37# Parse command line flags
38FLAGS "$@" || exit 1
39eval set -- "${FLAGS_ARGV}"
40
41# Only now can we die on error. shflags functions leak non-zero error codes,
Brian Harring7f175a52012-03-02 05:37:00 -080042# so will die prematurely if 'switch_to_strict_mode' is specified before now.
43switch_to_strict_mode
Zdenek Behand7bfd862011-05-11 23:56:46 +020044
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080045. ${SCRIPTS_DIR}/sdk_lib/make_conf_util.sh
46
Zdenek Behan308e9fd2011-05-12 22:25:47 +020047# Run version hooks as pre-update
48${SCRIPTS_DIR}/run_chroot_version_hooks
49
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080050# Create /etc/make.conf.host_setup. The file content is regenerated
51# from scratch every update. There are various reasons to do this:
52# + It's cheap, so this is an easy way to guarantee correct content
53# after an upgrade.
54# + Inside make_chroot.sh, we use a temporary version of the file
55# which must be updated before the script completes; that final
56# update happens here.
57# + If the repositories change to add or remove the private
58# overlay, the file may need to be regenerated.
59create_host_setup
David Jamese996baa2011-11-02 16:11:27 -070060
Zdenek Behand7bfd862011-05-11 23:56:46 +020061info "Updating chroot"
62
Mike Frysinger650bf872012-02-27 11:05:26 -050063EMERGE_FLAGS="-uNv --with-bdeps=y --select"
Zdenek Behan95626202011-05-12 05:54:19 +020064if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
65 EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg"
David James0dccff32011-06-09 13:03:47 -070066
67 # Only update toolchain when binpkgs are available. Toolchain rollout
68 # process only takes place when the chromiumos sdk builder finishes
69 # a successful build.
70 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/binutils"
71 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/gcc"
72 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-libs/glibc"
Zdenek Behan95626202011-05-12 05:54:19 +020073fi
Zdenek Behana29fb202011-05-12 05:21:14 +020074
David James184e3902012-02-23 20:19:28 -080075if [[ "${FLAGS_jobs}" -ne -1 ]]; then
76 EMERGE_FLAGS+=" --jobs=${FLAGS_jobs}"
77fi
78
Zdenek Behand7bfd862011-05-11 23:56:46 +020079# Perform an update of hard-host-depends and world in the chroot.
80EMERGE_CMD="emerge"
David James85dd1402012-06-07 14:55:46 -070081CHROMITE_BIN="${GCLIENT_ROOT}/chromite/bin"
Zdenek Behand7bfd862011-05-11 23:56:46 +020082if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
David James85dd1402012-06-07 14:55:46 -070083 EMERGE_CMD="${CHROMITE_BIN}/parallel_emerge"
Zdenek Behand7bfd862011-05-11 23:56:46 +020084fi
Zdenek Behan95626202011-05-12 05:54:19 +020085
Zdenek Behan4748e872011-10-11 03:23:11 +020086# In first pass, update portage and toolchains. Lagged updates of both
87# can cause serious issues later.
Zdenek Behan2fbd5af2012-03-12 19:38:50 +010088if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_FALSE}" ]; then
Zdenek Behan42184b42012-05-30 19:42:31 +020089 # First update crossdev.
90 sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} crossdev
91
Mike Frysinger5e2e2732012-08-22 17:18:36 -040092 TOOLCHAIN_FLAGS=( "--include-boards=${FLAGS_toolchain_boards}" )
Zdenek Behan2fbd5af2012-03-12 19:38:50 +010093 # This should really only be skipped while bootstrapping.
94 if [ "${FLAGS_usepkg}" -eq "${FLAGS_FALSE}" ]; then
Mike Frysinger5e2e2732012-08-22 17:18:36 -040095 TOOLCHAIN_FLAGS+=( --nousepkg )
Zdenek Behan2fbd5af2012-03-12 19:38:50 +010096 fi
97 # Expand the path before sudo, as root doesn't have the same path magic.
Ahmad Sharif89b8a8b2012-09-21 20:12:45 -070098 sudo -E $(type -p cros_setup_toolchains) "${TOOLCHAIN_FLAGS[@]}"
Zdenek Behan4748e872011-10-11 03:23:11 +020099fi
100
David James85dd1402012-06-07 14:55:46 -0700101# Build cros_workon packages when they are changed.
102for pkg in $("${CHROMITE_BIN}/cros_list_modified_packages" --host); do
103 EMERGE_FLAGS+=" --reinstall-atoms=${pkg} --usepkg-exclude=${pkg}"
104done
105
Zdenek Behan4748e872011-10-11 03:23:11 +0200106# Second pass, update everything else.
107EMERGE_FLAGS+=" --deep"
David James855afb72012-03-14 20:04:59 -0700108sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \
Zdenek Behana29fb202011-05-12 05:21:14 +0200109 chromeos-base/hard-host-depends world
Zdenek Behand7bfd862011-05-11 23:56:46 +0200110
Zdenek Behan99fb7422011-10-17 01:12:34 +0200111# Automatically discard all CONFIG_PROTECT'ed files. Those that are
112# protected should not be overwritten until the variable is changed.
113# Autodiscard is option "-9" followed by the "YES" confirmation.
114printf '%s\nYES\n' -9 | sudo etc-update
115
Mike Frysinger67b495b2013-03-19 01:55:39 -0400116cmds=()
117
David Jamesd899f8d2011-08-17 05:22:52 -0700118# If the user still has old perl modules installed, update them.
119PERL_VERSIONS=$(find /usr/lib*/perl5/vendor_perl/ -maxdepth 1 -mindepth 1 \
120 -type d -printf '%P\n' | sort -u | wc -w)
121if [ "$PERL_VERSIONS" -gt 1 ] ; then
Mike Frysinger67b495b2013-03-19 01:55:39 -0400122 cmds+=( 'perl-cleaner --all -- --quiet' )
David Jamesd899f8d2011-08-17 05:22:52 -0700123fi
Matt Tennant0a9d32d2012-07-30 16:51:37 -0700124
Mike Frysinger67b495b2013-03-19 01:55:39 -0400125# If we've got multiple versions of python installed, clear them out.
126PYTHON_VERSIONS=( $(qlist -ICv -e dev-lang/python | sort -nr) )
127if [[ ${#PYTHON_VERSIONS[@]} -gt 1 ]]; then
128 info "Cleaning up system python"
129 cmds+=(
130 # Make sure we have the latest version selected.
131 'eselect python update'
132 # Unmerge all the older versions.
133 "CLEAN_DELAY=0 emerge -Cq ${PYTHON_VERSIONS[*]:1}"
134 # Make sure chromite can be found.
135 'rm -f /usr/lib64/python*/site-packages/chromite'
136 "ln -sf /mnt/host/source/chromite \
137 /usr/lib64/python$(eselect python show --ABI)/site-packages/chromite"
138 )
139fi
140
141# If the user still has old python modules installed, update them.
142PYTHON_VERSIONS=$(ls -d /usr/lib*/python*/ | cut -d/ -f4 | sort -u | wc -w)
143if [[ ${PYTHON_VERSIONS} -gt 1 ]]; then
144 PY_UPDATE_FLAGS=()
145 if [[ "${FLAGS_jobs}" -ne -1 ]]; then
146 PY_UPDATE_FLAGS+=( --jobs=${FLAGS_jobs} )
147 fi
148 cmds+=(
149 "python-updater --package-manager-command ${EMERGE_CMD} -- \
150 ${PY_UPDATE_FLAGS[*]}"
Mike Frysingera937b4c2013-03-25 16:37:48 -0400151 )
152
153 # python-updater does not handle /usr/local, so do it ourselves.
154 # We have to run this after python-updater though since these packages
155 # might rely on other dev-python stuff in /usr.
156 pkgs=( $(qfile -qC /usr/local/lib*/python* | sort -u) )
157 if [[ ${#pkgs[@]} -gt 0 ]]; then
158 cmds+=( "${EMERGE_CMD} ${PY_UPDATE_FLAGS[*]} ${pkgs[*]}" )
159 fi
160
161 cmds+=(
Mike Frysinger67b495b2013-03-19 01:55:39 -0400162 # Remove empty dirs if possible.
Mike Frysingera937b4c2013-03-25 16:37:48 -0400163 'rmdir /usr/local/lib*/python*/site-packages /usr/local/lib*/python*/ \
164 /usr/lib*/python*/site-packages /usr/lib*/python*/ 2>/dev/null || :'
Mike Frysinger67b495b2013-03-19 01:55:39 -0400165 )
166fi
167
168sudo_multi "${cmds[@]}"
169
Matt Tennant0a9d32d2012-07-30 16:51:37 -0700170command_completed