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 sync your checkout, build a Chromium OS image, and test it all | 7 # Script to sync your checkout, build a Chromium OS image, and test it all |
8 # with one command. Can also check out a new Chromium OS checkout and | 8 # with one command. Can also check out a new Chromium OS checkout and |
9 # perform a subset of the above operations. | 9 # perform a subset of the above operations. |
10 # | 10 # |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 # to live update the image. | 141 # to live update the image. |
142 FLAGS_image_to_live=${FLAGS_TRUE} | 142 FLAGS_image_to_live=${FLAGS_TRUE} |
143 fi | 143 fi |
144 | 144 |
145 # If they gave us a remote host, then we assume they want us to do a live | 145 # If they gave us a remote host, then we assume they want us to do a live |
146 # update. | 146 # update. |
147 if [[ -n "${FLAGS_remote}" ]]; then | 147 if [[ -n "${FLAGS_remote}" ]]; then |
148 FLAGS_image_to_live=${FLAGS_TRUE} | 148 FLAGS_image_to_live=${FLAGS_TRUE} |
149 fi | 149 fi |
150 | 150 |
151 # Grabbing a buildbot build is exclusive with building | 151 # Grabbing a buildbot build is exclusive with syncing and building |
152 if [[ -n "${FLAGS_grab_buildbot}" ]]; then | 152 if [[ -n "${FLAGS_grab_buildbot}" ]]; then |
153 if [[ -z "${FLAGS_buildbot_uri}" ]]; then | 153 if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then |
154 echo "--grab_buildbot requires --buildbot_uri" | 154 if [[ -z "${FLAGS_buildbot_uri}" ]]; then |
155 exit 1 | 155 echo "--grab_buildbot=LATEST requires --buildbot_uri or setting " |
| 156 echo "BUILDBOT_URI" |
| 157 exit 1 |
| 158 fi |
156 fi | 159 fi |
| 160 FLAGS_sync=${FLAGS_FALSE} |
157 FLAGS_build=${FLAGS_FALSE} | 161 FLAGS_build=${FLAGS_FALSE} |
158 FLAGS_master=${FLAGS_FALSE} | 162 FLAGS_master=${FLAGS_FALSE} |
159 fi | 163 fi |
160 | 164 |
161 if [[ ${FLAGS_image_to_live} -eq ${FLAGS_TRUE} ]]; then | 165 if [[ ${FLAGS_image_to_live} -eq ${FLAGS_TRUE} ]]; then |
162 if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_FALSE} ]]; then | 166 if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_FALSE} ]]; then |
163 echo "WARNING: You have specified to live reimage a machine with" | 167 echo "WARNING: You have specified to live reimage a machine with" |
164 echo "an image that is not modified for test (so it cannot be" | 168 echo "an image that is not modified for test (so it cannot be" |
165 echo "later live reimaged)" | 169 echo "later live reimaged)" |
166 fi | 170 fi |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 echo " * Master image (build_image)" | 236 echo " * Master image (build_image)" |
233 fi | 237 fi |
234 if [[ -n "${FLAGS_grab_buildbot}" ]]; then | 238 if [[ -n "${FLAGS_grab_buildbot}" ]]; then |
235 if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then | 239 if [[ "${FLAGS_grab_buildbot}" == "LATEST" ]]; then |
236 echo " * Grab latest buildbot image under ${FLAGS_buildbot_uri}" | 240 echo " * Grab latest buildbot image under ${FLAGS_buildbot_uri}" |
237 else | 241 else |
238 echo " * Grab buildbot image zip at URI ${FLAGS_grab_buildbot}" | 242 echo " * Grab buildbot image zip at URI ${FLAGS_grab_buildbot}" |
239 fi | 243 fi |
240 fi | 244 fi |
241 if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_TRUE} ]]; then | 245 if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_TRUE} ]]; then |
242 echo " * Make image able to run tests (mod_image_for_test)" | 246 if [[ -n "${FLAGS_grab_buildbot}" ]]; then |
| 247 echo " * Use the prebuilt image modded for test (rootfs_test.image)" |
| 248 echo " * Install prebuilt cross-compiled autotests in chroot" |
| 249 else |
| 250 echo " * Make image able to run tests (mod_image_for_test)" |
| 251 fi |
243 set_passwd=${FLAGS_TRUE} | 252 set_passwd=${FLAGS_TRUE} |
244 fi | 253 fi |
245 if [[ ${set_passwd} -eq ${FLAGS_TRUE} ]]; then | 254 if [[ ${set_passwd} -eq ${FLAGS_TRUE} ]]; then |
246 if [[ -n "${FLAGS_chronos_passwd}" ]]; then | 255 if [[ -n "${FLAGS_chronos_passwd}" ]]; then |
247 echo " * Set chronos password to ${FLAGS_chronos_passwd}" | 256 echo " * Set chronos password to ${FLAGS_chronos_passwd}" |
248 else | 257 else |
249 echo " * Set chronos password randomly" | 258 echo " * Set chronos password randomly" |
250 fi | 259 fi |
251 fi | 260 fi |
252 if [[ -n "${FLAGS_image_to_usb}" ]]; then | 261 if [[ -n "${FLAGS_image_to_usb}" ]]; then |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 function describe_phase() { | 324 function describe_phase() { |
316 local desc="$1" | 325 local desc="$1" |
317 echo "" | 326 echo "" |
318 echo "#" | 327 echo "#" |
319 echo "#" | 328 echo "#" |
320 echo "# ${desc}" | 329 echo "# ${desc}" |
321 echo "#" | 330 echo "#" |
322 } | 331 } |
323 | 332 |
324 | 333 |
| 334 # Called when there is a failure and we exit early |
| 335 function failure() { |
| 336 trap - EXIT |
| 337 describe_phase "Failure during: ${LAST_PHASE}" |
| 338 show_duration |
| 339 } |
| 340 |
| 341 |
325 # Runs a phase, describing it first, and also updates the sudo timeout | 342 # Runs a phase, describing it first, and also updates the sudo timeout |
326 # afterwards. | 343 # afterwards. |
327 # Arguments: | 344 # Arguments: |
328 # $1 - phase description | 345 # $1 - phase description |
329 # $2.. - command/params to run | 346 # $2.. - command/params to run |
330 function run_phase() { | 347 function run_phase() { |
331 local desc="$1" | 348 local desc="$1" |
332 shift | 349 shift |
| 350 LAST_PHASE="${desc}" |
333 describe_phase "${desc}" | 351 describe_phase "${desc}" |
334 echo "+ $@" | 352 echo "+ $@" |
335 "$@" | 353 "$@" |
336 sudo -v | 354 sudo -v |
337 } | 355 } |
338 | 356 |
339 | 357 |
340 # Runs a phase, similar to run_phase, but runs within the chroot. | 358 # Runs a phase, similar to run_phase, but runs within the chroot. |
341 # Arguments: | 359 # Arguments: |
342 # $1 - phase description | 360 # $1 - phase description |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 fi | 430 fi |
413 FLAGS_grab_buildbot="${FLAGS_buildbot_uri}/${latest}/image.zip" | 431 FLAGS_grab_buildbot="${FLAGS_buildbot_uri}/${latest}/image.zip" |
414 fi | 432 fi |
415 local dl_dir=$(mktemp -d "/tmp/image.XXXX") | 433 local dl_dir=$(mktemp -d "/tmp/image.XXXX") |
416 echo "Grabbing image from ${FLAGS_grab_buildbot} to ${dl_dir}" | 434 echo "Grabbing image from ${FLAGS_grab_buildbot} to ${dl_dir}" |
417 run_phase "Downloading image" curl "${FLAGS_grab_buildbot}" \ | 435 run_phase "Downloading image" curl "${FLAGS_grab_buildbot}" \ |
418 -o "${dl_dir}/image.zip" | 436 -o "${dl_dir}/image.zip" |
419 cd "${dl_dir}" | 437 cd "${dl_dir}" |
420 unzip image.zip | 438 unzip image.zip |
421 check_rootfs_validity | 439 check_rootfs_validity |
422 echo "Copying in local_repo/local_packages" | |
423 # TODO(kmixter): Make this architecture indep once buildbot is. | |
424 mv -f local_repo/local_packages/* "${FLAGS_top}/src/build/x86/local_packages" | |
425 local image_basename=$(basename $(dirname "${FLAGS_grab_buildbot}")) | 440 local image_basename=$(basename $(dirname "${FLAGS_grab_buildbot}")) |
426 local image_dir="${FLAGS_top}/src/build/images/${image_basename}" | 441 local image_base_dir="${FLAGS_top}/src/build/images/${FLAGS_board}" |
| 442 local image_dir="${image_base_dir}/${image_basename}" |
427 echo "Copying in build image to ${image_dir}" | 443 echo "Copying in build image to ${image_dir}" |
428 rm -rf "${image_dir}" | 444 rm -rf "${image_dir}" |
429 mkdir -p "${image_dir}" | 445 mkdir -p "${image_dir}" |
430 # Note that if mbr.image does not exist, this image was not successful. | 446 # Note that if mbr.image does not exist, this image was not successful. |
431 mv mbr.image rootfs.image "${image_dir}" | 447 mv mbr.image rootfs.image "${image_dir}" |
| 448 if [[ ${FLAGS_mod_image_for_test} -eq ${FLAGS_TRUE} ]]; then |
| 449 run_phase "Installing buildbot test modified image" \ |
| 450 mv rootfs_test.image "${image_dir}/rootfs.image" |
| 451 FLAGS_mod_image_for_test=${FLAGS_FALSE} |
| 452 if [[ -e "autotest.tgz" || -e "autotest.tar.bz2" ]]; then |
| 453 # pull in autotest |
| 454 local dir="${FLAGS_chroot}/build/${FLAGS_board}/usr/local" |
| 455 local tar_args="xzf" |
| 456 local tar_name="${dl_dir}/autotest.tgz" |
| 457 if [[ -e "autotest.tar.bz2" ]]; then |
| 458 tar_args="xjf" |
| 459 tar_name="${dl_dir}/autotest.tar.bz2" |
| 460 fi |
| 461 sudo rm -rf "${dir}/autotest" |
| 462 cd ${dir} |
| 463 run_phase "Installing buildbot autotest cross-compiled binaries" \ |
| 464 sudo tar ${tar_args} "${tar_name}" |
| 465 fi |
| 466 fi |
432 chdir_relative . | 467 chdir_relative . |
433 run_phase "Removing downloaded image" rm -rf "${dl_dir}" | 468 run_phase "Removing downloaded image" rm -rf "${dl_dir}" |
434 } | 469 } |
435 | 470 |
| 471 |
436 function main() { | 472 function main() { |
437 assert_outside_chroot | 473 assert_outside_chroot |
438 assert_not_root_user | 474 assert_not_root_user |
439 | 475 |
440 # Parse command line | 476 # Parse command line |
441 FLAGS "$@" || exit 1 | 477 FLAGS "$@" || exit 1 |
442 eval set -- "${FLAGS_ARGV}" | 478 eval set -- "${FLAGS_ARGV}" |
443 | 479 |
444 # Die on any errors. | 480 # Die on any errors. |
445 set -e | 481 set -e |
446 | 482 |
447 validate_and_set_param_defaults | 483 validate_and_set_param_defaults |
448 | 484 |
449 # Cache up sudo status | 485 # Cache up sudo status |
450 sudo -v | 486 sudo -v |
451 | 487 |
452 if [[ ${FLAGS_interactive} -eq ${FLAGS_TRUE} ]]; then | 488 if [[ ${FLAGS_interactive} -eq ${FLAGS_TRUE} ]]; then |
453 interactive | 489 interactive |
454 fi | 490 fi |
455 | 491 |
456 set_start_time | 492 set_start_time |
| 493 trap failure EXIT |
457 | 494 |
458 local withdev_param="" | 495 local withdev_param="" |
459 if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]]; then | 496 if [[ ${FLAGS_withdev} -eq ${FLAGS_TRUE} ]]; then |
460 withdev_param="--withdev" | 497 withdev_param="--withdev" |
461 fi | 498 fi |
462 | 499 |
463 local jobs_param="" | 500 local jobs_param="" |
464 if [[ ${FLAGS_jobs} -gt 1 ]]; then | 501 if [[ ${FLAGS_jobs} -gt 1 ]]; then |
465 jobs_param="--jobs=${FLAGS_jobs}" | 502 jobs_param="--jobs=${FLAGS_jobs}" |
466 fi | 503 fi |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 578 |
542 if [[ -n "${FLAGS_test}" ]]; then | 579 if [[ -n "${FLAGS_test}" ]]; then |
543 chdir_relative src/scripts | 580 chdir_relative src/scripts |
544 # We purposefully do not quote FLAGS_test below as we expect it may | 581 # We purposefully do not quote FLAGS_test below as we expect it may |
545 # have multiple parameters | 582 # have multiple parameters |
546 run_phase "Running tests on Chromium OS machine ${FLAGS_remote}" \ | 583 run_phase "Running tests on Chromium OS machine ${FLAGS_remote}" \ |
547 ./run_remote_tests.sh "--remote=${FLAGS_remote}" ${FLAGS_test} \ | 584 ./run_remote_tests.sh "--remote=${FLAGS_remote}" ${FLAGS_test} \ |
548 "${board_param}" | 585 "${board_param}" |
549 fi | 586 fi |
550 | 587 |
| 588 trap - EXIT |
551 echo "Successfully used ${FLAGS_top} to:" | 589 echo "Successfully used ${FLAGS_top} to:" |
552 describe_steps | 590 describe_steps |
553 show_duration | 591 show_duration |
554 } | 592 } |
555 | 593 |
556 | 594 |
557 main $@ | 595 main $@ |
OLD | NEW |