diff --git a/chroot_version_hooks.d/24_distfiles_migration b/chroot_version_hooks.d/24_distfiles_migration new file mode 100644 index 0000000000..fcd16660c7 --- /dev/null +++ b/chroot_version_hooks.d/24_distfiles_migration @@ -0,0 +1,33 @@ +# 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. + +# Previously distfiles were stored entirely in the chroot, forcing us +# to download it everytime. This content is now stored externally, exposed +# to the chroot via mount binds. +# +# What we're doing here is moving any existing content from the old locations, +# into the new locations- which will already have a mount bind in place. +# If it *doesn't*, meaning parallel cros_sdk usage, we just wipe the content +# (user can redownload it after all). +# +# Once that's done, upgrade the chroot directory structure installing +# syms pointing back to the new location. + +upgrade_path() { + local src="/var/lib/portage/$1" + local dest="/var/cache/distfiles/$2" + if [ -L "$src" ]; then + # Already upgraded- skip this one. + return 0 + fi + # Suppress failures. User just has to download in that case. + sudo find "$src"/ -maxdepth 1 -mindepth 1 -exec sudo mv -t "$dest/" {} + || : + sudo rm -rf "$src" + sudo ln -s ../../cache/distfiles/"$2" "$src" +} + +upgrade_path distfiles host +upgrade_path distfiles-target target + +exit 0 diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index e6acc97b96..0339a761fe 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -25,6 +25,8 @@ DEFINE_string chrome_root "" \ "The root of your chrome browser source. Should contain a 'src' subdir." DEFINE_string chrome_root_mount "/home/$USER/chrome_root" \ "The mount point of the chrome broswer source in the chroot." +DEFINE_string distfiles "" \ + "Override the destination dir used for distfiles." DEFINE_boolean official_build $FLAGS_FALSE \ "Set CHROMEOS_OFFICIAL=1 for release builds." @@ -67,6 +69,9 @@ if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then CHROMEOS_OFFICIAL=1 fi +[ -z "${FLAGS_distfiles}" ] && \ + FLAGS_distfiles="${FLAGS_trunk}/distfiles" + # Only now can we die on error. shflags functions leak non-zero error codes, # so will die prematurely if 'set -e' is specified before now. # TODO: replace shflags with something less error-prone, or contribute a fix. @@ -290,6 +295,11 @@ function setup_env { fi unset REFERENCE_DIR + debug "Setting up shared distfiles directory." + mkdir -p "${FLAGS_distfiles}"/{target,host} + sudo mkdir -p "${FLAGS_chroot}/var/cache/distfiles/" + queue_mount "${FLAGS_distfiles}" "--bind" "/var/cache/distfiles" + if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then TARGET_DIR="${FLAGS_chroot}/home/${USER}/.ssh" diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh index f26dbab1b0..2ac5767657 100755 --- a/sdk_lib/make_chroot.sh +++ b/sdk_lib/make_chroot.sh @@ -198,9 +198,15 @@ EOF sudo chmod 0644 "${FLAGS_chroot}"/etc/make.conf.user # Create directories referred to by our conf files. - sudo mkdir -p -m 775 "${FLAGS_chroot}/var/lib/portage/distfiles" \ - "${FLAGS_chroot}/var/lib/portage/distfiles-target" \ - "${FLAGS_chroot}/var/lib/portage/pkgs" + sudo mkdir -p -m 775 "${FLAGS_chroot}/var/lib/portage/pkgs" + + # These are created for compatibility while transitioning + # make.conf and friends over to the new location. + # TODO(ferringb): remove this 03/12 or so. + sudo ln -s ../../cache/distfiles/host \ + "${FLAGS_chroot}/var/lib/portage/distfiles" + sudo ln -s ../../cache/distfiles/target \ + "${FLAGS_chroot}/var/lib/portage/distfiles-target" if [[ $FLAGS_jobs -ne -1 ]]; then EMERGE_JOBS="--jobs=$FLAGS_jobs"