From c9422fa467ecab72cd4d639df6593457d3bf7746 Mon Sep 17 00:00:00 2001 From: Chris Sosa Date: Mon, 5 Mar 2012 15:58:07 -0800 Subject: [PATCH] Deprecate --test, --withdev, --factory, --factory_install from build_image. Using these flags directly was deprecated a while back and is causing confusion which way is the right way. This CL removes all these FLAGS from build_image (though keeps support of them in mod_image_for_test/image_to_usb invocations in common.sh). In this change I've also defaulted build_image to build the developer image (and only the developer image). BUG=chromium-os:27362 TEST=Been busy testing. Have built the following combinations and verified them: build_image base build_image build_image base dev test build_image dev build_image dev factory_test build_image factory_install Change-Id: Ie534c276a9ec571926964320ac176daa91b12a81 Reviewed-on: https://gerrit.chromium.org/gerrit/17386 Tested-by: Chris Sosa Reviewed-by: Richard Barnette Commit-Ready: Chris Sosa --- build_image | 66 ++++++++++-------------- build_library/base_image_util.sh | 17 ++---- build_library/build_image_util.sh | 86 +++++++------------------------ build_library/dev_image_util.sh | 12 ++--- build_library/test_image_util.sh | 18 ++++--- common.sh | 2 +- 6 files changed, 67 insertions(+), 134 deletions(-) diff --git a/build_image b/build_image index 8e293c8b97..ce3f6755cf 100755 --- a/build_image +++ b/build_image @@ -23,19 +23,10 @@ DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \ "Directory in which to place image result directories (named by version)" DEFINE_boolean replace ${FLAGS_FALSE} \ "Overwrite existing output, if any." -DEFINE_boolean withdev ${FLAGS_TRUE} \ - "Include useful developer friendly utilities in the image." DEFINE_integer jobs -1 \ "How many packages to build in parallel at maximum." DEFINE_boolean statefuldev ${FLAGS_TRUE} \ "Install development packages on stateful partition rather than the rootfs" -DEFINE_boolean test ${FLAGS_FALSE} \ - "Modify the image for automated testing" -DEFINE_boolean factory ${FLAGS_FALSE} \ - "Modify the image for manufacturing testing" -DEFINE_boolean factory_install ${FLAGS_FALSE} \ - "Build a smaller image to overlay the factory install shim on; this argument \ -is also required in image_to_usb." DEFINE_integer rootfs_partition_size 1024 \ "rootfs partition size in MiBs." DEFINE_integer rootfs_size 850 \ @@ -104,7 +95,6 @@ set -e # Determine build version. OVERLAY_CHROMEOS_DIR="${SRC_ROOT}/third_party/chromiumos-overlay/chromeos" . "${OVERLAY_CHROMEOS_DIR}/config/chromeos_version.sh" || exit 1 - # N.B. Ordering matters for some of the libraries below, because # some of the files contain initialization used by later files. . "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1 @@ -117,11 +107,10 @@ OVERLAY_CHROMEOS_DIR="${SRC_ROOT}/third_party/chromiumos-overlay/chromeos" . "${BUILD_LIBRARY_DIR}/test_image_content.sh" || exit 1 parse_build_image_args - # Tweak flags, configure extra USE flags, and add packages for the factory # install shim. EXTRA_PACKAGES="" -if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then +if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then # TODO: Build a separated ebuild for the install shim to reduce size. INSTALL_MASK="${FACTORY_SHIM_INSTALL_MASK}" @@ -160,21 +149,10 @@ fi # If we are creating a developer image, also create a pristine image with a # different name. PRISTINE_IMAGE_NAME= -if [ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]; then - PRISTINE_IMAGE_NAME=${CHROMEOS_BASE_IMAGE_NAME} -# Rename pristine image for factory install shim. -elif [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then +if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then PRISTINE_IMAGE_NAME=${CHROMEOS_FACTORY_INSTALL_SHIM_NAME} else - # No withdev and no factory_install set meaning we must be building just the - # base image. - PRISTINE_IMAGE_NAME=chromiumos_image.bin - # Verify our assertion is true. - if [ ${IMAGES_TO_BUILD} != ${CHROMEOS_BASE_IMAGE_NAME} ]; then - warn "${IMAGES_TO_BUILD} != ${CHROMEOS_BASE_IMAGE_NAME}" - die "Should only reach this condition if only building the base image." - fi - IMAGES_TO_BUILD="chromiumos_image.bin" + PRISTINE_IMAGE_NAME=${CHROMEOS_BASE_IMAGE_NAME} fi ROOT_FS_DIR="${BUILD_DIR}/rootfs" @@ -224,7 +202,7 @@ create_base_image ${PRISTINE_IMAGE_NAME} BOOT_FLAG= -if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then +if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then BOOT_FLAG="-b 1" # BOOT_FLAG_DEVELOPER value defined in load_kernel_fw.h info "--factory_install set, pass BOOT_FLAG_DEVELOPER flag to" \ "load_kernel_test" @@ -236,20 +214,22 @@ if should_build_image "${PRISTINE_IMAGE_NAME}"; then "${DEVKEYSDIR}/recovery_key.vbpubk" ${BOOT_FLAG} fi -# Create a developer image based on the chromium os base image. -if [ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]; then +# Create a developer image if an image that is based on it is requested. +if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} \ + ${CHROMEOS_TEST_IMAGE_NAME} ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then copy_image ${CHROMEOS_BASE_IMAGE_NAME} ${CHROMEOS_DEVELOPER_IMAGE_NAME} - install_dev_packages ${CHROMEOS_DEVELOPER_IMAGE_NAME} + install_dev_packages ${CHROMEOS_DEVELOPER_IMAGE_NAME} fi -# Create a test or factory test image if desired. -if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then +# From a developer image create a test|factory_test image. +if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then + copy_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} ${CHROMEOS_TEST_IMAGE_NAME} + mod_image_for_test ${CHROMEOS_TEST_IMAGE_NAME} +fi +if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then copy_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} \ ${CHROMEOS_FACTORY_TEST_IMAGE_NAME} mod_image_for_test ${CHROMEOS_FACTORY_TEST_IMAGE_NAME} -elif [ ${FLAGS_test} -eq ${FLAGS_TRUE} ]; then - copy_image ${CHROMEOS_DEVELOPER_IMAGE_NAME} ${CHROMEOS_TEST_IMAGE_NAME} - mod_image_for_test ${CHROMEOS_TEST_IMAGE_NAME} fi rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${ESP_FS_DIR}" @@ -261,14 +241,22 @@ generate_au_zip || echo "Failed generating AU zip file - ignoring Error..." LINK_NAME="${FLAGS_output_root}/${BOARD}/${FLAGS_symlink}" ln -sfT $(basename ${BUILD_DIR}) ${LINK_NAME} -echo "Done. Image created in ${BUILD_DIR}" -echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}" -if [ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]; then +echo "Done. Image(s) created in ${BUILD_DIR}" + +# Print out the images we generated. +if should_build_image ${CHROMEOS_BASE_IMAGE_NAME}; then + echo "Non-developer Chromium OS image created as ${PRISTINE_IMAGE_NAME}" +fi +if should_build_image ${CHROMEOS_FACTORY_SHIM_NAME}; then + echo "Chromium OS Factory install shim created as ${PRISTINE_IMAGE_NAME}" +fi +if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME}; then echo "Developer image created as ${CHROMEOS_DEVELOPER_IMAGE_NAME}" fi -if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then +if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then echo "Factory test image created as ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}" -elif [ ${FLAGS_test} -eq ${FLAGS_TRUE} ]; then +fi +if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then echo "Test image created as ${CHROMEOS_TEST_IMAGE_NAME}" fi diff --git a/build_library/base_image_util.sh b/build_library/base_image_util.sh index 4e337ed67d..5f3922064b 100755 --- a/build_library/base_image_util.sh +++ b/build_library/base_image_util.sh @@ -146,21 +146,13 @@ create_base_image() { --strip-components=3 --exclude=usr/include --exclude=sys-include \ --exclude=*.a --exclude=*.o - # If it's a developer image, also copy over the libc debug info so that gdb - # works with threads and also for a better debugging experience. - if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]] ; then - sudo mkdir -p "${ROOT_FS_DIR}/usr/local/lib/debug" - sudo tar jxpf "${LIBC_PATH}" -C "${ROOT_FS_DIR}/usr/local/lib/debug" \ - ./usr/lib/debug/usr/${CHOST} --strip-components=6 - fi - . "${SRC_ROOT}/platform/dev/toolchain_utils.sh" board_ctarget=$(get_ctarget_from_board "${BOARD}") for atom in $(portageq match / cross-$board_ctarget/gcc); do copy_gcc_libs "${ROOT_FS_DIR}" $atom done - if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then + if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then # Install our custom factory install kernel with the appropriate use flags # to the image. emerge_custom_kernel "${ROOT_FS_DIR}" @@ -186,8 +178,7 @@ create_base_image() { # not support verified boot yet (see create_legacy_bootloader_templates.sh) # so rootfs verification is disabled if we are building with --factory_install local enable_rootfs_verification= - if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]] && - [[ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]] ; then + if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then enable_rootfs_verification="--enable_rootfs_verification" fi @@ -198,7 +189,7 @@ create_base_image() { ${enable_rootfs_verification} # Don't test the factory install shim - if [ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]; then + if ! should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then # Check that the image has been correctly created. test_image_content "$ROOT_FS_DIR" fi @@ -234,7 +225,7 @@ create_base_image() { trap - EXIT USE_DEV_KEYS= - if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then + if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then USE_DEV_KEYS="--use_dev_keys" fi diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index a9a9360a08..172e9ef041 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -47,80 +47,32 @@ get_images_to_build() { esac done + # Set default if none specified. + if [ -z "${IMAGES_TO_BUILD}" ]; then + IMAGES_TO_BUILD=${CHROMEOS_DEVELOPER_IMAGE_NAME} + fi + info "The following images will be built ${IMAGES_TO_BUILD}." } # Look at flags to determine which image types we should build. parse_build_image_args() { - # If argv is specified, we use the new parsing method to determine exactly - # which images we need to build and the flags to set. - if [ -n "${FLAGS_ARGV}" ]; then - info "Ignoring image flags since image(s) in $FLAGS_ARGV specified." - get_images_to_build ${FLAGS_ARGV} - # Start at ground zero with all image flags set to False. - FLAGS_withdev=${FLAGS_FALSE} - FLAGS_test=${FLAGS_FALSE} - FLAGS_factory=${FLAGS_FALSE} - FLAGS_factory_install=${FLAGS_FALSE} - if should_build_image ${CHROMEOS_DEVELOPER_IMAGE_NAME}; then - FLAGS_withdev=${FLAGS_TRUE} - fi - if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then - FLAGS_withdev=${FLAGS_TRUE} - FLAGS_test=${FLAGS_TRUE} - if should_build_image "${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"; then - die "Cannot build both the test and factory_test images." - fi - fi - if should_build_image ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; then - FLAGS_withdev=${FLAGS_TRUE} - FLAGS_factory=${FLAGS_TRUE} - fi - if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then - for image in ${CHROMEOS_BASE_IMAGE_NAME} ${CHROMEOS_DEVELOPER_IMAGE_NAME}\ - ${CHROMEOS_TEST_IMAGE_NAME} ${CHROMEOS_FACTORY_TEST_IMAGE_NAME}; do - should_build_image ${image} && die "Can't build both $image" \ - "and ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}." - done - FLAGS_factory_install=${FLAGS_TRUE} - fi - else - # Legacy method for tweaking flags to do the right thing. - if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then - if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then - info "Incompatible flags: --factory and --factory_install cannot both" \ - "be set to True. Resetting --factory to False." - FLAGS_factory=${FLAGS_FALSE} - fi - if [ ${FLAGS_test} -eq ${FLAGS_TRUE} ]; then - info "Incompatible flags: --test and --factory_install cannot both be" \ - "set to True. Resetting --test to False." - FLAGS_test=${FLAGS_FALSE} - fi - # Disable --withdev flag when --factory_install is set to True. Otherwise, - # the dev image produced will be based on install shim, rather than a - # pristine image. - if [ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]; then - info "Incompatible flags: --withdev and --factory_install cannot both" \ - "be set to True. Resetting --withdev to False." - FLAGS_withdev=${FLAGS_FALSE} - fi - fi - if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then - if [ ${FLAGS_test} -eq ${FLAGS_FALSE} ]; then - info "Incompatible flags: --factory implies --test. Resetting --test" \ - "to True." - FLAGS_test=${FLAGS_TRUE} - fi - fi - if [ ${FLAGS_test} -eq ${FLAGS_TRUE} ]; then - if [ ${FLAGS_withdev} -eq ${FLAGS_FALSE} ]; then - info "Incompatible flags: --test implies --withdev. Resetting" \ - "--withdev to True." - FLAGS_withdev=${FLAGS_TRUE} - fi + get_images_to_build ${FLAGS_ARGV} + if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then + if should_build_image "${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"; then + die "Cannot build both the test and factory_test images." fi fi + if should_build_image ${CHROMEOS_BASE_IMAGE_NAME} \ + ${CHROMEOS_DEVELOPER_IMAGE_NAME} ${CHROMEOS_TEST_IMAGE_NAME} \ + ${CHROMEOS_FACTORY_TEST_IMAGE_NAME} && + should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then + die "Can't build ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME} with any other" \ + "image." + fi + if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then + FLAGS_enable_rootfs_verification=${FLAGS_FALSE} + fi } check_blacklist() { diff --git a/build_library/dev_image_util.sh b/build_library/dev_image_util.sh index 4ce42b4e82..4f8fa39bdc 100755 --- a/build_library/dev_image_util.sh +++ b/build_library/dev_image_util.sh @@ -27,6 +27,12 @@ install_dev_packages() { # Install developer packages described in chromeos-dev. emerge_to_image --root="${root_dev_dir}" chromeos-dev + # Copy over the libc debug info so that gdb + # works with threads and also for a better debugging experience. + sudo mkdir -p "${ROOT_FS_DIR}/usr/local/lib/debug" + sudo tar jxpf "${LIBC_PATH}" -C "${ROOT_FS_DIR}/usr/local/lib/debug" \ + ./usr/lib/debug/usr/${CHOST} --strip-components=6 + # Install the bare necessary files so that the "emerge" command works if [ ${FLAGS_statefuldev} -eq ${FLAGS_TRUE} ]; then sudo cp -a ${root_dev_dir}/share/portage ${ROOT_FS_DIR}/usr/share @@ -82,12 +88,6 @@ install_dev_packages() { done fi - # Check that the image has been correctly created. Only do it if not - # building a factory install shim, as the INSTALL_MASK for it will make - # test_image fail. - if [ ${FLAGS_factory_install} -eq ${FLAGS_FALSE} ]; then - test_image_content "$ROOT_FS_DIR" - fi info "Developer image built and stored at ${image_name}" unmount_image diff --git a/build_library/test_image_util.sh b/build_library/test_image_util.sh index ead04a08db..e6d2abbb12 100755 --- a/build_library/test_image_util.sh +++ b/build_library/test_image_util.sh @@ -53,17 +53,18 @@ emerge_to_image() { "$@" ${EMERGE_JOBS} } - -# Returns 0 if this image was requested to be built, 1 otherwise. -# $1 The name of the image to build. +# Returns 0 if any of the images was requested to be built, 1 otherwise. +# $@ The name(s) of the images to check. should_build_image() { # Fast pass back if we should build all incremental images. - local image_name=$1 + local images="$@" + local image_name local image_to_build - [ -z "${IMAGES_TO_BUILD}" ] && return 0 - for image_to_build in ${IMAGES_TO_BUILD}; do - [ ${image_to_build} = ${image_name} ] && return 0 + for image_name in ${images}; do + for image_to_build in ${IMAGES_TO_BUILD}; do + [ ${image_to_build} = ${image_name} ] && return 0 + done done return 1 @@ -120,7 +121,8 @@ mod_image_for_test () { STATEFUL_DIR="${STATEFUL_FS_DIR}" ARCH="${ARCH}" BACKDOOR="${BACKDOOR}" \ "${mod_test_script}" - if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then + if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] || + should_build_image ${CHROMEOS_FACTORY_IMAGE_NAME}; then emerge_to_image --root="${ROOT_FS_DIR}" factorytest-init INSTALL_MASK="${FACTORY_TEST_INSTALL_MASK}" emerge_to_image --root="${ROOT_FS_DIR}/usr/local" \ diff --git a/common.sh b/common.sh index 9e1a01d959..763ca42fbb 100644 --- a/common.sh +++ b/common.sh @@ -257,7 +257,7 @@ FACTORY_TEST_INSTALL_MASK=" /usr/local/autotest/client/site_tests/realtimecomm_GTalk* " -# Mask for factory install shim (build_image --factory_install) +# Mask for factory install shim (build_image factory_install) FACTORY_SHIM_INSTALL_MASK=" $DEFAULT_INSTALL_MASK /opt/[^g]*