Add an advanced option to build_image so that a caller can specify the version.

This change adds the ability for a caller to pass a specific version name
to build_image rather than rely on parsing of chromeos_version.sh + attempt
number.

BUG=chromium-os:29077
TEST=Ran build_image w/ w/out option

Change-Id: I69b76ae4bfc148325686902606476a0aae293e56
Reviewed-on: https://gerrit.chromium.org/gerrit/21391
Reviewed-by: Brian Harring <ferringb@chromium.org>
Tested-by: Chris Sosa <sosa@chromium.org>
diff --git a/build_image b/build_image
index 67564d9..fc6dd05 100755
--- a/build_image
+++ b/build_image
@@ -62,6 +62,8 @@
 # not needed for the typical developer workflow.
 DEFINE_integer build_attempt 1 \
   "The build attempt for this image build."
+DEFINE_string version "" \
+  "Overrides version number in name to this version."
 DEFINE_integer jobs -1 \
   "How many packages to build in parallel at maximum."
 DEFINE_boolean replace ${FLAGS_FALSE} \
diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh
index 172e9ef..d2cbfeb 100755
--- a/build_library/build_image_util.sh
+++ b/build_library/build_image_util.sh
@@ -11,8 +11,13 @@
 
 # Use canonical path since some tools (e.g. mount) do not like symlinks.
 # Append build attempt to output directory.
-IMAGE_SUBDIR="R${CHROME_BRANCH}-${CHROMEOS_VERSION_STRING}-a\
+IMAGE_SUBDIR="R${CHROME_BRANCH}"
+if [ -z "${FLAGS_version}" ]; then
+  IMAGE_SUBDIR="${IMAGE_SUBDIR}-${CHROMEOS_VERSION_STRING}-a\
 ${FLAGS_build_attempt}"
+else
+  IMAGE_SUBDIR="${IMAGE_SUBDIR}-${FLAGS_version}"
+fi
 BUILD_DIR="${FLAGS_output_root}/${BOARD}/${IMAGE_SUBDIR}"
 OUTSIDE_OUTPUT_DIR="../build/images/${BOARD}/${IMAGE_SUBDIR}"
 IMAGES_TO_BUILD=