blob: 333a03f9661c1c79ea9a3f7944d53715fc48ec5d [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.
David James184e3902012-02-23 20:19:28 -080029DEFINE_integer jobs -1 \
30 "How many packages to build in parallel at maximum."
Zdenek Behan2fbd5af2012-03-12 19:38:50 +010031DEFINE_boolean skip_toolchain_update $FLAGS_FALSE \
32 "Don't update the toolchains."
Mike Frysinger7f2ebbd2012-06-01 21:41:27 -040033DEFINE_string toolchain_boards "" \
34 "Extra toolchains to setup for the specified boards."
Zdenek Behand7bfd862011-05-11 23:56:46 +020035
36# Parse command line flags
37FLAGS "$@" || exit 1
38eval set -- "${FLAGS_ARGV}"
39
40# Only now can we die on error. shflags functions leak non-zero error codes,
Brian Harring7f175a52012-03-02 05:37:00 -080041# so will die prematurely if 'switch_to_strict_mode' is specified before now.
42switch_to_strict_mode
Zdenek Behand7bfd862011-05-11 23:56:46 +020043
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080044. ${SCRIPTS_DIR}/sdk_lib/make_conf_util.sh
45
Zdenek Behan308e9fd2011-05-12 22:25:47 +020046# Run version hooks as pre-update
47${SCRIPTS_DIR}/run_chroot_version_hooks
48
Gilad Arnoldfbc41112015-04-07 08:43:43 +030049info "Updating chroot"
50
J. Richard Barnettee80f6de2012-02-24 14:08:34 -080051# Create /etc/make.conf.host_setup. The file content is regenerated
52# from scratch every update. There are various reasons to do this:
53# + It's cheap, so this is an easy way to guarantee correct content
54# after an upgrade.
55# + Inside make_chroot.sh, we use a temporary version of the file
56# which must be updated before the script completes; that final
57# update happens here.
58# + If the repositories change to add or remove the private
59# overlay, the file may need to be regenerated.
60create_host_setup
David Jamese996baa2011-11-02 16:11:27 -070061
Chris Masonebbccc242014-02-08 16:23:53 -080062sudo_clear_shadow_locks /
63
Mike Frysingerc405e7b2014-11-14 13:39:22 -050064# First make sure the cross-compilers have the right config settings.
65# We don't actually build them yet though as we want to wait for the
66# sdk to have all up-to-date packages.
Zdenek Behan2fbd5af2012-03-12 19:38:50 +010067if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_FALSE}" ]; then
Mike Frysingerc405e7b2014-11-14 13:39:22 -050068 info "Updating cross-compilers"
69 TOOLCHAIN_FLAGS=()
Zdenek Behan42184b42012-05-30 19:42:31 +020070
Mike Frysingerc405e7b2014-11-14 13:39:22 -050071 if [[ -n ${FLAGS_toolchain_boards} ]]; then
72 TOOLCHAIN_FLAGS+=(
73 "--targets=boards"
74 "--include-boards=${FLAGS_toolchain_boards}"
75 )
76 fi
77
Zdenek Behan2fbd5af2012-03-12 19:38:50 +010078 # This should really only be skipped while bootstrapping.
79 if [ "${FLAGS_usepkg}" -eq "${FLAGS_FALSE}" ]; then
Mike Frysinger5e2e2732012-08-22 17:18:36 -040080 TOOLCHAIN_FLAGS+=( --nousepkg )
Zdenek Behan2fbd5af2012-03-12 19:38:50 +010081 fi
82 # Expand the path before sudo, as root doesn't have the same path magic.
Ahmad Sharif89b8a8b2012-09-21 20:12:45 -070083 sudo -E $(type -p cros_setup_toolchains) "${TOOLCHAIN_FLAGS[@]}"
Zdenek Behan4748e872011-10-11 03:23:11 +020084fi
85
Mike Frysingerc405e7b2014-11-14 13:39:22 -050086info "Updating the SDK"
87
Gilad Arnoldfbc41112015-04-07 08:43:43 +030088# Perform an update of all the sdk packages in the chroot.
89CHROMITE_BIN="${GCLIENT_ROOT}/chromite/bin"
90EMERGE_CMD="${CHROMITE_BIN}/parallel_emerge"
91
92EMERGE_FLAGS="-uNv --with-bdeps=y --select"
93if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
94 EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg"
95
96 # Only update toolchain when binpkgs are available. Toolchain rollout
97 # process only takes place when the chromiumos sdk builder finishes
98 # a successful build.
Rahul Chaudhry42c86af2015-07-31 11:13:03 -070099 EMERGE_FLAGS+=" --useoldpkg-atoms=dev-lang/go"
Gilad Arnoldfbc41112015-04-07 08:43:43 +0300100 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/binutils"
101 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/gcc"
102 EMERGE_FLAGS+=" --useoldpkg-atoms=sys-libs/glibc"
103fi
104
105if [[ "${FLAGS_jobs}" -ne -1 ]]; then
106 EMERGE_FLAGS+=" --jobs=${FLAGS_jobs}"
107fi
108
David James85dd1402012-06-07 14:55:46 -0700109# Build cros_workon packages when they are changed.
110for pkg in $("${CHROMITE_BIN}/cros_list_modified_packages" --host); do
111 EMERGE_FLAGS+=" --reinstall-atoms=${pkg} --usepkg-exclude=${pkg}"
112done
113
Zdenek Behan4748e872011-10-11 03:23:11 +0200114# Second pass, update everything else.
115EMERGE_FLAGS+=" --deep"
Mike Frysinger0bf12792014-03-22 01:46:42 -0400116sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} virtual/target-sdk world
Zdenek Behand7bfd862011-05-11 23:56:46 +0200117
Zdenek Behan99fb7422011-10-17 01:12:34 +0200118# Automatically discard all CONFIG_PROTECT'ed files. Those that are
119# protected should not be overwritten until the variable is changed.
120# Autodiscard is option "-9" followed by the "YES" confirmation.
121printf '%s\nYES\n' -9 | sudo etc-update
122
David Jamesd899f8d2011-08-17 05:22:52 -0700123# If the user still has old perl modules installed, update them.
124PERL_VERSIONS=$(find /usr/lib*/perl5/vendor_perl/ -maxdepth 1 -mindepth 1 \
125 -type d -printf '%P\n' | sort -u | wc -w)
126if [ "$PERL_VERSIONS" -gt 1 ] ; then
Mike Frysingerae030a32014-10-05 20:54:45 -0400127 # Some perl packages might not exist anymore due to the upgrade, so unmerge
128 # any that no longer exist.
129 info "Looking for outdated perl packages"
130 pkgs=()
131 for pkg in $(qlist -IC dev-perl/ perl-core/ virtual/perl-); do
132 equery which ${pkg} >/dev/null || pkgs+=( "${pkg}" )
133 done
134 if [[ ${#pkgs[@]} -gt 0 ]]; then
135 sudo qmerge -Uyq "${pkgs[@]}"
136 fi
Mike Frysinger27cb1542013-03-27 22:11:44 -0400137 sudo perl-cleaner --all -- --quiet
David Jamesd899f8d2011-08-17 05:22:52 -0700138fi
Matt Tennant0a9d32d2012-07-30 16:51:37 -0700139
140command_completed