| #!/bin/bash |
| |
| # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| |
| . "$(dirname "$0")/common.sh" || exit 1 |
| |
| # Script must run inside the chroot |
| assert_inside_chroot "$@" |
| |
| # Do not run as root |
| assert_not_root_user |
| |
| # Developer-visible flags. |
| DEFINE_boolean usepkg $FLAGS_TRUE \ |
| "Use binary packages to bootstrap." |
| |
| FLAGS_HELP="usage: $(basename $0) [flags] |
| Performs an update of the chroot. This script is called as part of |
| build_packages, so there is typically no need to call this script directly. |
| " |
| show_help_if_requested "$@" |
| |
| # The following options are advanced options, only available to those willing |
| # to read the source code. They are not shown in help output, since they are |
| # not needed for the typical developer workflow. |
| DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel" |
| DEFINE_integer jobs -1 \ |
| "How many packages to build in parallel at maximum." |
| DEFINE_boolean skip_toolchain_update $FLAGS_FALSE \ |
| "Don't update the toolchains." |
| DEFINE_string toolchain_boards "" \ |
| "Extra toolchains to setup for the specified boards." |
| |
| # Parse command line flags |
| FLAGS "$@" || exit 1 |
| eval set -- "${FLAGS_ARGV}" |
| |
| # Only now can we die on error. shflags functions leak non-zero error codes, |
| # so will die prematurely if 'switch_to_strict_mode' is specified before now. |
| switch_to_strict_mode |
| |
| . ${SCRIPTS_DIR}/sdk_lib/make_conf_util.sh |
| |
| # Run version hooks as pre-update |
| ${SCRIPTS_DIR}/run_chroot_version_hooks |
| |
| # Create /etc/make.conf.host_setup. The file content is regenerated |
| # from scratch every update. There are various reasons to do this: |
| # + It's cheap, so this is an easy way to guarantee correct content |
| # after an upgrade. |
| # + Inside make_chroot.sh, we use a temporary version of the file |
| # which must be updated before the script completes; that final |
| # update happens here. |
| # + If the repositories change to add or remove the private |
| # overlay, the file may need to be regenerated. |
| create_host_setup |
| |
| info "Updating chroot" |
| |
| EMERGE_FLAGS="-uNv --with-bdeps=y --select" |
| if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then |
| EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg" |
| |
| # Only update toolchain when binpkgs are available. Toolchain rollout |
| # process only takes place when the chromiumos sdk builder finishes |
| # a successful build. |
| EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/binutils" |
| EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/gcc" |
| EMERGE_FLAGS+=" --useoldpkg-atoms=sys-libs/glibc" |
| fi |
| |
| if [[ "${FLAGS_jobs}" -ne -1 ]]; then |
| EMERGE_FLAGS+=" --jobs=${FLAGS_jobs}" |
| fi |
| |
| # Perform an update of hard-host-depends and world in the chroot. |
| EMERGE_CMD="emerge" |
| CHROMITE_BIN="${GCLIENT_ROOT}/chromite/bin" |
| if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then |
| EMERGE_CMD="${CHROMITE_BIN}/parallel_emerge" |
| fi |
| |
| # In first pass, update portage and toolchains. Lagged updates of both |
| # can cause serious issues later. |
| if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_FALSE}" ]; then |
| # First update crossdev. |
| sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} crossdev |
| |
| TOOLCHAIN_FLAGS=( "--include-boards=${FLAGS_toolchain_boards}" ) |
| # This should really only be skipped while bootstrapping. |
| if [ "${FLAGS_usepkg}" -eq "${FLAGS_FALSE}" ]; then |
| TOOLCHAIN_FLAGS+=( --nousepkg ) |
| fi |
| # Expand the path before sudo, as root doesn't have the same path magic. |
| sudo -E $(type -p cros_setup_toolchains) "${TOOLCHAIN_FLAGS[@]}" |
| fi |
| |
| # Build cros_workon packages when they are changed. |
| for pkg in $("${CHROMITE_BIN}/cros_list_modified_packages" --host); do |
| EMERGE_FLAGS+=" --reinstall-atoms=${pkg} --usepkg-exclude=${pkg}" |
| done |
| |
| # Second pass, update everything else. |
| EMERGE_FLAGS+=" --deep" |
| sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \ |
| chromeos-base/hard-host-depends world |
| |
| # Automatically discard all CONFIG_PROTECT'ed files. Those that are |
| # protected should not be overwritten until the variable is changed. |
| # Autodiscard is option "-9" followed by the "YES" confirmation. |
| printf '%s\nYES\n' -9 | sudo etc-update |
| |
| cmds=() |
| |
| # If the user still has old perl modules installed, update them. |
| PERL_VERSIONS=$(find /usr/lib*/perl5/vendor_perl/ -maxdepth 1 -mindepth 1 \ |
| -type d -printf '%P\n' | sort -u | wc -w) |
| if [ "$PERL_VERSIONS" -gt 1 ] ; then |
| cmds+=( 'perl-cleaner --all -- --quiet' ) |
| fi |
| |
| # If we've got multiple versions of python installed, clear them out. |
| PYTHON_VERSIONS=( $(qlist -ICv -e dev-lang/python | sort -nr) ) |
| if [[ ${#PYTHON_VERSIONS[@]} -gt 1 ]]; then |
| info "Cleaning up system python" |
| cmds+=( |
| # Make sure we have the latest version selected. |
| 'eselect python update' |
| # Unmerge all the older versions. |
| "CLEAN_DELAY=0 emerge -Cq ${PYTHON_VERSIONS[*]:1}" |
| # Make sure chromite can be found. |
| 'rm -f /usr/lib64/python*/site-packages/chromite' |
| "ln -sf /mnt/host/source/chromite \ |
| /usr/lib64/python$(eselect python show --ABI)/site-packages/chromite" |
| ) |
| fi |
| |
| # If the user still has old python modules installed, update them. |
| PYTHON_VERSIONS=$(ls -d /usr/lib*/python*/ | cut -d/ -f4 | sort -u | wc -w) |
| if [[ ${PYTHON_VERSIONS} -gt 1 ]]; then |
| PY_UPDATE_FLAGS=() |
| if [[ "${FLAGS_jobs}" -ne -1 ]]; then |
| PY_UPDATE_FLAGS+=( --jobs=${FLAGS_jobs} ) |
| fi |
| cmds+=( |
| "python-updater --package-manager-command ${EMERGE_CMD} -- \ |
| ${PY_UPDATE_FLAGS[*]}" |
| ) |
| |
| # python-updater does not handle /usr/local, so do it ourselves. |
| # We have to run this after python-updater though since these packages |
| # might rely on other dev-python stuff in /usr. |
| pkgs=( $(qfile -qC /usr/local/lib*/python* | sort -u) ) |
| if [[ ${#pkgs[@]} -gt 0 ]]; then |
| cmds+=( "${EMERGE_CMD} ${PY_UPDATE_FLAGS[*]} ${pkgs[*]}" ) |
| fi |
| |
| cmds+=( |
| # Remove empty dirs if possible. |
| 'rmdir /usr/local/lib*/python*/site-packages /usr/local/lib*/python*/ \ |
| /usr/lib*/python*/site-packages /usr/lib*/python*/ 2>/dev/null || :' |
| ) |
| fi |
| |
| sudo_multi "${cmds[@]}" |
| |
| command_completed |