From 7b6f377c581ec6d7170b550bd17f0c1a746a0906 Mon Sep 17 00:00:00 2001 From: Brian Harring Date: Sun, 23 Sep 2012 14:01:13 -0700 Subject: [PATCH] sdk_lib/*: Make --cache_dir option required. This is forced by cros_sdk; in conjunction w/ this, drop --distfiles and mangle the chroot on during entrance dropping a symlink in the old /var/cache/distfiles location pointing to the new mounted cache_dir location. Additionally, thread CHROMEOS_CACHEDIR down through the end. Do this without relying on a version upgrade script- we can't require they be run before entering, thus we exploit the fact that cros_sdk explicitly forces a write lock to do the upgrade, if we see the old form we know we can do the upgrade w/out worrying about collisions. CQ-DEPEND=CL:33871 BUG=chromium-os:34457 TEST=manual testing. Change-Id: I6805266e3ec683f05d3ba615f9e8840642a28e48 Reviewed-on: https://gerrit.chromium.org/gerrit/33868 Commit-Ready: Brian Harring Reviewed-by: Brian Harring Tested-by: Brian Harring --- sdk_lib/enter_chroot.sh | 30 ++++++++++++++++++++++-------- sdk_lib/make_chroot.sh | 26 ++++++++++++++++++++------ 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index f06e4f5d03..c81f89fc15 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -27,8 +27,7 @@ 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_string cache_dir "" "Directory to use for caching." DEFINE_boolean official_build $FLAGS_FALSE \ "Set CHROMEOS_OFFICIAL=1 for release builds." @@ -73,8 +72,8 @@ if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then CHROMEOS_OFFICIAL=1 fi -[ -z "${FLAGS_distfiles}" ] && \ - FLAGS_distfiles="${FLAGS_trunk}/distfiles" +[ -z "${FLAGS_cache_dir}" ] && \ + die "--cache_dir is required" # 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. @@ -359,10 +358,25 @@ 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" + chroot_cache='/var/cache/chromeos-cache' + debug "Setting up shared cache dir directory." + mkdir -p "${FLAGS_cache_dir}"/distfiles/{target,host} + sudo mkdir -p "${FLAGS_chroot}/${chroot_cache}" + queue_mount "${FLAGS_cache_dir}" "--bind" "${chroot_cache}" + # TODO(build): remove this as of 12/01/12. + # Because of how distfiles -> cache_dir was deployed, if this isn't + # a symlink, we *know* the ondisk pathways aren't compatible- thus + # fix it now. + distfiles_path="${FLAGS_chroot}/var/cache/distfiles" + if [ ! -L "${distfiles_path}" ]; then + # While we're at it, ensure the var is exported w/in the chroot; it + # won't exist if distfiles isn't a symlink. + p="${FLAGS_chroot}/etc/profile.d/chromeos-cache.sh" + sudo_multi "rm -rf '${distfiles_path}'" \ + "ln -s chromeos-cache/distfiles '${distfiles_path}'" \ + "echo 'export CHROMEOS_CACHEDIR=${chroot_cache}' > '${p}'" \ + "chmod 0644 '${p}'" + fi if [ $FLAGS_ssh_agent -eq $FLAGS_TRUE ]; then if [ -n "${SSH_AUTH_SOCK}" -a -d "${HOME}/.ssh" ]; then diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh index 94dfe826c9..ae33fbf8d3 100755 --- a/sdk_lib/make_chroot.sh +++ b/sdk_lib/make_chroot.sh @@ -45,6 +45,7 @@ DEFINE_string stage3_date "2010.03.09" \ "Use the stage3 with the given date." DEFINE_string stage3_path "" \ "Use the stage3 located on this path." +DEFINE_string cache_dir "" "Directory to store caches within." # Parse command line flags. FLAGS_HELP="usage: $SCRIPT_NAME [flags]" @@ -63,6 +64,10 @@ umask 022 # TODO: replace shflags with something less error-prone, or contribute a fix. switch_to_strict_mode +[[ "${FLAGS_delete}" == "${FLAGS_FALSE}" ]] && \ + [[ -z "${FLAGS_cache_dir}" ]] && \ + die "--cache_dir is required" + . "${SCRIPT_ROOT}"/sdk_lib/make_conf_util.sh FULLNAME="ChromeOS Developer" @@ -93,7 +98,8 @@ ENTER_CHROOT_ARGS=( # Invoke enter_chroot. This can only be used after sudo has been installed. enter_chroot() { - "$ENTER_CHROOT" --chroot "$FLAGS_chroot" -- "${ENTER_CHROOT_ARGS[@]}" "$@" + "$ENTER_CHROOT" --cache_dir "${FLAGS_cache_dir}" --chroot "$FLAGS_chroot" \ + -- "${ENTER_CHROOT_ARGS[@]}" "$@" } # Invoke enter_chroot running the command as root, and w/out sudo. @@ -101,6 +107,7 @@ enter_chroot() { early_env=() early_enter_chroot() { "$ENTER_CHROOT" --chroot "$FLAGS_chroot" --early_make_chroot \ + --cache_dir "${FLAGS_cache_dir}" \ -- "${ENTER_CHROOT_ARGS[@]}" "${early_env[@]}" "$@" } @@ -208,8 +215,15 @@ init_setup () { # Create directories referred to by our conf files. sudo mkdir -p -m 775 "${FLAGS_chroot}/var/lib/portage/pkgs" \ - "${FLAGS_chroot}/var/cache/distfiles" \ - "${FLAGS_chroot}/var/cache/chromeos-chrome" + "${FLAGS_chroot}/var/cache/"chromeos-{cache,chrome} \ + "${FLAGS_chroot}/etc/profile.d" + + echo "export CHROMEOS_CACHEDIR=/var/cache/chromeos-cache" | \ + sudo_clobber "${FLAGS_chroot}/etc/profile.d/chromeos-cachedir.sh" + sudo_multi \ + "chmod 0644 '${FLAGS_chroot}/etc/profile.d/chromeos-cachedir.sh'" \ + "rm -rf '${FLAGS_chroot}/var/cache/distfiles'" \ + "ln -s chromeos-cache/distfiles '${FLAGS_chroot}/var/cache/distfiles'" # Run this from w/in the chroot so we use whatever uid/gid # these are defined as w/in the chroot. @@ -217,10 +231,10 @@ init_setup () { # 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 \ + # TODO(ferringb): remove this 01/13 or so. + sudo ln -s ../../cache/chromeos-cache/distfiles/host \ "${FLAGS_chroot}/var/lib/portage/distfiles" - sudo ln -s ../../cache/distfiles/target \ + sudo ln -s ../../cache/chromeos-cache/distfiles/target \ "${FLAGS_chroot}/var/lib/portage/distfiles-target" # Add chromite/bin and depot_tools into the path globally; note that the