Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Matt Tennant | 0a9d32d | 2012-07-30 16:51:37 -0700 | [diff] [blame] | 3 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 7 | |
David James | 0b1baf6 | 2012-03-15 09:26:23 -0700 | [diff] [blame] | 8 | . "$(dirname "$0")/common.sh" || exit 1 |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 9 | |
| 10 | # Script must run inside the chroot |
| 11 | assert_inside_chroot "$@" |
| 12 | |
Zdenek Behan | 308e9fd | 2011-05-12 22:25:47 +0200 | [diff] [blame] | 13 | # Do not run as root |
| 14 | assert_not_root_user |
| 15 | |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 16 | # Developer-visible flags. |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 17 | DEFINE_boolean usepkg $FLAGS_TRUE \ |
| 18 | "Use binary packages to bootstrap." |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 19 | |
| 20 | FLAGS_HELP="usage: $(basename $0) [flags] |
| 21 | Performs an update of the chroot. This script is called as part of |
| 22 | build_packages, so there is typically no need to call this script directly. |
| 23 | " |
| 24 | show_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 James | 184e390 | 2012-02-23 20:19:28 -0800 | [diff] [blame] | 29 | DEFINE_integer jobs -1 \ |
| 30 | "How many packages to build in parallel at maximum." |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 31 | DEFINE_boolean skip_toolchain_update $FLAGS_FALSE \ |
| 32 | "Don't update the toolchains." |
Mike Frysinger | 7f2ebbd | 2012-06-01 21:41:27 -0400 | [diff] [blame] | 33 | DEFINE_string toolchain_boards "" \ |
| 34 | "Extra toolchains to setup for the specified boards." |
Mike Frysinger | 237117b | 2017-10-19 12:42:09 -0400 | [diff] [blame] | 35 | DEFINE_boolean eclean ${FLAGS_TRUE} \ |
| 36 | "Run eclean to delete old binpkgs after updating the chroot." |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 37 | |
| 38 | # Parse command line flags |
| 39 | FLAGS "$@" || exit 1 |
| 40 | eval set -- "${FLAGS_ARGV}" |
| 41 | |
| 42 | # Only now can we die on error. shflags functions leak non-zero error codes, |
Brian Harring | 7f175a5 | 2012-03-02 05:37:00 -0800 | [diff] [blame] | 43 | # so will die prematurely if 'switch_to_strict_mode' is specified before now. |
| 44 | switch_to_strict_mode |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 45 | |
J. Richard Barnette | e80f6de | 2012-02-24 14:08:34 -0800 | [diff] [blame] | 46 | . ${SCRIPTS_DIR}/sdk_lib/make_conf_util.sh |
| 47 | |
Zdenek Behan | 308e9fd | 2011-05-12 22:25:47 +0200 | [diff] [blame] | 48 | # Run version hooks as pre-update |
Alex Klein | e5e0ea9 | 2018-09-13 17:18:15 -0600 | [diff] [blame] | 49 | run_chroot_version_hooks |
Zdenek Behan | 308e9fd | 2011-05-12 22:25:47 +0200 | [diff] [blame] | 50 | |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 51 | info "Updating chroot" |
| 52 | |
J. Richard Barnette | e80f6de | 2012-02-24 14:08:34 -0800 | [diff] [blame] | 53 | # Create /etc/make.conf.host_setup. The file content is regenerated |
| 54 | # from scratch every update. There are various reasons to do this: |
| 55 | # + It's cheap, so this is an easy way to guarantee correct content |
| 56 | # after an upgrade. |
| 57 | # + Inside make_chroot.sh, we use a temporary version of the file |
| 58 | # which must be updated before the script completes; that final |
| 59 | # update happens here. |
| 60 | # + If the repositories change to add or remove the private |
| 61 | # overlay, the file may need to be regenerated. |
| 62 | create_host_setup |
David James | e996baa | 2011-11-02 16:11:27 -0700 | [diff] [blame] | 63 | |
Chris Masone | bbccc24 | 2014-02-08 16:23:53 -0800 | [diff] [blame] | 64 | sudo_clear_shadow_locks / |
| 65 | |
Mike Frysinger | c405e7b | 2014-11-14 13:39:22 -0500 | [diff] [blame] | 66 | # First make sure the cross-compilers have the right config settings. |
| 67 | # We don't actually build them yet though as we want to wait for the |
| 68 | # sdk to have all up-to-date packages. |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 69 | if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_FALSE}" ]; then |
Mike Frysinger | c405e7b | 2014-11-14 13:39:22 -0500 | [diff] [blame] | 70 | info "Updating cross-compilers" |
| 71 | TOOLCHAIN_FLAGS=() |
Zdenek Behan | 42184b4 | 2012-05-30 19:42:31 +0200 | [diff] [blame] | 72 | |
Mike Frysinger | c405e7b | 2014-11-14 13:39:22 -0500 | [diff] [blame] | 73 | if [[ -n ${FLAGS_toolchain_boards} ]]; then |
| 74 | TOOLCHAIN_FLAGS+=( |
| 75 | "--targets=boards" |
| 76 | "--include-boards=${FLAGS_toolchain_boards}" |
| 77 | ) |
| 78 | fi |
| 79 | |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 80 | # This should really only be skipped while bootstrapping. |
| 81 | if [ "${FLAGS_usepkg}" -eq "${FLAGS_FALSE}" ]; then |
Mike Frysinger | 5e2e273 | 2012-08-22 17:18:36 -0400 | [diff] [blame] | 82 | TOOLCHAIN_FLAGS+=( --nousepkg ) |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 83 | fi |
| 84 | # Expand the path before sudo, as root doesn't have the same path magic. |
Ahmad Sharif | 89b8a8b | 2012-09-21 20:12:45 -0700 | [diff] [blame] | 85 | sudo -E $(type -p cros_setup_toolchains) "${TOOLCHAIN_FLAGS[@]}" |
Zdenek Behan | 4748e87 | 2011-10-11 03:23:11 +0200 | [diff] [blame] | 86 | fi |
| 87 | |
Nicolas Boichat | 03a6305 | 2017-12-01 14:51:27 +0800 | [diff] [blame] | 88 | # Make sure depot_tools is bootstrapped, so that it can build chromeos-chrome. |
| 89 | info "Bootstrapping depot_tools" |
| 90 | ensure_bootstrap |
| 91 | |
Mike Frysinger | c405e7b | 2014-11-14 13:39:22 -0500 | [diff] [blame] | 92 | info "Updating the SDK" |
| 93 | |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 94 | # Perform an update of all the sdk packages in the chroot. |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 95 | EMERGE_CMD="${CHROMITE_BIN}/parallel_emerge" |
| 96 | |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame] | 97 | EMERGE_FLAGS=( -uNv --with-bdeps=y --select ) |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 98 | if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame] | 99 | EMERGE_FLAGS+=( --getbinpkg ) |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 100 | |
| 101 | # Only update toolchain when binpkgs are available. Toolchain rollout |
| 102 | # process only takes place when the chromiumos sdk builder finishes |
| 103 | # a successful build. |
Mike Frysinger | d0e4af7 | 2017-09-13 00:24:34 -0400 | [diff] [blame] | 104 | PACKAGES=( |
| 105 | $("${CHROMITE_BIN}/cros_setup_toolchains" --show-packages host) |
| 106 | ) |
| 107 | # Sanity check we got some valid results. |
| 108 | [[ ${#PACKAGES[@]} -eq 0 ]] && die_notrace "cros_setup_toolchains failed" |
Manoj Gupta | 661fb77 | 2018-04-12 22:04:35 -0700 | [diff] [blame] | 109 | # Update post cross-packages. This is needed to update rust. |
| 110 | PACKAGES+=( |
| 111 | $("${CHROMITE_BIN}/cros_setup_toolchains" --show-packages host-post-cross) |
| 112 | ) |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame] | 113 | EMERGE_FLAGS+=( |
Mike Frysinger | d0e4af7 | 2017-09-13 00:24:34 -0400 | [diff] [blame] | 114 | $(printf ' --useoldpkg-atoms=%s' "${PACKAGES[@]}") |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame] | 115 | ) |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 116 | fi |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 117 | if [[ "${FLAGS_jobs}" -ne -1 ]]; then |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame] | 118 | EMERGE_FLAGS+=( --jobs="${FLAGS_jobs}" ) |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 119 | fi |
| 120 | |
David James | 85dd140 | 2012-06-07 14:55:46 -0700 | [diff] [blame] | 121 | # Build cros_workon packages when they are changed. |
| 122 | for pkg in $("${CHROMITE_BIN}/cros_list_modified_packages" --host); do |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame] | 123 | EMERGE_FLAGS+=( --reinstall-atoms="${pkg}" --usepkg-exclude="${pkg}" ) |
David James | 85dd140 | 2012-06-07 14:55:46 -0700 | [diff] [blame] | 124 | done |
| 125 | |
Zdenek Behan | 4748e87 | 2011-10-11 03:23:11 +0200 | [diff] [blame] | 126 | # Second pass, update everything else. |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame] | 127 | EMERGE_FLAGS+=( --deep ) |
Manoj Gupta | f8fcdca | 2018-04-13 04:47:27 +0000 | [diff] [blame] | 128 | sudo -E ${EMERGE_CMD} "${EMERGE_FLAGS[@]}" virtual/target-sdk world |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 129 | |
Manoj Gupta | 4853533 | 2018-04-12 22:04:35 -0700 | [diff] [blame] | 130 | # Install post cross packages if binary pkgs are available. |
| 131 | if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then |
| 132 | # Use --usepkgonly to ensure that packages are not built from source. |
| 133 | EMERGE_FLAGS=( -uNv --with-bdeps=y --select --getbinpkg --deep --usepkgonly ) |
| 134 | EMERGE_FLAGS+=( |
| 135 | $("${CHROMITE_BIN}/cros_setup_toolchains" --show-packages host-post-cross) |
| 136 | ) |
| 137 | sudo -E ${EMERGE_CMD} "${EMERGE_FLAGS[@]}" |
Benjamin Gordon | aefd3d9 | 2018-10-16 10:21:09 -0600 | [diff] [blame] | 138 | |
| 139 | # Install nobdeps packages only when binary pkgs are available, since we don't |
| 140 | # want to accidentally pull in build deps for a rebuild. |
| 141 | EMERGE_FLAGS=( -uNv --with-bdeps=n --oneshot --getbinpkg --deep --usepkgonly ) |
| 142 | sudo -E "${EMERGE_CMD}" "${EMERGE_FLAGS[@]}" virtual/target-sdk-nobdeps |
Manoj Gupta | 4853533 | 2018-04-12 22:04:35 -0700 | [diff] [blame] | 143 | fi |
| 144 | |
Zdenek Behan | 99fb742 | 2011-10-17 01:12:34 +0200 | [diff] [blame] | 145 | # 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. |
| 148 | printf '%s\nYES\n' -9 | sudo etc-update |
| 149 | |
David James | d899f8d | 2011-08-17 05:22:52 -0700 | [diff] [blame] | 150 | # If the user still has old perl modules installed, update them. |
Ben Chan | 0c9da66 | 2017-05-15 17:29:51 -0700 | [diff] [blame] | 151 | "${SCRIPTS_DIR}/build_library/perl_rebuild.sh" |
Matt Tennant | 0a9d32d | 2012-07-30 16:51:37 -0700 | [diff] [blame] | 152 | |
Mike Frysinger | 237117b | 2017-10-19 12:42:09 -0400 | [diff] [blame] | 153 | # Finally clean out any stale binpkgs we've accumulated. |
| 154 | if [[ ${FLAGS_eclean} -eq ${FLAGS_TRUE} ]]; then |
| 155 | info "Running 'eclean -d packages' to clean up stale binpkgs" |
| 156 | sudo eclean -d packages |
| 157 | fi |
| 158 | |
Matt Tennant | 0a9d32d | 2012-07-30 16:51:37 -0700 | [diff] [blame] | 159 | command_completed |