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." |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 35 | |
| 36 | # Parse command line flags |
| 37 | FLAGS "$@" || exit 1 |
| 38 | eval set -- "${FLAGS_ARGV}" |
| 39 | |
| 40 | # 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] | 41 | # so will die prematurely if 'switch_to_strict_mode' is specified before now. |
| 42 | switch_to_strict_mode |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 43 | |
J. Richard Barnette | e80f6de | 2012-02-24 14:08:34 -0800 | [diff] [blame] | 44 | . ${SCRIPTS_DIR}/sdk_lib/make_conf_util.sh |
| 45 | |
Zdenek Behan | 308e9fd | 2011-05-12 22:25:47 +0200 | [diff] [blame] | 46 | # Run version hooks as pre-update |
| 47 | ${SCRIPTS_DIR}/run_chroot_version_hooks |
| 48 | |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 49 | info "Updating chroot" |
| 50 | |
J. Richard Barnette | e80f6de | 2012-02-24 14:08:34 -0800 | [diff] [blame] | 51 | # 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. |
| 60 | create_host_setup |
David James | e996baa | 2011-11-02 16:11:27 -0700 | [diff] [blame] | 61 | |
Chris Masone | bbccc24 | 2014-02-08 16:23:53 -0800 | [diff] [blame] | 62 | sudo_clear_shadow_locks / |
| 63 | |
Mike Frysinger | c405e7b | 2014-11-14 13:39:22 -0500 | [diff] [blame] | 64 | # 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 Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 67 | if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_FALSE}" ]; then |
Mike Frysinger | c405e7b | 2014-11-14 13:39:22 -0500 | [diff] [blame] | 68 | info "Updating cross-compilers" |
| 69 | TOOLCHAIN_FLAGS=() |
Zdenek Behan | 42184b4 | 2012-05-30 19:42:31 +0200 | [diff] [blame] | 70 | |
Mike Frysinger | c405e7b | 2014-11-14 13:39:22 -0500 | [diff] [blame] | 71 | if [[ -n ${FLAGS_toolchain_boards} ]]; then |
| 72 | TOOLCHAIN_FLAGS+=( |
| 73 | "--targets=boards" |
| 74 | "--include-boards=${FLAGS_toolchain_boards}" |
| 75 | ) |
| 76 | fi |
| 77 | |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 78 | # This should really only be skipped while bootstrapping. |
| 79 | if [ "${FLAGS_usepkg}" -eq "${FLAGS_FALSE}" ]; then |
Mike Frysinger | 5e2e273 | 2012-08-22 17:18:36 -0400 | [diff] [blame] | 80 | TOOLCHAIN_FLAGS+=( --nousepkg ) |
Zdenek Behan | 2fbd5af | 2012-03-12 19:38:50 +0100 | [diff] [blame] | 81 | fi |
| 82 | # 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] | 83 | sudo -E $(type -p cros_setup_toolchains) "${TOOLCHAIN_FLAGS[@]}" |
Zdenek Behan | 4748e87 | 2011-10-11 03:23:11 +0200 | [diff] [blame] | 84 | fi |
| 85 | |
Mike Frysinger | c405e7b | 2014-11-14 13:39:22 -0500 | [diff] [blame] | 86 | info "Updating the SDK" |
| 87 | |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 88 | # Perform an update of all the sdk packages in the chroot. |
| 89 | CHROMITE_BIN="${GCLIENT_ROOT}/chromite/bin" |
| 90 | EMERGE_CMD="${CHROMITE_BIN}/parallel_emerge" |
| 91 | |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame^] | 92 | EMERGE_FLAGS=( -uNv --with-bdeps=y --select ) |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 93 | if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame^] | 94 | EMERGE_FLAGS+=( --getbinpkg ) |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 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. |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame^] | 99 | EMERGE_FLAGS+=( |
| 100 | --useoldpkg-atoms=dev-lang/go |
| 101 | --useoldpkg-atoms=sys-devel/binutils |
| 102 | --useoldpkg-atoms=sys-devel/clang |
| 103 | --useoldpkg-atoms=sys-devel/gcc |
| 104 | --useoldpkg-atoms=sys-devel/llvm |
| 105 | --useoldpkg-atoms=sys-libs/glibc |
| 106 | ) |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 107 | fi |
| 108 | |
| 109 | if [[ "${FLAGS_jobs}" -ne -1 ]]; then |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame^] | 110 | EMERGE_FLAGS+=( --jobs="${FLAGS_jobs}" ) |
Gilad Arnold | fbc4111 | 2015-04-07 08:43:43 +0300 | [diff] [blame] | 111 | fi |
| 112 | |
David James | 85dd140 | 2012-06-07 14:55:46 -0700 | [diff] [blame] | 113 | # Build cros_workon packages when they are changed. |
| 114 | for pkg in $("${CHROMITE_BIN}/cros_list_modified_packages" --host); do |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame^] | 115 | EMERGE_FLAGS+=( --reinstall-atoms="${pkg}" --usepkg-exclude="${pkg}" ) |
David James | 85dd140 | 2012-06-07 14:55:46 -0700 | [diff] [blame] | 116 | done |
| 117 | |
Zdenek Behan | 4748e87 | 2011-10-11 03:23:11 +0200 | [diff] [blame] | 118 | # Second pass, update everything else. |
Mike Frysinger | df30825 | 2017-06-15 21:54:53 -0400 | [diff] [blame^] | 119 | EMERGE_FLAGS+=( --deep ) |
| 120 | sudo -E ${EMERGE_CMD} "${EMERGE_FLAGS[@]}" virtual/target-sdk world |
Zdenek Behan | d7bfd86 | 2011-05-11 23:56:46 +0200 | [diff] [blame] | 121 | |
Zdenek Behan | 99fb742 | 2011-10-17 01:12:34 +0200 | [diff] [blame] | 122 | # Automatically discard all CONFIG_PROTECT'ed files. Those that are |
| 123 | # protected should not be overwritten until the variable is changed. |
| 124 | # Autodiscard is option "-9" followed by the "YES" confirmation. |
| 125 | printf '%s\nYES\n' -9 | sudo etc-update |
| 126 | |
David James | d899f8d | 2011-08-17 05:22:52 -0700 | [diff] [blame] | 127 | # If the user still has old perl modules installed, update them. |
Ben Chan | 0c9da66 | 2017-05-15 17:29:51 -0700 | [diff] [blame] | 128 | "${SCRIPTS_DIR}/build_library/perl_rebuild.sh" |
Matt Tennant | 0a9d32d | 2012-07-30 16:51:37 -0700 | [diff] [blame] | 129 | |
| 130 | command_completed |