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_string board "$DEFAULT_BOARD" \ | 23 DEFINE_string board "$DEFAULT_BOARD" \ |
24 "The board to build packages for." | 24 "The board to build packages for." |
25 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ | 25 DEFINE_string chroot "$DEFAULT_CHROOT_DIR" \ |
26 "The chroot of the build to archive." | 26 "The chroot of the build to archive." |
27 DEFINE_string from "$DEFAULT_FROM" \ | 27 DEFINE_string from "$DEFAULT_FROM" \ |
28 "Directory to archive" | 28 "Directory to archive" |
29 DEFINE_string to "$DEFAULT_TO" "Directory of build 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)" | 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." | 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." | 32 DEFINE_boolean official_build $FLAGS_FALSE "Set CHROMEOS_OFFICIAL=1 for release
builds." |
33 DEFINE_string build_number "" \ | 33 DEFINE_string build_number "" \ |
34 "The build-bot build number (when called by buildbot only)." "b" | 34 "The build-bot build number (when called by buildbot only)." "b" |
35 DEFINE_boolean test_mod $FLAGS_TRUE "Modify image for testing purposes" | 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" |
36 | 40 |
37 # Parse command line | 41 # Parse command line |
38 FLAGS "$@" || exit 1 | 42 FLAGS "$@" || exit 1 |
39 eval set -- "${FLAGS_ARGV}" | 43 eval set -- "${FLAGS_ARGV}" |
40 | 44 |
41 # Set if default from path is used | 45 # Set if default from path is used |
42 DEFAULT_USED= | 46 DEFAULT_USED= |
43 | 47 |
44 # Reset "default" FLAGS_from based on passed-in board if not set on cmd-line | 48 # Reset "default" FLAGS_from based on passed-in board if not set on cmd-line |
45 if [ "$FLAGS_from" = "$DEFAULT_FROM" ] | 49 if [ "$FLAGS_from" = "$DEFAULT_FROM" ] |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 fi | 92 fi |
89 | 93 |
90 # The Chromium buildbot scripts only create a clickable link to the archive | 94 # The Chromium buildbot scripts only create a clickable link to the archive |
91 # if an output line of the form "last change: XXX" exists | 95 # if an output line of the form "last change: XXX" exists |
92 echo "last change: $LAST_CHANGE" | 96 echo "last change: $LAST_CHANGE" |
93 echo "archive from: $FLAGS_from" | 97 echo "archive from: $FLAGS_from" |
94 | 98 |
95 # Create the output directory | 99 # Create the output directory |
96 OUTDIR="${FLAGS_to}/${LAST_CHANGE}" | 100 OUTDIR="${FLAGS_to}/${LAST_CHANGE}" |
97 ZIPFILE="${OUTDIR}/${FLAGS_zipname}" | 101 ZIPFILE="${OUTDIR}/${FLAGS_zipname}" |
| 102 FACTORY_ZIPFILE="${OUTDIR}/factory_${FLAGS_zipname}" |
98 echo "archive to dir: $OUTDIR" | 103 echo "archive to dir: $OUTDIR" |
99 echo "archive to file: $ZIPFILE" | 104 echo "archive to file: $ZIPFILE" |
100 | 105 |
101 rm -rf "$OUTDIR" | 106 rm -rf "$OUTDIR" |
102 mkdir -p "$OUTDIR" | 107 mkdir -p "$OUTDIR" |
103 | 108 |
| 109 |
| 110 SRC_IMAGE="${FLAGS_from}/chromiumos_image.bin" |
| 111 BACKUP_IMAGE="${FLAGS_from}/chromiumos_image_bkup.bin" |
| 112 |
| 113 # Apply mod_image_for_test to the developer image, and store the |
| 114 # result in a new location. Usage: |
| 115 # do_chroot_mod "$OUTPUT_IMAGE" "--flags_to_mod_image_for_test" |
| 116 function do_chroot_mod() { |
| 117 MOD_ARGS=$2 |
| 118 OUTPUT_IMAGE=$1 |
| 119 cp -f "${SRC_IMAGE}" "${BACKUP_IMAGE}" |
| 120 ./enter_chroot.sh -- ./mod_image_for_test.sh --board $FLAGS_board \ |
| 121 --yes ${MOD_ARGS} |
| 122 mv "${SRC_IMAGE}" "${OUTPUT_IMAGE}" |
| 123 mv "${BACKUP_IMAGE}" "${SRC_IMAGE}" |
| 124 } |
| 125 |
104 # Modify image for test if flag set. | 126 # Modify image for test if flag set. |
105 if [ $FLAGS_test_mod -eq $FLAGS_TRUE ] | 127 if [ $FLAGS_test_mod -eq $FLAGS_TRUE ] |
106 then | 128 then |
107 echo "Modifying image for test" | 129 echo "Modifying image for test" |
108 SRC_IMAGE="${FLAGS_from}/chromiumos_image.bin" | 130 do_chroot_mod "${FLAGS_from}/chromiumos_test_image.bin" "" |
109 ./enter_chroot.sh -- ./mod_image_for_test.sh --board $FLAGS_board --yes | 131 |
110 mv "$SRC_IMAGE" "${FLAGS_from}/chromiumos_test_image.bin" | 132 pushd "${FLAGS_chroot}/build/${FLAGS_board}/usr/local" |
111 cd "${FLAGS_chroot}/build/${FLAGS_board}/usr/local" | |
112 echo "Archiving autotest build artifacts" | 133 echo "Archiving autotest build artifacts" |
113 tar cjf "${FLAGS_from}/autotest.tar.bz2" autotest | 134 tar cjf "${FLAGS_from}/autotest.tar.bz2" autotest |
| 135 popd |
114 fi | 136 fi |
115 | 137 |
| 138 if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ] |
| 139 then |
| 140 echo "Modifying image for factory test" |
| 141 do_chroot_mod "${FLAGS_from}/chromiumos_factory_image.bin" \ |
| 142 "--factory" |
| 143 fi |
| 144 |
| 145 if [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ] |
| 146 then |
| 147 echo "Modifying image for factory install" |
| 148 do_chroot_mod "${FLAGS_from}/chromiumos_factory_install_image.bin" \ |
| 149 "--factory_install" |
| 150 fi |
| 151 |
| 152 # Remove the developer build. |
| 153 rm -f ${SRC_IMAGE} |
| 154 |
116 # Zip the build | 155 # Zip the build |
117 echo "Compressing and archiving build..." | 156 echo "Compressing and archiving build..." |
118 cd "$FLAGS_from" | 157 cd "$FLAGS_from" |
119 zip -r "$ZIPFILE" * | 158 MANIFEST=`ls | grep -v factory` |
| 159 zip -r "${ZIPFILE}" ${MANIFEST} |
| 160 |
| 161 if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ] || \ |
| 162 [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ] |
| 163 then |
| 164 FACTORY_MANIFEST=`ls | grep factory` |
| 165 zip -r "${FACTORY_ZIPFILE}" ${FACTORY_MANIFEST} |
| 166 fi |
120 cd - | 167 cd - |
121 | 168 |
122 # Update LATEST file | 169 # Update LATEST file |
123 echo "$LAST_CHANGE" > "${FLAGS_to}/LATEST" | 170 echo "$LAST_CHANGE" > "${FLAGS_to}/LATEST" |
124 | 171 |
125 # Make sure files are readable | 172 # Make sure files are readable |
126 chmod 644 "$ZIPFILE" "${FLAGS_to}/LATEST" | 173 chmod 644 "$ZIPFILE" "${FLAGS_to}/LATEST" |
127 chmod 755 "$OUTDIR" | 174 chmod 755 "$OUTDIR" |
128 | 175 |
129 if [ $FLAGS_test_mod -eq $FLAGS_TRUE -a $FLAGS_official_build -eq $FLAGS_TRUE ] | 176 if [ $FLAGS_test_mod -eq $FLAGS_TRUE -a $FLAGS_official_build -eq $FLAGS_TRUE ] |
130 then | 177 then |
131 echo "Creating hwqual archive" | 178 echo "Creating hwqual archive" |
132 HWQUAL_NAME="chromeos-hwqual-${FLAGS_board}-${CHROMEOS_VERSION_STRING}" | 179 HWQUAL_NAME="chromeos-hwqual-${FLAGS_board}-${CHROMEOS_VERSION_STRING}" |
133 "${SCRIPTS_DIR}/archive_hwqual" --from "${OUTDIR}" \ | 180 "${SCRIPTS_DIR}/archive_hwqual" --from "${OUTDIR}" \ |
134 --output_tag "${HWQUAL_NAME}" | 181 --output_tag "${HWQUAL_NAME}" |
135 fi | 182 fi |
136 | 183 |
137 # Purge old builds if necessary | 184 # Purge old builds if necessary |
138 if [ $FLAGS_keep_max -gt 0 ] | 185 if [ $FLAGS_keep_max -gt 0 ] |
139 then | 186 then |
140 echo "Deleting old builds (all but the newest ${FLAGS_keep_max})..." | 187 echo "Deleting old builds (all but the newest ${FLAGS_keep_max})..." |
141 cd "$FLAGS_to" | 188 cd "$FLAGS_to" |
142 # +2 because line numbers start at 1 and need to skip LATEST file | 189 # +2 because line numbers start at 1 and need to skip LATEST file |
143 rm -rf `ls -t1 | tail --lines=+$(($FLAGS_keep_max + 2))` | 190 rm -rf `ls -t1 | tail --lines=+$(($FLAGS_keep_max + 2))` |
144 cd - | 191 cd - |
145 fi | 192 fi |
146 | 193 |
147 echo "Done." | 194 echo "Done." |
OLD | NEW |