diff --git a/chroot_version_hooks.d/50_add_chromite_link b/chroot_version_hooks.d/50_add_chromite_link new file mode 100644 index 0000000000..38b0c5530e --- /dev/null +++ b/chroot_version_hooks.d/50_add_chromite_link @@ -0,0 +1,13 @@ +# 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. +python_path=$(python -c 'import sys;print sys.version[:3]') +python_path="/usr/lib/python${python_path}/site-packages/chromite" +if [ ! -L "${python_path}" ]; then + sudo rm -rf "${python_path}" \ + "/home/${PORTAGE_USERNAME:-${SUDO_USER:-${USER}}}/.local/lib/python2.6/site-packages/chromite" + sudo mkdir -p "$(dirname "${python_path}")" + sudo ln -s "${CHROOT_TRUNK_DIR}"/chromite "${python_path}" +fi + +exit 0 diff --git a/common.sh b/common.sh index 7d05f2b953..aa4f050c2d 100644 --- a/common.sh +++ b/common.sh @@ -180,9 +180,7 @@ die_notrace() { # by the calling script. get_gclient_root_list() { if [ $INSIDE_CHROOT -eq 1 ]; then - echo "/home/${USER}/trunk" - - if [ -n "${SUDO_USER}" ]; then echo "/home/${SUDO_USER}/trunk"; fi + echo "${CHROOT_TRUNK_DIR}" fi if [ -n "${COMMON_SH}" ]; then echo "$(dirname "$COMMON_SH")/../.."; fi @@ -327,12 +325,64 @@ CHROMEOS_TEST_IMAGE_NAME="chromiumos_test_image.bin" CHROMEOS_FACTORY_TEST_IMAGE_NAME="chromiumos_factory_image.bin" CHROMEOS_FACTORY_INSTALL_SHIM_NAME="factory_install_shim.bin" -# Directory locations inside the dev chroot -if [ "${USER}" = "root" ]; then - CHROOT_TRUNK_DIR="/home/${SUDO_USER}/trunk" -else - CHROOT_TRUNK_DIR="/home/${USER}/trunk" -fi +# Directory locations inside the dev chroot; try the new default, +# falling back to user specific paths if the upgrade has yet to +# happen. +_user="${USER}" +[ "${USER}" = "root" ] && _user="${SUDO_USER}" +_CHROOT_TRUNK_DIRS=( "/home/${_user}/trunk" /mnt/host/source ) +_DEPOT_TOOLS_DIRS=( "/home/${_user}/depot_tools" /mnt/host/depot_tools ) +unset _user + +_process_mount_pt() { + # Given 4 arguments; the root path, the variable to set, + # the old location, and the new; finally, forcing the upgrade is doable + # via if a 5th arg is provided. + # This will then try to migrate the old to new if we can do so right now + # (else leaving symlinks in place w/in the new), and will set $1 to the + # new location. + local base="${1:-/}" var="${2}" old="${3}" new="${4}" force="${5:-false}" + local _sudo=$([ "$USER" != root ] && echo sudo) + local val="${new}" + if [ -L "${base}/${new}" ] || [ ! -e "${base}/${new}" ]; then + # Ok, it's either a symlink or this is the first run. Upgrade if we can- + # specifically, if we're outside the chroot and we can rmdir the old. + # If we cannot rmdir the old, that's due to a mount being bound to that + # point (even if we can't see it, it's there)- thus fallback to adding + # compat links. + if ${force} || ( [ "$INSIDE_CHROOT" -eq 0 ] && \ + ${_sudo} rmdir "${base}/${old}" 2> /dev/null ); then + ${_sudo} rm -f "${base}/${new}" || : + ${_sudo} mkdir -p "${base}/${new}" "$(dirname "${base}/${old}" )" + ${_sudo} ln -s "${new}" "${base}/${old}" + else + if [ ! -L "${base}/${new}" ]; then + # We can't do the upgrade right now; install compatibility links. + ${_sudo} mkdir -p "$(dirname "${base}/${new}")" "${base}/${old}" + ${_sudo} ln -s "${old}" "${base}/${new}" + fi + val="${old}" + fi + fi + eval "${var}=\"${val}\"" +} + +set_chroot_trunk_dir() { + # This takes two optional arguments; the first being the path to the chroot + # base; this is only used by enter_chroot. The second argument is whether + # or not to force the new pathways; this is only used by make_chroot. Passing + # a non-null value for $2 forces the new paths. + if [ "${INSIDE_CHROOT}" == 0 ] && [ -z "${1-}" ]; then + # Can't do the upgrade, thus skip trying to do so. + CHROOT_TRUNK_DIR="${_CHROOT_TRUNK_DIRS[1]}" + DEPOT_TOOLS_DIR="${_DEPOT_TOOLS_DIRS[1]}" + return + fi + _process_mount_pt "$1" CHROOT_TRUNK_DIR "${_CHROOT_TRUNK_DIRS[@]}" ${2:+true} + _process_mount_pt "$1" DEPOT_TOOLS_DIR "${_DEPOT_TOOLS_DIRS[@]}" ${2:+true} +} + +set_chroot_trunk_dir # Install make for portage ebuilds. Used by build_image and gmergefs. # TODO: Is /usr/local/autotest-chrome still used by anyone? diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index 23078ff401..a16da3ad3c 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -86,7 +86,6 @@ FILES_TO_COPY_TO_CHROOT=( INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot -INNER_DEPOT_TOOLS_ROOT="/home/${SUDO_USER}/depot_tools" # inside chroot FUSE_DEVICE="/dev/fuse" chmod 0777 "$FLAGS_chroot/var/lock" @@ -94,6 +93,11 @@ chmod 0777 "$FLAGS_chroot/var/lock" LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot" MOUNTED_PATH=$(readlink -f "$FLAGS_chroot") +# Reset the depot tools/internal trunk pathways to what they'll +# be w/in the chroot. +set_chroot_trunk_dir "${FLAGS_chroot}" + + setup_mount() { # If necessary, mount $source in the host FS at $target inside the # chroot directory with $mount_args. We don't write to /etc/mtab because @@ -213,6 +217,7 @@ setup_env() { setup_mount /run/shm "--bind" /run/shm fi fi + setup_mount "${FLAGS_trunk}" "--bind" "${CHROOT_TRUNK_DIR}" debug "Setting up referenced repositories if required." @@ -327,7 +332,7 @@ setup_env() { # A reference to the DEPOT_TOOLS path may be passed in by cros_sdk. if [ -n "${DEPOT_TOOLS}" ]; then debug "Mounting depot_tools" - setup_mount "${DEPOT_TOOLS}" --bind "${INNER_DEPOT_TOOLS_ROOT}" + setup_mount "${DEPOT_TOOLS}" --bind "${DEPOT_TOOLS_DIR}" fi # Mount additional directories as specified in .local_mounts file. diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh index 258619c94f..265e4ddddc 100755 --- a/sdk_lib/make_chroot.sh +++ b/sdk_lib/make_chroot.sh @@ -85,7 +85,7 @@ fi # Support faster build if necessary. EMERGE_CMD="emerge" if [ "$FLAGS_fast" -eq "${FLAGS_TRUE}" ]; then - CHROOT_CHROMITE_DIR="/home/${SUDO_USER}/trunk/chromite" + CHROOT_CHROMITE_DIR="${CHROOT_TRUNK_DIR}/chromite" EMERGE_CMD="${CHROOT_CHROMITE_DIR}/bin/parallel_emerge" fi @@ -163,11 +163,11 @@ init_setup () { mkdir -p -m 755 "${FLAGS_chroot}/usr" \ "${FLAGS_chroot}/usr/local/portage" \ "${FLAGS_chroot}"/"${CROSSDEV_OVERLAY}" - ln -sf "${CHROOT_TRUNK}/src/third_party/portage" \ + ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/portage" \ "${FLAGS_chroot}/usr/portage" - ln -sf "${CHROOT_TRUNK}/src/third_party/chromiumos-overlay" \ + ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/chromiumos-overlay" \ "${FLAGS_chroot}"/"${CHROOT_OVERLAY}" - ln -sf "${CHROOT_TRUNK}/src/third_party/portage-stable" \ + ln -sf "${CHROOT_TRUNK_DIR}/src/third_party/portage-stable" \ "${FLAGS_chroot}"/"${PORTAGE_STABLE_OVERLAY}" # Some operations need an mtab. @@ -236,11 +236,15 @@ init_setup () { # We rely on 'env-update' getting called below. target="${FLAGS_chroot}/etc/env.d/99chromiumos" cat < "${target}" -PATH=/home/${SUDO_USER}/trunk/chromite/bin:/home/${SUDO_USER}/depot_tools -CROS_WORKON_SRCROOT="${CHROOT_TRUNK}" +PATH=${CHROOT_TRUNK_DIR}/chromite/bin:${DEPOT_TOOLS_DIR} +CROS_WORKON_SRCROOT="${CHROOT_TRUNK_DIR}" PORTAGE_USERNAME=${SUDO_USER} EOF + # Add chromite into python path. + CHROOT_TRUNK_DIR="${CHROOT_TRUNK_DIR}" bash -e \ + "${SCRIPT_ROOT}/chroot_version_hooks.d/50_add_chromite_pythonpath" + # TODO(zbehan): Configure stuff that is usually configured in postinst's, # but wasn't. Fix the postinst's. info "Running post-inst configuration hacks" @@ -278,12 +282,6 @@ en_US.UTF-8 UTF-8 EOF fi - # Add chromite as a local site-package. - local site_packages="/home/${SUDO_USER}/.local/lib/python2.6/site-packages" - user_mkdir "${FLAGS_chroot}${site_packages}" - user_symlink ../../../../trunk/chromite \ - "${FLAGS_chroot}${site_packages}/chromite" - # Automatically change to scripts directory. echo 'cd ${CHROOT_CWD:-~/trunk/src/scripts}' \ | user_append "$FLAGS_chroot/home/${SUDO_USER}/.bash_profile" @@ -333,7 +331,7 @@ CHROOT_TRUNK="${CHROOT_TRUNK_DIR}" PORTAGE="${SRC_ROOT}/third_party/portage" OVERLAY="${SRC_ROOT}/third_party/chromiumos-overlay" CONFIG_DIR="${OVERLAY}/chromeos/config" -CHROOT_CONFIG="${CHROOT_TRUNK}/src/third_party/chromiumos-overlay/chromeos/config" +CHROOT_CONFIG="${CHROOT_TRUNK_DIR}/src/third_party/chromiumos-overlay/chromeos/config" PORTAGE_STABLE_OVERLAY="/usr/local/portage/stable" CROSSDEV_OVERLAY="/usr/local/portage/crossdev" CHROOT_OVERLAY="/usr/local/portage/chromiumos" @@ -386,10 +384,15 @@ fi # Set up users, if needed, before mkdir/mounts below. [ -f $CHROOT_STATE ] || init_users +# Reset internal vars to force them to the 'inside the chroot' value; +# since user directories now exist, this can do the upgrade in place. +set_chroot_trunk_dir "${FLAGS_chroot}" poppycock + echo info "Setting up mounts..." # Set up necessary mounts and make sure we clean them up on exit. -mkdir -p "${FLAGS_chroot}/${CHROOT_TRUNK}" "${FLAGS_chroot}/run" +mkdir -p "${FLAGS_chroot}/${CHROOT_TRUNK_DIR}" \ + "${FLAGS_chroot}/${DEPOT_TOOLS_DIR}" "${FLAGS_chroot}/run" # Create a special /etc/make.conf.host_setup that we use to bootstrap # the chroot. The regular content for the file will be generated the @@ -452,7 +455,7 @@ if [[ ${FLAGS_usepkg} -eq ${FLAGS_FALSE} ]]; then TOOLCHAIN_ARGS+=( --nousepkg ) fi # Note: early_enter_chroot executes as root. -early_enter_chroot "${CHROOT_TRUNK}/chromite/bin/cros_setup_toolchains" \ +early_enter_chroot "${CHROOT_TRUNK_DIR}/chromite/bin/cros_setup_toolchains" \ --hostonly "${TOOLCHAIN_ARGS[@]}" # dhcpcd is included in 'world' by the stage3 that we pull in for some reason. @@ -468,7 +471,7 @@ if [ -n "${INITIALIZE_CHROOT}" ]; then # If we're creating a new chroot, we also want to set it to the latest # version. enter_chroot \ - "${CHROOT_TRUNK}/src/scripts/run_chroot_version_hooks" --force_latest + "${CHROOT_TRUNK_DIR}/src/scripts/run_chroot_version_hooks" --force_latest fi # Update chroot. @@ -488,7 +491,7 @@ fi if [[ "${FLAGS_jobs}" -ne -1 ]]; then UPDATE_ARGS+=( --jobs=${FLAGS_jobs} ) fi -enter_chroot "${CHROOT_TRUNK}/src/scripts/update_chroot" "${UPDATE_ARGS[@]}" +enter_chroot "${CHROOT_TRUNK_DIR}/src/scripts/update_chroot" "${UPDATE_ARGS[@]}" CHROOT_EXAMPLE_OPT="" if [[ "$FLAGS_chroot" != "$DEFAULT_CHROOT_DIR" ]]; then @@ -497,7 +500,7 @@ fi # As a final pass, build all desired cross-toolchains. info "Updating toolchains" -enter_chroot sudo -E "${CHROOT_TRUNK}/chromite/bin/cros_setup_toolchains" \ +enter_chroot sudo -E "${CHROOT_TRUNK_DIR}/chromite/bin/cros_setup_toolchains" \ "${TOOLCHAIN_ARGS[@]}" command_completed