| 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 # Load common constants. This should be the first executable line. | 9 # Load common constants. This should be the first executable line. |
| 10 # The path to common.sh should be relative to your script's location. | 10 # The path to common.sh should be relative to your script's location. |
| 11 . "$(dirname "$0")/common.sh" | 11 . "$(dirname "$0")/common.sh" |
| 12 | 12 |
| 13 # Script must be run outside the chroot | 13 # Script must be run outside the chroot |
| 14 assert_outside_chroot | 14 assert_outside_chroot |
| 15 | 15 |
| 16 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" | 16 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" |
| 17 # Default to the most recent image | 17 # Default to the most recent image |
| 18 DEFAULT_TO="${GCLIENT_ROOT}/archive" | 18 DEFAULT_TO="${GCLIENT_ROOT}/archive" |
| 19 DEFAULT_FROM="${IMAGES_DIR}/$DEFAULT_BOARD/$(ls -t1 \ | 19 DEFAULT_FROM="${IMAGES_DIR}/$DEFAULT_BOARD/$(ls -t1 \ |
| 20 $IMAGES_DIR/$DEFAULT_BOARD 2>&-| head -1)" | 20 $IMAGES_DIR/$DEFAULT_BOARD 2>&-| head -1)" |
| 21 | 21 |
| 22 # Flags | 22 # Flags |
| 23 DEFINE_boolean archive_debug $FLAGS_TRUE \ |
| 24 "Archive debug information for build" |
| 23 DEFINE_string board "$DEFAULT_BOARD" \ | 25 DEFINE_string board "$DEFAULT_BOARD" \ |
| 24 "The board to build packages for." | 26 "The board to build packages for." |
| 27 DEFINE_string build_number "" \ |
| 28 "The build-bot build number (when called by buildbot only)." "b" |
| 25 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ | 29 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ |
| 26 "The chroot of the build to archive." | 30 "The chroot of the build to archive." |
| 31 DEFINE_boolean factory_install_mod $FLAGS_FALSE \ |
| 32 "Modify image for factory install purposes" |
| 33 DEFINE_boolean factory_test_mod $FLAGS_FALSE \ |
| 34 "Modify image for factory testing purposes" |
| 27 DEFINE_string from "$DEFAULT_FROM" \ | 35 DEFINE_string from "$DEFAULT_FROM" \ |
| 28 "Directory to archive" | 36 "Directory to archive" |
| 29 DEFINE_string to "$DEFAULT_TO" "Directory of build archive" | |
| 30 DEFINE_integer keep_max 0 "Maximum builds to keep in archive (0=all)" | |
| 31 DEFINE_string zipname "image.zip" "Name of zip file to create." | |
| 32 DEFINE_boolean official_build $FLAGS_FALSE "Set CHROMEOS_OFFICIAL=1 for release
builds." | |
| 33 DEFINE_string build_number "" \ | |
| 34 "The build-bot build number (when called by buildbot only)." "b" | |
| 35 DEFINE_boolean test_mod $FLAGS_TRUE "Modify image for testing purposes" | |
| 36 DEFINE_boolean factory_test_mod $FLAGS_FALSE \ | |
| 37 "Modify image for factory testing purposes" | |
| 38 DEFINE_boolean factory_install_mod $FLAGS_FALSE \ | |
| 39 "Modify image for factory install purposes" | |
| 40 DEFINE_string gsutil "gsutil" \ | 37 DEFINE_string gsutil "gsutil" \ |
| 41 "Location of gsutil" | 38 "Location of gsutil" |
| 42 DEFINE_string gsd_gen_index "" \ | 39 DEFINE_string gsd_gen_index "" \ |
| 43 "Location of gsd_generate_index.py" | 40 "Location of gsd_generate_index.py" |
| 44 DEFINE_string acl "private" \ | 41 DEFINE_string acl "private" \ |
| 45 "ACL to set on GSD archives" | 42 "ACL to set on GSD archives" |
| 46 DEFINE_string gsutil_archive "" \ | 43 DEFINE_string gsutil_archive "" \ |
| 47 "Optional datastore archive location" | 44 "Optional datastore archive location" |
| 45 DEFINE_integer keep_max 0 "Maximum builds to keep in archive (0=all)" |
| 46 DEFINE_boolean official_build $FLAGS_FALSE "Set CHROMEOS_OFFICIAL=1 for release
builds." |
| 47 DEFINE_boolean test_mod $FLAGS_TRUE "Modify image for testing purposes" |
| 48 DEFINE_string to "$DEFAULT_TO" "Directory of build archive" |
| 49 DEFINE_string zipname "image.zip" "Name of zip file to create." |
| 48 | 50 |
| 49 # Parse command line | 51 # Parse command line |
| 50 FLAGS "$@" || exit 1 | 52 FLAGS "$@" || exit 1 |
| 51 eval set -- "${FLAGS_ARGV}" | 53 eval set -- "${FLAGS_ARGV}" |
| 52 | 54 |
| 53 # Set if default from path is used | 55 # Set if default from path is used |
| 54 DEFAULT_USED= | 56 DEFAULT_USED= |
| 55 | 57 |
| 56 # Reset "default" FLAGS_from based on passed-in board if not set on cmd-line | 58 # Reset "default" FLAGS_from based on passed-in board if not set on cmd-line |
| 57 if [ "$FLAGS_from" = "$DEFAULT_FROM" ] | 59 if [ "$FLAGS_from" = "$DEFAULT_FROM" ] |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 echo "$LAST_CHANGE" > "${FLAGS_to}/LATEST" | 183 echo "$LAST_CHANGE" > "${FLAGS_to}/LATEST" |
| 182 | 184 |
| 183 # Make sure files are readable | 185 # Make sure files are readable |
| 184 chmod 644 "$ZIPFILE" "${FLAGS_to}/LATEST" | 186 chmod 644 "$ZIPFILE" "${FLAGS_to}/LATEST" |
| 185 chmod 755 "$OUTDIR" | 187 chmod 755 "$OUTDIR" |
| 186 | 188 |
| 187 | 189 |
| 188 function gsutil_archive() { | 190 function gsutil_archive() { |
| 189 IN_PATH="$1" | 191 IN_PATH="$1" |
| 190 OUT_PATH="$2" | 192 OUT_PATH="$2" |
| 191 if [ $FLAGS_gsutil_archive != "" ] | 193 if [ -n "$FLAGS_gsutil_archive" ] |
| 192 then | 194 then |
| 193 FULL_OUT_PATH="${FLAGS_gsutil_archive}/${OUT_PATH}" | 195 FULL_OUT_PATH="${FLAGS_gsutil_archive}/${OUT_PATH}" |
| 194 echo "Using gsutil to archive to ${OUT_PATH}..." | 196 echo "Using gsutil to archive to ${OUT_PATH}..." |
| 195 ${FLAGS_gsutil} cp ${IN_PATH} ${FULL_OUT_PATH} | 197 ${FLAGS_gsutil} cp ${IN_PATH} ${FULL_OUT_PATH} |
| 196 ${FLAGS_gsutil} setacl ${FLAGS_acl} ${FULL_OUT_PATH} | 198 ${FLAGS_gsutil} setacl ${FLAGS_acl} ${FULL_OUT_PATH} |
| 197 if [ $FLAGS_gsd_gen_index != "" ] | 199 if [ $FLAGS_gsd_gen_index != "" ] |
| 198 then | 200 then |
| 199 echo "Updating indexes..." | 201 echo "Updating indexes..." |
| 200 ${FLAGS_gsd_gen_index} \ | 202 ${FLAGS_gsd_gen_index} \ |
| 201 --gsutil=${FLAGS_gsutil} \ | 203 --gsutil=${FLAGS_gsutil} \ |
| 202 -a ${FLAGS_acl} \ | 204 -a ${FLAGS_acl} \ |
| 203 -p ${FULL_OUT_PATH} ${FLAGS_gsutil_archive} | 205 -p ${FULL_OUT_PATH} ${FLAGS_gsutil_archive} |
| 204 fi | 206 fi |
| 205 fi | 207 fi |
| 206 } | 208 } |
| 207 | 209 |
| 208 if [ $FLAGS_test_mod -eq $FLAGS_TRUE -a $FLAGS_official_build -eq $FLAGS_TRUE ] | 210 if [ $FLAGS_test_mod -eq $FLAGS_TRUE -a $FLAGS_official_build -eq $FLAGS_TRUE ] |
| 209 then | 211 then |
| 210 echo "Creating hwqual archive" | 212 echo "Creating hwqual archive" |
| 211 HWQUAL_NAME="chromeos-hwqual-${FLAGS_board}-${CHROMEOS_VERSION_STRING}" | 213 HWQUAL_NAME="chromeos-hwqual-${FLAGS_board}-${CHROMEOS_VERSION_STRING}" |
| 212 "${SCRIPTS_DIR}/archive_hwqual" --from "${OUTDIR}" \ | 214 "${SCRIPTS_DIR}/archive_hwqual" --from "${OUTDIR}" \ |
| 213 --output_tag "${HWQUAL_NAME}" | 215 --output_tag "${HWQUAL_NAME}" |
| 214 gsutil_archive "${OUTDIR}/${HWQUAL_NAME}.tar.bz2" \ | 216 gsutil_archive "${OUTDIR}/${HWQUAL_NAME}.tar.bz2" \ |
| 215 "${LAST_CHANGE}/${HWQUAL_NAME}.tar.bz2" | 217 "${LAST_CHANGE}/${HWQUAL_NAME}.tar.bz2" |
| 216 fi | 218 fi |
| 217 | 219 |
| 220 if [ $FLAGS_archive_debug -eq $FLAGS_TRUE ] |
| 221 then |
| 222 echo "Creating debug archive" |
| 223 pushd "${FLAGS_chroot}/build/${FLAGS_board}/usr/lib" |
| 224 sudo tar czf "${OUTDIR}/debug.tgz" --exclude debug/usr/local/autotest \ |
| 225 --exclude debug/tests debug |
| 226 CMD="chown \${SUDO_UID}:\${SUDO_GID} ${OUTDIR}/debug.tgz" |
| 227 sudo sh -c "${CMD}" |
| 228 popd |
| 229 fi |
| 230 |
| 218 gsutil_archive "${ZIPFILE}" "${LAST_CHANGE}/${FLAGS_zipname}" | 231 gsutil_archive "${ZIPFILE}" "${LAST_CHANGE}/${FLAGS_zipname}" |
| 219 if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ] || \ | 232 if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ] || \ |
| 220 [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ] | 233 [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ] |
| 221 then | 234 then |
| 222 gsutil_archive "${FACTORY_ZIPFILE}" \ | 235 gsutil_archive "${FACTORY_ZIPFILE}" \ |
| 223 "${LAST_CHANGE}/factory_${FLAGS_zipname}" | 236 "${LAST_CHANGE}/factory_${FLAGS_zipname}" |
| 224 fi | 237 fi |
| 225 gsutil_archive "${FLAGS_to}/LATEST" "LATEST" | 238 gsutil_archive "${FLAGS_to}/LATEST" "LATEST" |
| 226 | 239 |
| 227 # Purge old builds if necessary | 240 # Purge old builds if necessary |
| 228 if [ $FLAGS_keep_max -gt 0 ] | 241 if [ $FLAGS_keep_max -gt 0 ] |
| 229 then | 242 then |
| 230 echo "Deleting old builds (all but the newest ${FLAGS_keep_max})..." | 243 echo "Deleting old builds (all but the newest ${FLAGS_keep_max})..." |
| 231 cd "$FLAGS_to" | 244 cd "$FLAGS_to" |
| 232 # +2 because line numbers start at 1 and need to skip LATEST file | 245 # +2 because line numbers start at 1 and need to skip LATEST file |
| 233 rm -rf `ls -t1 | tail --lines=+$(($FLAGS_keep_max + 2))` | 246 rm -rf `ls -t1 | tail --lines=+$(($FLAGS_keep_max + 2))` |
| 234 cd - | 247 cd - |
| 235 fi | 248 fi |
| 236 | 249 |
| 237 echo "Done." | 250 echo "Done." |
| OLD | NEW |