From ffede3b4146dfa538f35650e600c648579dcb322 Mon Sep 17 00:00:00 2001 From: David James Date: Tue, 7 Sep 2010 14:22:38 -0700 Subject: [PATCH] Use --usepkgonly in build_image to ensure no accidental builds of packages. Historically, we used --usepkgonly in build_image to ensure that packages were not accidentally built during this step. Recently, build_image was updated to use --usepkg. The benefit of using --usepkg was that it would not install obsolete binary packages to your image. It was counter-intuitive that --usepkgonly would install packages to your image that are not actually installed to your board root. The disadvantage, however, of --usepkg, was that it sometimes tried to build packages afresh using the image as your build root, and this failed with strange errors because you're not supposed to do that. This change fixes build_image to give useful errors by switching back to --usepkgonly. To fix the problem where --usepkgonly installs packages that are not installed, we first run eclean- to clean all unused packages from the board root. This change is a big improvement because a number of people have run into strange issues with build_image due to this problem and have had trouble debugging them. This change was actually written by Sean Paul, and I am shepherding his change through for him because he doesn't have a Chromium account yet. BUG=chromium-os:6437 TEST= 1) build_packages && build_image should still work 2) build_packages && ./cros_workon start power_manager && build_image should fail with an error that all versions of the power manager are masked. This happens because you started working on the power manager, but did not build the version of the power manager you were working on before installing it. 3) Assuming you are working on the power manager, build_packages && build_image should succeed because your cros_workon'd version of the package is built. 4) ( ./cros_workon start power_manager && build_packages && ./cros_workon stop power_manager && build_image ) should fail with the same error message as case 2 for similar reasons. 5) ( ./cros_workon start power_manager && build_packages && ./cros_workon stop power_manager && build_packages && build_image ) should work because you've built your new version of the stable package. Change-Id: Ia3858c70997bc6f0ec0b6d1bfaede8d3272a0976 Review URL: http://codereview.chromium.org/3305010 --- build_image | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/build_image b/build_image index f51b1826af..b4a6f1ac62 100755 --- a/build_image +++ b/build_image @@ -30,6 +30,8 @@ DEFINE_integer build_attempt 1 \ "The build attempt for this image build." DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \ "Directory in which to place image result directories (named by version)" +DEFINE_boolean eclean ${FLAGS_TRUE} \ + "Perform eclean- -d as part of this script to remove obsolete packages" DEFINE_boolean replace ${FLAGS_FALSE} \ "Overwrite existing output, if any." DEFINE_boolean withdev ${FLAGS_TRUE} \ @@ -384,13 +386,13 @@ update_dev_packages() { # Install developer packages described in chromeos-dev. sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ --root="${root_dev_dir}" --root-deps=rdeps \ - --usepkg -uDNv chromeos-dev ${EMERGE_JOBS} + --usepkgonly -uDNv chromeos-dev ${EMERGE_JOBS} if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then # Clean out unused packages sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ --root="${ROOT_FS_DIR}" --root-deps=rdeps \ - --usepkg --depclean ${EMERGE_JOBS} + --usepkgonly --depclean ${EMERGE_JOBS} fi # Re-run ldconfig to fix /etc/ldconfig.so.cache. @@ -453,12 +455,12 @@ update_base_packages() { # Emerge updated packages, exactly like when creating base image sudo USE="${EXTRA_USE}" INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ --root="${ROOT_FS_DIR}" --root-deps=rdeps \ - --usepkg -uDNv chromeos ${EXTRA_PACKAGES} ${EMERGE_JOBS} + --usepkgonly -uDNv chromeos ${EXTRA_PACKAGES} ${EMERGE_JOBS} # Clean out unused packages sudo INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ --root="${ROOT_FS_DIR}" --root-deps=rdeps \ - --usepkg --depclean ${EMERGE_JOBS} + --usepkgonly --depclean ${EMERGE_JOBS} trap - EXIT ${SCRIPTS_DIR}/mount_gpt_image.sh -u -r "${ROOT_FS_DIR}" \ @@ -585,13 +587,13 @@ create_base_image() { sudo mount --bind "${STATEFUL_FS_DIR}/var" "${ROOT_FS_DIR}/var" sudo mkdir -p "${ROOT_FS_DIR}/dev" - # We "emerge --root=${ROOT_FS_DIR} --root-deps=rdeps --usepkg" all of the + # We "emerge --root=${ROOT_FS_DIR} --root-deps=rdeps --usepkgonly" all of the # runtime packages for chrome os. This builds up a chrome os image from # binary packages with runtime dependencies only. We use INSTALL_MASK to # trim the image size as much as possible. sudo USE="${EXTRA_USE}" INSTALL_MASK="${INSTALL_MASK}" ${EMERGE_BOARD_CMD} \ --root="${ROOT_FS_DIR}" --root-deps=rdeps \ - --usepkg chromeos ${EXTRA_PACKAGES} ${EMERGE_JOBS} + --usepkgonly chromeos ${EXTRA_PACKAGES} ${EMERGE_JOBS} # Perform any customizations on the root file system that are needed. "${SCRIPTS_DIR}/customize_rootfs" \ @@ -680,6 +682,11 @@ if [[ $FLAGS_preserve -eq ${FLAGS_TRUE} ]] ; then fi fi +# Perform an eclean to remove packages which are not installed +if [[ "${FLAGS_eclean}" -eq "${FLAGS_TRUE}" ]]; then + eclean-${FLAGS_board} -d packages +fi + # Create the boot.desc file which stores the build-time configuration # information needed for making the image bootable after creation with # cros_make_image_bootable.