From dd59d7e9a6f54d2f2decd4ff247101db998c376e Mon Sep 17 00:00:00 2001 From: Gilad Arnold Date: Mon, 13 Feb 2012 11:31:58 -0800 Subject: [PATCH] image_to_usb.sh: do not require chromiumos_image.bin when --test_image is used. The recent changes to image_to_usb.sh assumed that chromiumos_image.bin is always used for generating a test image. This wasn't the case before these changes were applied, where a preexisting test image would have sufficed. This fix eliminates image autodetection entirely when --test_image it used and falls back to the old behavior: if a test image exists, it will use it; otherwise, it will generate it from the image specified by --image_name, or from the default chromiumos_image.bin. This is not to say that I like this behavior: it is subtle, may lead to errors (e.g. using a stale test image whereas the user assumes a new one should be generated), and inconsistent with other behaviors (e.g. installing a recovery image, where no image generation takes place at all). I believe that long term we should eliminate the generation of test images from image_to_usb.sh and have users invoke the necessary scripts (like mod_image_for_test.sh) explicitly. BUG=chromium-os:26239 TEST=Ran script with different combinations of --test_image, --image_name and image files present. Change-Id: Ib2491a7e45e23eb51ced6ef31d3f129ec7863a25 Reviewed-on: https://gerrit.chromium.org/gerrit/15764 Reviewed-by: Richard Barnette Commit-Ready: Gilad Arnold Tested-by: Gilad Arnold --- image_to_usb.sh | 74 ++++++++++++++++++++++--------------------- mod_image_for_test.sh | 2 +- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/image_to_usb.sh b/image_to_usb.sh index 173fa14ff1..ab61816b4b 100755 --- a/image_to_usb.sh +++ b/image_to_usb.sh @@ -230,54 +230,56 @@ fi STATEFUL_DIR="${FLAGS_from}/stateful_partition" mkdir -p "${STATEFUL_DIR}" -# Autodetect image. -if [ -z "${FLAGS_image_name}" ]; then - echo "No image name specified, autodetecting..." +# Figure out which image to use. +if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ]; then + # Test image requested: pass the provided (or otherwise default) image name + # to the method that's in charge of preparing a test image (note that this + # image may or may not exist). The test image filename is returned in + # CHROMEOS_RETURN_VAL. + prepare_test_image "${FLAGS_from}" \ + "${FLAGS_image_name:=${CHROMEOS_IMAGE_NAME}}" + SRC_IMAGE="${CHROMEOS_RETURN_VAL}" +else + # Auto-detect and select an image name if none provided. + if [ -z "${FLAGS_image_name}" ]; then + echo "No image name specified, autodetecting..." - # Obtain list of available images that can be used. - image_candidate_list=( "${CHROMEOS_IMAGE_NAME}" ) - if [ ${FLAGS_test_image} -eq ${FLAGS_FALSE} ]; then - # Generation of test image not signaled, look for other images as well. - image_candidate_list=( "${image_candidate_list[@]}" + # Obtain list of available images that can be used. + image_candidate_list=( "${CHROMEOS_IMAGE_NAME}" "${CHROMEOS_RECOVERY_IMAGE_NAME}" "${CHROMEOS_TEST_IMAGE_NAME}" "${CHROMEOS_FACTORY_TEST_IMAGE_NAME}" "${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}" ) - fi - unset image_list - for image_candidate in "${image_candidate_list[@]}"; do - if [ -f "${FLAGS_from}/${image_candidate}" ]; then - image_list=( "${image_list[@]}" "${image_candidate}" ) - fi - done + unset image_list + for image_candidate in "${image_candidate_list[@]}"; do + if [ -f "${FLAGS_from}/${image_candidate}" ]; then + image_list=( "${image_list[@]}" "${image_candidate}" ) + fi + done - num_images=${#image_list[*]} - if (( ${num_images} == 0 )); then - die "No candidate images could be detected" - elif (( ${num_images} == 1)); then - image="${image_list}" - echo "Found image ${image}" - else - # Select one from a list of available images; default to the first. - PS3="Select an image [1]: " - choose image "${image_list}" "ERROR" "${image_list[@]}" - if [ "${image}" == "ERROR" ]; then - die "Invalid selection" + num_images=${#image_list[*]} + if (( ${num_images} == 0 )); then + die "No candidate images could be detected" + elif (( ${num_images} == 1)); then + image="${image_list}" + echo "Found image ${image}" + else + # Select one from a list of available images; default to the first. + PS3="Select an image [1]: " + choose image "${image_list}" "ERROR" "${image_list[@]}" + if [ "${image}" == "ERROR" ]; then + die "Invalid selection" + fi fi + + FLAGS_image_name="${image}" fi - FLAGS_image_name="${image}" -fi - -if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then - # Make a test image - this returns the test filename in CHROMEOS_RETURN_VAL - prepare_test_image "${FLAGS_from}" "${FLAGS_image_name}" - SRC_IMAGE="${CHROMEOS_RETURN_VAL}" -else - # Use the standard image + # Use the selected image. SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}" fi +# Make sure that the selected image exists. if [ ! -f "${SRC_IMAGE}" ]; then die "Image not found: ${SRC_IMAGE}" fi diff --git a/mod_image_for_test.sh b/mod_image_for_test.sh index 07240b42d3..7ee3b1d79b 100755 --- a/mod_image_for_test.sh +++ b/mod_image_for_test.sh @@ -78,7 +78,7 @@ if [ $FLAGS_inplace -eq $FLAGS_FALSE ]; then copy_image $(basename "$FLAGS_image") $(basename "$TEST_PATHNAME") FLAGS_image="$TEST_PATHNAME" else - echo "Using cached $(basename "$FLAGS_image")" + echo "Using cached $(basename "${TEST_PATHNAME}")" exit fi