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 <jrbarnette@chromium.org>
Commit-Ready: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
This commit is contained in:
Gilad Arnold 2012-02-13 11:31:58 -08:00 committed by Gerrit
parent a0a02f4c3a
commit dd59d7e9a6
2 changed files with 39 additions and 37 deletions

View File

@ -230,20 +230,26 @@ fi
STATEFUL_DIR="${FLAGS_from}/stateful_partition"
mkdir -p "${STATEFUL_DIR}"
# Autodetect image.
if [ -z "${FLAGS_image_name}" ]; then
# 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[@]}"
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
@ -267,17 +273,13 @@ if [ -z "${FLAGS_image_name}" ]; then
fi
FLAGS_image_name="${image}"
fi
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

View File

@ -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