blob: 39cb16ee0a80232ca6fc143dd1f792be55736135 [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"
David James855afb72012-03-14 20:04:59 -070024
25# The following options are advanced options, only available to those willing
26# to read the source code. They are not shown in help output, since they are
27# not needed for the typical developer workflow.
David James184e3902012-02-23 20:19:28 -080028DEFINE_integer jobs -1 \
29 "How many packages to build in parallel at maximum."
Zdenek Behan2fbd5af2012-03-12 19:38:50 +010030DEFINE_boolean skip_toolchain_update $FLAGS_FALSE \
31 "Don't update the toolchains."
Mike Frysinger7f2ebbd2012-06-01 21:41:27 -040032DEFINE_string toolchain_boards "" \
33 "Extra toolchains to setup for the specified boards."
Mike Frysinger237117b2017-10-19 12:42:09 -040034DEFINE_boolean eclean ${FLAGS_TRUE} \
35 "Run eclean to delete old binpkgs after updating the chroot."
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
Alex Kleine5e0ea92018-09-13 17:18:15 -060048run_chroot_version_hooks
Zdenek Behan308e9fd2011-05-12 22:25:47 +020049
Gilad Arnoldfbc41112015-04-07 08:43:43 +030050info "Updating chroot"
51
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080052# Create /etc/make.conf.host_setup. The file content is regenerated
53# from scratch every update. There are various reasons to do this:
54# + It's cheap, so this is an easy way to guarantee correct content
55# after an upgrade.
56# + Inside make_chroot.sh, we use a temporary version of the file
57# which must be updated before the script completes; that final
58# update happens here.
59# + If the repositories change to add or remove the private
60# overlay, the file may need to be regenerated.
61create_host_setup
David Jamese996baa2011-11-02 16:11:27 -070062
Chris Masonebbccc242014-02-08 16:23:53 -080063sudo_clear_shadow_locks /
64
Mike Frysingerc405e7b2014-11-14 13:39:22 -050065# First make sure the cross-compilers have the right config settings.
66# We don't actually build them yet though as we want to wait for the
67# sdk to have all up-to-date packages.
Zdenek Behan2fbd5af2012-03-12 19:38:50 +010068if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_FALSE}" ]; then
Mike Frysingerc405e7b2014-11-14 13:39:22 -050069 info "Updating cross-compilers"
70 TOOLCHAIN_FLAGS=()
Zdenek Behan42184b42012-05-30 19:42:31 +020071
Mike Frysingerc405e7b2014-11-14 13:39:22 -050072 if [[ -n ${FLAGS_toolchain_boards} ]]; then
73 TOOLCHAIN_FLAGS+=(
74 "--targets=boards"
75 "--include-boards=${FLAGS_toolchain_boards}"
76 )
77 fi
78
Zdenek Behan2fbd5af2012-03-12 19:38:50 +010079 # This should really only be skipped while bootstrapping.
80 if [ "${FLAGS_usepkg}" -eq "${FLAGS_FALSE}" ]; then
Mike Frysinger5e2e2732012-08-22 17:18:36 -040081 TOOLCHAIN_FLAGS+=( --nousepkg )
Zdenek Behan2fbd5af2012-03-12 19:38:50 +010082 fi
83 # Expand the path before sudo, as root doesn't have the same path magic.
Mike Frysinger5cf035f2021-01-26 00:57:46 -050084 info_run sudo -E $(type -p cros_setup_toolchains) "${TOOLCHAIN_FLAGS[@]}"
Zdenek Behan4748e872011-10-11 03:23:11 +020085fi
86
Nicolas Boichat03a63052017-12-01 14:51:27 +080087# Make sure depot_tools is bootstrapped, so that it can build chromeos-chrome.
88info "Bootstrapping depot_tools"
Mike Frysingerbb90b652019-08-09 18:52:05 -040089# depot_tools doesn't support Python 3 at all.
90# TODO(crbug.com/984182): Drop EPYTHON setting if they ever finish.
91EPYTHON="python2" ensure_bootstrap
Nicolas Boichat03a63052017-12-01 14:51:27 +080092
Mike Frysinger61157612019-08-17 13:29:28 -040093# Perform an update of all the sdk packages in the chroot.
94EMERGE_CMD="${CHROMITE_BIN}/parallel_emerge"
Chris McDonaldac5d8632019-10-23 15:55:45 -060095
96info "Rebuilding Portage cache"
97# Before running any emerge operations, regenerate the Portage dependency cache
98# in parallel.
Mike Frysinger5cf035f2021-01-26 00:57:46 -050099info_run "${EMERGE_CMD[@]}" --regen --quiet
Chris McDonaldac5d8632019-10-23 15:55:45 -0600100
Mike Frysingerc405e7b2014-11-14 13:39:22 -0500101info "Updating the SDK"
102
Mike Frysinger697ab962019-11-04 20:02:43 -0500103EMERGE_FLAGS=( -uNv --with-bdeps=y )
Gilad Arnoldfbc41112015-04-07 08:43:43 +0300104if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
Mike Frysingerdf308252017-06-15 21:54:53 -0400105 EMERGE_FLAGS+=( --getbinpkg )
Gilad Arnoldfbc41112015-04-07 08:43:43 +0300106
107 # Only update toolchain when binpkgs are available. Toolchain rollout
108 # process only takes place when the chromiumos sdk builder finishes
109 # a successful build.
Mike Frysingerd0e4af72017-09-13 00:24:34 -0400110 PACKAGES=(
111 $("${CHROMITE_BIN}/cros_setup_toolchains" --show-packages host)
112 )
113 # Sanity check we got some valid results.
114 [[ ${#PACKAGES[@]} -eq 0 ]] && die_notrace "cros_setup_toolchains failed"
Manoj Gupta661fb772018-04-12 22:04:35 -0700115 # Update post cross-packages. This is needed to update rust.
116 PACKAGES+=(
117 $("${CHROMITE_BIN}/cros_setup_toolchains" --show-packages host-post-cross)
118 )
Mike Frysingerdf308252017-06-15 21:54:53 -0400119 EMERGE_FLAGS+=(
Mike Frysingerd0e4af72017-09-13 00:24:34 -0400120 $(printf ' --useoldpkg-atoms=%s' "${PACKAGES[@]}")
Mike Frysingerdf308252017-06-15 21:54:53 -0400121 )
Gilad Arnoldfbc41112015-04-07 08:43:43 +0300122fi
Gilad Arnoldfbc41112015-04-07 08:43:43 +0300123if [[ "${FLAGS_jobs}" -ne -1 ]]; then
Mike Frysingerdf308252017-06-15 21:54:53 -0400124 EMERGE_FLAGS+=( --jobs="${FLAGS_jobs}" )
Gilad Arnoldfbc41112015-04-07 08:43:43 +0300125fi
126
David James85dd1402012-06-07 14:55:46 -0700127# Build cros_workon packages when they are changed.
128for pkg in $("${CHROMITE_BIN}/cros_list_modified_packages" --host); do
Mike Frysingerdf308252017-06-15 21:54:53 -0400129 EMERGE_FLAGS+=( --reinstall-atoms="${pkg}" --usepkg-exclude="${pkg}" )
David James85dd1402012-06-07 14:55:46 -0700130done
131
Zdenek Behan4748e872011-10-11 03:23:11 +0200132# Second pass, update everything else.
Mike Frysingerdf308252017-06-15 21:54:53 -0400133EMERGE_FLAGS+=( --deep )
Mike Frysinger5cf035f2021-01-26 00:57:46 -0500134info_run sudo -E ${EMERGE_CMD} "${EMERGE_FLAGS[@]}" virtual/target-sdk world
Zdenek Behand7bfd862011-05-11 23:56:46 +0200135
Manoj Gupta48535332018-04-12 22:04:35 -0700136# Install post cross packages if binary pkgs are available.
137if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
Benjamin Gordonaefd3d92018-10-16 10:21:09 -0600138 # Install nobdeps packages only when binary pkgs are available, since we don't
139 # want to accidentally pull in build deps for a rebuild.
140 EMERGE_FLAGS=( -uNv --with-bdeps=n --oneshot --getbinpkg --deep --usepkgonly )
Mike Frysinger5cf035f2021-01-26 00:57:46 -0500141 info_run sudo -E "${EMERGE_CMD}" "${EMERGE_FLAGS[@]}" \
142 virtual/target-sdk-nobdeps
Manoj Gupta48535332018-04-12 22:04:35 -0700143fi
144
Zdenek Behan99fb7422011-10-17 01:12:34 +0200145# Automatically discard all CONFIG_PROTECT'ed files. Those that are
146# protected should not be overwritten until the variable is changed.
147# Autodiscard is option "-9" followed by the "YES" confirmation.
148printf '%s\nYES\n' -9 | sudo etc-update
149
David Jamesd899f8d2011-08-17 05:22:52 -0700150# If the user still has old perl modules installed, update them.
Ben Chan0c9da662017-05-15 17:29:51 -0700151"${SCRIPTS_DIR}/build_library/perl_rebuild.sh"
Matt Tennant0a9d32d2012-07-30 16:51:37 -0700152
Mike Frysinger237117b2017-10-19 12:42:09 -0400153# Finally clean out any stale binpkgs we've accumulated.
154if [[ ${FLAGS_eclean} -eq ${FLAGS_TRUE} ]]; then
Mike Frysinger5cf035f2021-01-26 00:57:46 -0500155 info "Cleaning stale binpkgs"
156 info_run sudo eclean -d packages
Mike Frysinger237117b2017-10-19 12:42:09 -0400157fi
158
Matt Tennant0a9d32d2012-07-30 16:51:37 -0700159command_completed