| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # Script to archive build results. Used by the buildbots. | 7 # Script to archive build results. Used by the buildbots. |
| 8 | 8 |
| 9 # --- BEGIN COMMON.SH BOILERPLATE --- | 9 # --- BEGIN COMMON.SH BOILERPLATE --- |
| 10 # Load common CrOS utilities. Inside the chroot this file is installed in | 10 # Load common CrOS utilities. Inside the chroot this file is installed in |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 # --- END COMMON.SH BOILERPLATE --- | 28 # --- END COMMON.SH BOILERPLATE --- |
| 29 | 29 |
| 30 # Script must be run outside the chroot | 30 # Script must be run outside the chroot |
| 31 assert_outside_chroot | 31 assert_outside_chroot |
| 32 | 32 |
| 33 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" | 33 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" |
| 34 # Default to the most recent image | 34 # Default to the most recent image |
| 35 DEFAULT_TO="${GCLIENT_ROOT}/archive" | 35 DEFAULT_TO="${GCLIENT_ROOT}/archive" |
| 36 DEFAULT_FROM="${IMAGES_DIR}/$DEFAULT_BOARD/$(ls -t1 \ | 36 DEFAULT_FROM="${IMAGES_DIR}/$DEFAULT_BOARD/$(ls -t1 \ |
| 37 $IMAGES_DIR/$DEFAULT_BOARD 2>&-| head -1)" | 37 $IMAGES_DIR/$DEFAULT_BOARD 2>&-| head -1)" |
| 38 # The set of environment assignment we need to pass to enter_chroots for this |
| 39 # build. e.g. USE flags alter some of the commands' effect. |
| 40 CHROOT_ENV="" |
| 38 | 41 |
| 39 # Flags | 42 # Flags |
| 40 DEFINE_boolean archive_debug $FLAGS_TRUE \ | 43 DEFINE_boolean archive_debug $FLAGS_TRUE \ |
| 41 "Archive debug information for build" | 44 "Archive debug information for build" |
| 42 DEFINE_string board "$DEFAULT_BOARD" \ | 45 DEFINE_string board "$DEFAULT_BOARD" \ |
| 43 "The board to build packages for." | 46 "The board to build packages for." |
| 44 DEFINE_string build_number "" \ | 47 DEFINE_string build_number "" \ |
| 45 "The build-bot build number (when called by buildbot only)." "b" | 48 "The build-bot build number (when called by buildbot only)." "b" |
| 46 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ | 49 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ |
| 47 "The chroot of the build to archive." | 50 "The chroot of the build to archive." |
| (...skipping 16 matching lines...) Expand all Loading... |
| 64 "Optional Whether to append build # and chrome os hash to GS uploads" | 67 "Optional Whether to append build # and chrome os hash to GS uploads" |
| 65 DEFINE_integer keep_max 0 "Maximum builds to keep in archive (0=all)" | 68 DEFINE_integer keep_max 0 "Maximum builds to keep in archive (0=all)" |
| 66 DEFINE_boolean official_build $FLAGS_FALSE \ | 69 DEFINE_boolean official_build $FLAGS_FALSE \ |
| 67 "Set CHROMEOS_OFFICIAL=1 for release builds." | 70 "Set CHROMEOS_OFFICIAL=1 for release builds." |
| 68 DEFINE_string test_tarball "" "Optional path to test tarball to archive" | 71 DEFINE_string test_tarball "" "Optional path to test tarball to archive" |
| 69 DEFINE_boolean test_mod $FLAGS_TRUE "Modify image for testing purposes" | 72 DEFINE_boolean test_mod $FLAGS_TRUE "Modify image for testing purposes" |
| 70 DEFINE_boolean prebuilt_upload $FLAGS_FALSE "Upload prebuilt binary packages." | 73 DEFINE_boolean prebuilt_upload $FLAGS_FALSE "Upload prebuilt binary packages." |
| 71 DEFINE_boolean remove_dev $FLAGS_TRUE "Remove the de image during archive." | 74 DEFINE_boolean remove_dev $FLAGS_TRUE "Remove the de image during archive." |
| 72 DEFINE_string to "$DEFAULT_TO" "Directory of build archive" | 75 DEFINE_string to "$DEFAULT_TO" "Directory of build archive" |
| 73 DEFINE_string zipname "image.zip" "Name of zip file to create." | 76 DEFINE_string zipname "image.zip" "Name of zip file to create." |
| 77 DEFINE_string useflags "" "USE flags to pass into mod_image_* and build_image." |
| 74 | 78 |
| 75 # Parse command line | 79 # Parse command line |
| 76 FLAGS "$@" || exit 1 | 80 FLAGS "$@" || exit 1 |
| 77 eval set -- "${FLAGS_ARGV}" | 81 eval set -- "${FLAGS_ARGV}" |
| 78 | 82 |
| 79 # Set if default from path is used | 83 # Set if default from path is used |
| 80 DEFAULT_USED= | 84 DEFAULT_USED= |
| 81 | 85 |
| 82 # Reset "default" FLAGS_from based on passed-in board if not set on cmd-line | 86 # Reset "default" FLAGS_from based on passed-in board if not set on cmd-line |
| 83 if [ "$FLAGS_from" = "$DEFAULT_FROM" ]; then | 87 if [ "$FLAGS_from" = "$DEFAULT_FROM" ]; then |
| 84 # Keep the directory name of the current image set (*.bin). | 88 # Keep the directory name of the current image set (*.bin). |
| 85 IMG_DIR="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" | 89 IMG_DIR="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" |
| 86 FLAGS_from="${IMAGES_DIR}/${FLAGS_board}/${IMG_DIR}" | 90 FLAGS_from="${IMAGES_DIR}/${FLAGS_board}/${IMG_DIR}" |
| 87 DEFAULT_USED=1 | 91 DEFAULT_USED=1 |
| 88 fi | 92 fi |
| 89 | 93 |
| 90 # Die on any errors. | 94 # Die on any errors. |
| 91 set -e | 95 set -e |
| 92 | 96 |
| 97 if [ -n "${FLAGS_useflags}" ]; then |
| 98 CHROOT_ENV="${CHROOT_ENV} USE='${FLAGS_useflags}'" |
| 99 fi |
| 100 |
| 93 if [ -z "$DEFAULT_USED" ]; then | 101 if [ -z "$DEFAULT_USED" ]; then |
| 94 if [ $FLAGS_test_mod -eq $FLAGS_TRUE ] || \ | 102 if [ $FLAGS_test_mod -eq $FLAGS_TRUE ] || \ |
| 95 [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ] || \ | 103 [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ] || \ |
| 96 [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ] | 104 [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ] |
| 97 then | 105 then |
| 98 echo "test_mod requires that the default from path be used." | 106 echo "test_mod requires that the default from path be used." |
| 99 echo "If non default behavior is desired, run mod_image_for_test manually" | 107 echo "If non default behavior is desired, run mod_image_for_test manually" |
| 100 echo "re-run archive build without test_mod" | 108 echo "re-run archive build without test_mod" |
| 101 exit 1 | 109 exit 1 |
| 102 fi | 110 fi |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 FACTORY_ZIPFILE="${OUTDIR}/factory_${FLAGS_zipname}" | 145 FACTORY_ZIPFILE="${OUTDIR}/factory_${FLAGS_zipname}" |
| 138 echo "archive to dir: $OUTDIR" | 146 echo "archive to dir: $OUTDIR" |
| 139 echo "archive to file: $ZIPFILE" | 147 echo "archive to file: $ZIPFILE" |
| 140 | 148 |
| 141 rm -rf "$OUTDIR" | 149 rm -rf "$OUTDIR" |
| 142 mkdir -p "$OUTDIR" | 150 mkdir -p "$OUTDIR" |
| 143 | 151 |
| 144 # Modify image for test if flag set. | 152 # Modify image for test if flag set. |
| 145 if [ $FLAGS_test_mod -eq $FLAGS_TRUE ]; then | 153 if [ $FLAGS_test_mod -eq $FLAGS_TRUE ]; then |
| 146 echo "Modifying image for test" | 154 echo "Modifying image for test" |
| 147 ./enter_chroot.sh -- ./mod_image_for_test.sh --board $FLAGS_board \ | 155 ./enter_chroot.sh $CHROOT_ENV -- ./mod_image_for_test.sh \ |
| 148 --noinplace --yes | 156 --board $FLAGS_board --noinplace --yes |
| 149 | 157 |
| 150 pushd "${FLAGS_chroot}/build/${FLAGS_board}/usr/local" | 158 pushd "${FLAGS_chroot}/build/${FLAGS_board}/usr/local" |
| 151 echo "Archiving autotest build artifacts" | 159 echo "Archiving autotest build artifacts" |
| 152 tar cjf "${FLAGS_from}/autotest.tar.bz2" --checkpoint=1000 autotest | 160 tar cjf "${FLAGS_from}/autotest.tar.bz2" --checkpoint=1000 autotest |
| 153 popd | 161 popd |
| 154 fi | 162 fi |
| 155 | 163 |
| 156 # Modify for recovery | 164 # Modify for recovery |
| 157 if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then | 165 if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then |
| 158 BUILDVER="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" | 166 BUILDVER="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" |
| 159 CHROOT_IMAGE_DIR=/home/$USER/trunk/src/build/images/$FLAGS_board/$BUILDVER | 167 CHROOT_IMAGE_DIR=/home/$USER/trunk/src/build/images/$FLAGS_board/$BUILDVER |
| 160 ./enter_chroot.sh -- ./mod_image_for_recovery.sh --board $FLAGS_board \ | 168 ./enter_chroot.sh $CHROOT_ENV -- ./mod_image_for_recovery.sh \ |
| 161 --image $CHROOT_IMAGE_DIR/chromiumos_base_image.bin | 169 --board $FLAGS_board --image $CHROOT_IMAGE_DIR/chromiumos_base_image.bin |
| 162 fi | 170 fi |
| 163 | 171 |
| 164 # Remove the developer build if test image is also built. | 172 # Remove the developer build if test image is also built. |
| 165 if [ $FLAGS_remove_dev -eq $FLAGS_TRUE ]; then | 173 if [ $FLAGS_remove_dev -eq $FLAGS_TRUE ]; then |
| 166 rm -f "${FLAGS_from}/${CHROMEOS_IMAGE_NAME}" | 174 rm -f "${FLAGS_from}/${CHROMEOS_IMAGE_NAME}" |
| 167 fi | 175 fi |
| 168 | 176 |
| 169 if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ]; then | 177 if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ]; then |
| 170 echo "Generating image for factory test" | 178 echo "Generating image for factory test" |
| 171 # HACK: The build system can't currently handle more than one image size | 179 # HACK: The build system can't currently handle more than one image size |
| 172 # at a time. Therefore it's necessary to do another round of build after | 180 # at a time. Therefore it's necessary to do another round of build after |
| 173 # archiving the original build. This should be fixed in Chromite. | 181 # archiving the original build. This should be fixed in Chromite. |
| 174 | 182 |
| 175 # HACK: cbuild has a special case when running on chrome-bot that | 183 # HACK: cbuild has a special case when running on chrome-bot that |
| 176 # zeroes out the current revision, which makes calling build_image directly | 184 # zeroes out the current revision, which makes calling build_image directly |
| 177 # fail. You must explictly call replace and specify a unique name numerically | 185 # fail. You must explictly call replace and specify a unique name numerically |
| 178 # using build_attempt. | 186 # using build_attempt. |
| 179 ./enter_chroot.sh -- ./build_image --board $FLAGS_board \ | 187 ./enter_chroot.sh $CHROOT_ENV -- ./build_image --board $FLAGS_board \ |
| 180 --replace --noenable_rootfs_verification --build_attempt 4 | 188 --replace --noenable_rootfs_verification --build_attempt 4 |
| 181 | 189 |
| 182 ./enter_chroot.sh -- ./mod_image_for_test.sh --board $FLAGS_board \ | 190 ./enter_chroot.sh $CHROOT_ENV -- ./mod_image_for_test.sh \ |
| 183 --yes --noinplace --factory | 191 --board $FLAGS_board --yes --noinplace --factory |
| 184 | 192 |
| 185 # Get the factory test dir: It is the newest build. | 193 # Get the factory test dir: It is the newest build. |
| 186 # This is the output dir for the factory shim, the factory test and | 194 # This is the output dir for the factory shim, the factory test and |
| 187 # release images will remain in IMG_DIR, defined previously. | 195 # release images will remain in IMG_DIR, defined previously. |
| 188 FACTORY_DIR="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" | 196 FACTORY_DIR="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" |
| 189 | 197 |
| 190 echo "Factory image dir: ${FACTORY_DIR}" | 198 echo "Factory image dir: ${FACTORY_DIR}" |
| 191 fi | 199 fi |
| 192 | 200 |
| 193 # Build differently sized shims. Currently only factory install shim is | 201 # Build differently sized shims. Currently only factory install shim is |
| 194 # supported, TODO(tgao): Add developer shim. | 202 # supported, TODO(tgao): Add developer shim. |
| 195 if [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ]; then | 203 if [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ]; then |
| 196 echo "Building factory install shim." | 204 echo "Building factory install shim." |
| 197 # HACK: The build system can't currently handle more than one image size | 205 # HACK: The build system can't currently handle more than one image size |
| 198 # at a time. Therefore it's necessary to do another round of build after | 206 # at a time. Therefore it's necessary to do another round of build after |
| 199 # archiving the original build. This should be fixed in Chromite. | 207 # archiving the original build. This should be fixed in Chromite. |
| 200 | 208 |
| 201 # HACK: cbuild has a special case when running on chrome-bot that | 209 # HACK: cbuild has a special case when running on chrome-bot that |
| 202 # zeroes out the current revision, which makes calling build_image directly | 210 # zeroes out the current revision, which makes calling build_image directly |
| 203 # fail. You must explictly call replace and specify a unique name numerically | 211 # fail. You must explictly call replace and specify a unique name numerically |
| 204 # using build_attempt. | 212 # using build_attempt. |
| 205 ./enter_chroot.sh -- ./build_image --board $FLAGS_board --factory_install \ | 213 ./enter_chroot.sh $CHROOT_ENV -- ./build_image --board $FLAGS_board \ |
| 206 --replace --build_attempt 7 | 214 --factory_install --replace --build_attempt 7 |
| 207 | 215 |
| 208 # Get the install shim dir: It is the newest build. | 216 # Get the install shim dir: It is the newest build. |
| 209 # This is the output dir for the factory shim, the factory test and | 217 # This is the output dir for the factory shim, the factory test and |
| 210 # release images will remain in IMG_DIR, defined previously. | 218 # release images will remain in IMG_DIR, defined previously. |
| 211 SHIM_DIR="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" | 219 SHIM_DIR="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" |
| 212 | 220 |
| 213 echo "Factory install shim dir: ${SHIM_DIR}" | 221 echo "Factory install shim dir: ${SHIM_DIR}" |
| 214 fi | 222 fi |
| 215 | 223 |
| 216 # Zip the build | 224 # Zip the build |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 # Purge old builds if necessary | 359 # Purge old builds if necessary |
| 352 if [ $FLAGS_keep_max -gt 0 ]; then | 360 if [ $FLAGS_keep_max -gt 0 ]; then |
| 353 echo "Deleting old builds (all but the newest ${FLAGS_keep_max})..." | 361 echo "Deleting old builds (all but the newest ${FLAGS_keep_max})..." |
| 354 cd "$FLAGS_to" | 362 cd "$FLAGS_to" |
| 355 # +2 because line numbers start at 1 and need to skip LATEST file | 363 # +2 because line numbers start at 1 and need to skip LATEST file |
| 356 rm -rf `ls -t1 | tail --lines=+$(($FLAGS_keep_max + 2))` | 364 rm -rf `ls -t1 | tail --lines=+$(($FLAGS_keep_max + 2))` |
| 357 cd - | 365 cd - |
| 358 fi | 366 fi |
| 359 | 367 |
| 360 echo "Done." | 368 echo "Done." |
| OLD | NEW |