mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-21 21:51:57 +02:00
Move source access to a standard location, add chromite to PYTHONPATH.
Rather than having to find /home/${SUDO_USER:-${USER}}/trunk, instead just look for /mnt/host/trunk (defined by common.sh as $CHROOT_TRUNK_DIR). This simplifies code flow, and is a requirement for shoving chromite into PYTHONPATH globally w/in the chroot. BUG=chromium-os:37347 TEST=cros_sdk --replace; cros_sdk w/ chroot upgrade. Change-Id: I9ee3e6556541a91193f49cbf74ffc5a8e090537f Reviewed-on: https://gerrit.chromium.org/gerrit/39921 Tested-by: Brian Harring <ferringb@chromium.org> Reviewed-by: David James <davidjames@chromium.org>
This commit is contained in:
parent
11e0f66cc9
commit
2499bfbeb2
13
chroot_version_hooks.d/50_add_chromite_link
Normal file
13
chroot_version_hooks.d/50_add_chromite_link
Normal file
@ -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
|
68
common.sh
68
common.sh
@ -180,9 +180,7 @@ die_notrace() {
|
|||||||
# by the calling script.
|
# by the calling script.
|
||||||
get_gclient_root_list() {
|
get_gclient_root_list() {
|
||||||
if [ $INSIDE_CHROOT -eq 1 ]; then
|
if [ $INSIDE_CHROOT -eq 1 ]; then
|
||||||
echo "/home/${USER}/trunk"
|
echo "${CHROOT_TRUNK_DIR}"
|
||||||
|
|
||||||
if [ -n "${SUDO_USER}" ]; then echo "/home/${SUDO_USER}/trunk"; fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${COMMON_SH}" ]; then echo "$(dirname "$COMMON_SH")/../.."; 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_TEST_IMAGE_NAME="chromiumos_factory_image.bin"
|
||||||
CHROMEOS_FACTORY_INSTALL_SHIM_NAME="factory_install_shim.bin"
|
CHROMEOS_FACTORY_INSTALL_SHIM_NAME="factory_install_shim.bin"
|
||||||
|
|
||||||
# Directory locations inside the dev chroot
|
# Directory locations inside the dev chroot; try the new default,
|
||||||
if [ "${USER}" = "root" ]; then
|
# falling back to user specific paths if the upgrade has yet to
|
||||||
CHROOT_TRUNK_DIR="/home/${SUDO_USER}/trunk"
|
# happen.
|
||||||
else
|
_user="${USER}"
|
||||||
CHROOT_TRUNK_DIR="/home/${USER}/trunk"
|
[ "${USER}" = "root" ] && _user="${SUDO_USER}"
|
||||||
fi
|
_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.
|
# Install make for portage ebuilds. Used by build_image and gmergefs.
|
||||||
# TODO: Is /usr/local/autotest-chrome still used by anyone?
|
# TODO: Is /usr/local/autotest-chrome still used by anyone?
|
||||||
|
@ -86,7 +86,6 @@ FILES_TO_COPY_TO_CHROOT=(
|
|||||||
|
|
||||||
INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot
|
INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot
|
||||||
CHROME_ROOT_CONFIG="/var/cache/chrome_root" # 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"
|
FUSE_DEVICE="/dev/fuse"
|
||||||
|
|
||||||
chmod 0777 "$FLAGS_chroot/var/lock"
|
chmod 0777 "$FLAGS_chroot/var/lock"
|
||||||
@ -94,6 +93,11 @@ chmod 0777 "$FLAGS_chroot/var/lock"
|
|||||||
LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot"
|
LOCKFILE="$FLAGS_chroot/var/lock/enter_chroot"
|
||||||
MOUNTED_PATH=$(readlink -f "$FLAGS_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() {
|
setup_mount() {
|
||||||
# If necessary, mount $source in the host FS at $target inside the
|
# 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
|
# 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
|
setup_mount /run/shm "--bind" /run/shm
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
setup_mount "${FLAGS_trunk}" "--bind" "${CHROOT_TRUNK_DIR}"
|
setup_mount "${FLAGS_trunk}" "--bind" "${CHROOT_TRUNK_DIR}"
|
||||||
|
|
||||||
debug "Setting up referenced repositories if required."
|
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.
|
# A reference to the DEPOT_TOOLS path may be passed in by cros_sdk.
|
||||||
if [ -n "${DEPOT_TOOLS}" ]; then
|
if [ -n "${DEPOT_TOOLS}" ]; then
|
||||||
debug "Mounting depot_tools"
|
debug "Mounting depot_tools"
|
||||||
setup_mount "${DEPOT_TOOLS}" --bind "${INNER_DEPOT_TOOLS_ROOT}"
|
setup_mount "${DEPOT_TOOLS}" --bind "${DEPOT_TOOLS_DIR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Mount additional directories as specified in .local_mounts file.
|
# Mount additional directories as specified in .local_mounts file.
|
||||||
|
@ -85,7 +85,7 @@ fi
|
|||||||
# Support faster build if necessary.
|
# Support faster build if necessary.
|
||||||
EMERGE_CMD="emerge"
|
EMERGE_CMD="emerge"
|
||||||
if [ "$FLAGS_fast" -eq "${FLAGS_TRUE}" ]; then
|
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"
|
EMERGE_CMD="${CHROOT_CHROMITE_DIR}/bin/parallel_emerge"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -163,11 +163,11 @@ init_setup () {
|
|||||||
mkdir -p -m 755 "${FLAGS_chroot}/usr" \
|
mkdir -p -m 755 "${FLAGS_chroot}/usr" \
|
||||||
"${FLAGS_chroot}/usr/local/portage" \
|
"${FLAGS_chroot}/usr/local/portage" \
|
||||||
"${FLAGS_chroot}"/"${CROSSDEV_OVERLAY}"
|
"${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"
|
"${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}"
|
"${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}"
|
"${FLAGS_chroot}"/"${PORTAGE_STABLE_OVERLAY}"
|
||||||
|
|
||||||
# Some operations need an mtab.
|
# Some operations need an mtab.
|
||||||
@ -236,11 +236,15 @@ init_setup () {
|
|||||||
# We rely on 'env-update' getting called below.
|
# We rely on 'env-update' getting called below.
|
||||||
target="${FLAGS_chroot}/etc/env.d/99chromiumos"
|
target="${FLAGS_chroot}/etc/env.d/99chromiumos"
|
||||||
cat <<EOF > "${target}"
|
cat <<EOF > "${target}"
|
||||||
PATH=/home/${SUDO_USER}/trunk/chromite/bin:/home/${SUDO_USER}/depot_tools
|
PATH=${CHROOT_TRUNK_DIR}/chromite/bin:${DEPOT_TOOLS_DIR}
|
||||||
CROS_WORKON_SRCROOT="${CHROOT_TRUNK}"
|
CROS_WORKON_SRCROOT="${CHROOT_TRUNK_DIR}"
|
||||||
PORTAGE_USERNAME=${SUDO_USER}
|
PORTAGE_USERNAME=${SUDO_USER}
|
||||||
EOF
|
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,
|
# TODO(zbehan): Configure stuff that is usually configured in postinst's,
|
||||||
# but wasn't. Fix the postinst's.
|
# but wasn't. Fix the postinst's.
|
||||||
info "Running post-inst configuration hacks"
|
info "Running post-inst configuration hacks"
|
||||||
@ -278,12 +282,6 @@ en_US.UTF-8 UTF-8
|
|||||||
EOF
|
EOF
|
||||||
fi
|
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.
|
# Automatically change to scripts directory.
|
||||||
echo 'cd ${CHROOT_CWD:-~/trunk/src/scripts}' \
|
echo 'cd ${CHROOT_CWD:-~/trunk/src/scripts}' \
|
||||||
| user_append "$FLAGS_chroot/home/${SUDO_USER}/.bash_profile"
|
| user_append "$FLAGS_chroot/home/${SUDO_USER}/.bash_profile"
|
||||||
@ -333,7 +331,7 @@ CHROOT_TRUNK="${CHROOT_TRUNK_DIR}"
|
|||||||
PORTAGE="${SRC_ROOT}/third_party/portage"
|
PORTAGE="${SRC_ROOT}/third_party/portage"
|
||||||
OVERLAY="${SRC_ROOT}/third_party/chromiumos-overlay"
|
OVERLAY="${SRC_ROOT}/third_party/chromiumos-overlay"
|
||||||
CONFIG_DIR="${OVERLAY}/chromeos/config"
|
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"
|
PORTAGE_STABLE_OVERLAY="/usr/local/portage/stable"
|
||||||
CROSSDEV_OVERLAY="/usr/local/portage/crossdev"
|
CROSSDEV_OVERLAY="/usr/local/portage/crossdev"
|
||||||
CHROOT_OVERLAY="/usr/local/portage/chromiumos"
|
CHROOT_OVERLAY="/usr/local/portage/chromiumos"
|
||||||
@ -386,10 +384,15 @@ fi
|
|||||||
# Set up users, if needed, before mkdir/mounts below.
|
# Set up users, if needed, before mkdir/mounts below.
|
||||||
[ -f $CHROOT_STATE ] || init_users
|
[ -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
|
echo
|
||||||
info "Setting up mounts..."
|
info "Setting up mounts..."
|
||||||
# Set up necessary mounts and make sure we clean them up on exit.
|
# 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
|
# 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
|
# 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 )
|
TOOLCHAIN_ARGS+=( --nousepkg )
|
||||||
fi
|
fi
|
||||||
# Note: early_enter_chroot executes as root.
|
# 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[@]}"
|
--hostonly "${TOOLCHAIN_ARGS[@]}"
|
||||||
|
|
||||||
# dhcpcd is included in 'world' by the stage3 that we pull in for some reason.
|
# 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
|
# If we're creating a new chroot, we also want to set it to the latest
|
||||||
# version.
|
# version.
|
||||||
enter_chroot \
|
enter_chroot \
|
||||||
"${CHROOT_TRUNK}/src/scripts/run_chroot_version_hooks" --force_latest
|
"${CHROOT_TRUNK_DIR}/src/scripts/run_chroot_version_hooks" --force_latest
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Update chroot.
|
# Update chroot.
|
||||||
@ -488,7 +491,7 @@ fi
|
|||||||
if [[ "${FLAGS_jobs}" -ne -1 ]]; then
|
if [[ "${FLAGS_jobs}" -ne -1 ]]; then
|
||||||
UPDATE_ARGS+=( --jobs=${FLAGS_jobs} )
|
UPDATE_ARGS+=( --jobs=${FLAGS_jobs} )
|
||||||
fi
|
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=""
|
CHROOT_EXAMPLE_OPT=""
|
||||||
if [[ "$FLAGS_chroot" != "$DEFAULT_CHROOT_DIR" ]]; then
|
if [[ "$FLAGS_chroot" != "$DEFAULT_CHROOT_DIR" ]]; then
|
||||||
@ -497,7 +500,7 @@ fi
|
|||||||
|
|
||||||
# As a final pass, build all desired cross-toolchains.
|
# As a final pass, build all desired cross-toolchains.
|
||||||
info "Updating 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[@]}"
|
"${TOOLCHAIN_ARGS[@]}"
|
||||||
|
|
||||||
command_completed
|
command_completed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user