OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
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 """CBuildbot is wrapper around the build process used by the pre-flight queue""" | 7 """CBuildbot is wrapper around the build process used by the pre-flight queue""" |
8 | 8 |
9 import errno | 9 import errno |
10 import heapq | 10 import heapq |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 '--board=%s' % board, | 202 '--board=%s' % board, |
203 '--tracking_branch=%s' % tracking_branch, | 203 '--tracking_branch=%s' % tracking_branch, |
204 '--overlays=%s' % ':'.join(chroot_overlays), | 204 '--overlays=%s' % ':'.join(chroot_overlays), |
205 '--packages=%s' % ':'.join(packages), | 205 '--packages=%s' % ':'.join(packages), |
206 '--drop_file=%s' % ReinterpretPathForChroot(_PACKAGE_FILE % | 206 '--drop_file=%s' % ReinterpretPathForChroot(_PACKAGE_FILE % |
207 {'buildroot': buildroot}), | 207 {'buildroot': buildroot}), |
208 'commit'], | 208 'commit'], |
209 cwd=cwd, enter_chroot=True) | 209 cwd=cwd, enter_chroot=True) |
210 | 210 |
211 | 211 |
| 212 def _MarkChromeAsStable(buildroot, tracking_branch, chrome_rev): |
| 213 """Returns the portage atom for the revved chrome ebuild - see man emerge.""" |
| 214 cwd = os.path.join(buildroot, 'src', 'scripts') |
| 215 portage_atom_string = RunCommand(['bin/cros_mark_chrome_as_stable', |
| 216 '--tracking_branch=%s' % tracking_branch, |
| 217 chrome_rev], cwd=cwd, redirect_stdout=True, |
| 218 enter_chroot=True).rstrip() |
| 219 if not portage_atom_string: |
| 220 Info('Found nothing to rev.') |
| 221 return None |
| 222 else: |
| 223 return portage_atom_string.split('=')[1] |
| 224 |
| 225 |
212 def _UprevAllPackages(buildroot, tracking_branch, board, overlays): | 226 def _UprevAllPackages(buildroot, tracking_branch, board, overlays): |
213 """Uprevs all packages that have been updated since last uprev.""" | 227 """Uprevs all packages that have been updated since last uprev.""" |
214 cwd = os.path.join(buildroot, 'src', 'scripts') | 228 cwd = os.path.join(buildroot, 'src', 'scripts') |
215 chroot_overlays = [ReinterpretPathForChroot(path) for path in overlays] | 229 chroot_overlays = [ReinterpretPathForChroot(path) for path in overlays] |
216 RunCommand(['./cros_mark_as_stable', '--all', | 230 RunCommand(['./cros_mark_as_stable', '--all', |
217 '--board=%s' % board, | 231 '--board=%s' % board, |
218 '--overlays=%s' % ':'.join(chroot_overlays), | 232 '--overlays=%s' % ':'.join(chroot_overlays), |
219 '--tracking_branch=%s' % tracking_branch, | 233 '--tracking_branch=%s' % tracking_branch, |
220 '--drop_file=%s' % ReinterpretPathForChroot(_PACKAGE_FILE % | 234 '--drop_file=%s' % ReinterpretPathForChroot(_PACKAGE_FILE % |
221 {'buildroot': buildroot}), | 235 {'buildroot': buildroot}), |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 RunCommand(['./setup_board', '--fast', '--default', '--board=%s' % board], | 318 RunCommand(['./setup_board', '--fast', '--default', '--board=%s' % board], |
305 cwd=cwd, enter_chroot=True) | 319 cwd=cwd, enter_chroot=True) |
306 | 320 |
307 | 321 |
308 def _Build(buildroot): | 322 def _Build(buildroot): |
309 """Wrapper around build_packages.""" | 323 """Wrapper around build_packages.""" |
310 cwd = os.path.join(buildroot, 'src', 'scripts') | 324 cwd = os.path.join(buildroot, 'src', 'scripts') |
311 RunCommand(['./build_packages'], cwd=cwd, enter_chroot=True) | 325 RunCommand(['./build_packages'], cwd=cwd, enter_chroot=True) |
312 | 326 |
313 | 327 |
| 328 def _BuildChrome(buildroot, board, chrome_atom_to_build): |
| 329 """Wrapper for emerge call to build Chrome.""" |
| 330 cwd = os.path.join(buildroot, 'src', 'scripts') |
| 331 RunCommand(['emerge-%s' % board, '=%s' % chrome_atom_to_build], |
| 332 cwd=cwd, enter_chroot=True) |
| 333 |
| 334 |
314 def _EnableLocalAccount(buildroot): | 335 def _EnableLocalAccount(buildroot): |
315 cwd = os.path.join(buildroot, 'src', 'scripts') | 336 cwd = os.path.join(buildroot, 'src', 'scripts') |
316 # Set local account for test images. | 337 # Set local account for test images. |
317 RunCommand(['./enable_localaccount.sh', | 338 RunCommand(['./enable_localaccount.sh', |
318 'chronos'], | 339 'chronos'], |
319 print_cmd=False, cwd=cwd) | 340 print_cmd=False, cwd=cwd) |
320 | 341 |
321 | 342 |
322 def _BuildImage(buildroot): | 343 def _BuildImage(buildroot): |
323 _WipeOldOutput(buildroot) | 344 _WipeOldOutput(buildroot) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 # print >> sys.stderr, 'CBUILDBOT Revision list found %s' % revisions | 409 # print >> sys.stderr, 'CBUILDBOT Revision list found %s' % revisions |
389 # revision_list = _ParseRevisionString(revisions, | 410 # revision_list = _ParseRevisionString(revisions, |
390 # _CreateRepoDictionary(buildroot, board)) | 411 # _CreateRepoDictionary(buildroot, board)) |
391 # _UprevFromRevisionList(buildroot, tracking_branch, revision_list, board, | 412 # _UprevFromRevisionList(buildroot, tracking_branch, revision_list, board, |
392 # overlays) | 413 # overlays) |
393 #else: | 414 #else: |
394 Info('CBUILDBOT Revving all') | 415 Info('CBUILDBOT Revving all') |
395 _UprevAllPackages(buildroot, tracking_branch, board, overlays) | 416 _UprevAllPackages(buildroot, tracking_branch, board, overlays) |
396 | 417 |
397 | 418 |
398 def _UprevPush(buildroot, tracking_branch, board, overlays): | 419 def _UprevPush(buildroot, tracking_branch, board, overlays, dryrun): |
399 """Pushes uprev changes to the main line.""" | 420 """Pushes uprev changes to the main line.""" |
400 cwd = os.path.join(buildroot, 'src', 'scripts') | 421 cwd = os.path.join(buildroot, 'src', 'scripts') |
401 RunCommand(['./cros_mark_as_stable', '--srcroot=..', | 422 cmd = ['./cros_mark_as_stable', |
402 '--board=%s' % board, | 423 '--srcroot=%s' % os.path.join(buildroot, 'src'), |
403 '--overlays=%s' % ':'.join(overlays), | 424 '--board=%s' % board, |
404 '--tracking_branch=%s' % tracking_branch, | 425 '--overlays=%s' % ':'.join(overlays), |
405 '--push_options=--bypass-hooks -f', 'push'], | 426 '--tracking_branch=%s' % tracking_branch |
406 cwd=cwd) | 427 ] |
| 428 if dryrun: |
| 429 cmd.append('--dryrun') |
| 430 |
| 431 cmd.append('push') |
| 432 RunCommand(cmd, cwd=cwd) |
407 | 433 |
408 | 434 |
409 def _ArchiveTestResults(buildroot, board, test_results_dir, | 435 def _ArchiveTestResults(buildroot, board, test_results_dir, |
410 gsutil, archive_dir, acl): | 436 gsutil, archive_dir, acl): |
411 """Archives the test results into Google Storage | 437 """Archives the test results into Google Storage |
412 | 438 |
413 Takes the results from the test_results_dir and the last qemu image and | 439 Takes the results from the test_results_dir and the last qemu image and |
414 uploads them to Google Storage. | 440 uploads them to Google Storage. |
415 | 441 |
416 Arguments: | 442 Arguments: |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 | 515 |
490 | 516 |
491 def main(): | 517 def main(): |
492 # Parse options | 518 # Parse options |
493 usage = "usage: %prog [options] cbuildbot_config" | 519 usage = "usage: %prog [options] cbuildbot_config" |
494 parser = optparse.OptionParser(usage=usage) | 520 parser = optparse.OptionParser(usage=usage) |
495 parser.add_option('-r', '--buildroot', | 521 parser.add_option('-r', '--buildroot', |
496 help='root directory where build occurs', default=".") | 522 help='root directory where build occurs', default=".") |
497 parser.add_option('-n', '--buildnumber', | 523 parser.add_option('-n', '--buildnumber', |
498 help='build number', type='int', default=0) | 524 help='build number', type='int', default=0) |
| 525 parser.add_option('--chrome_rev', default=None, type='string', |
| 526 dest='chrome_rev', |
| 527 help=('Chrome_rev of type [tot|latest_release|' |
| 528 'sticky_release]')) |
499 parser.add_option('-f', '--revisionfile', | 529 parser.add_option('-f', '--revisionfile', |
500 help='file where new revisions are stored') | 530 help='file where new revisions are stored') |
501 parser.add_option('--clobber', action='store_true', dest='clobber', | 531 parser.add_option('--clobber', action='store_true', dest='clobber', |
502 default=False, | 532 default=False, |
503 help='Clobbers an old checkout before syncing') | 533 help='Clobbers an old checkout before syncing') |
504 parser.add_option('--debug', action='store_true', dest='debug', | 534 parser.add_option('--debug', action='store_true', dest='debug', |
505 default=False, | 535 default=False, |
506 help='Override some options to run as a developer.') | 536 help='Override some options to run as a developer.') |
| 537 parser.add_option('--nosync', action='store_false', dest='sync', |
| 538 default=True, |
| 539 help="Don't sync before building.") |
| 540 parser.add_option('--notests', action='store_false', dest='tests', |
| 541 default=True, |
| 542 help='Override values from buildconfig and run no tests.') |
507 parser.add_option('-t', '--tracking-branch', dest='tracking_branch', | 543 parser.add_option('-t', '--tracking-branch', dest='tracking_branch', |
508 default='cros/master', help='Run the buildbot on a branch') | 544 default='cros/master', help='Run the buildbot on a branch') |
509 parser.add_option('-u', '--url', dest='url', | 545 parser.add_option('-u', '--url', dest='url', |
510 default='http://git.chromium.org/git/manifest', | 546 default='http://git.chromium.org/git/manifest', |
511 help='Run the buildbot on internal manifest') | 547 help='Run the buildbot on internal manifest') |
512 parser.add_option('-g', '--gsutil', default='', help='Location of gsutil') | 548 parser.add_option('-g', '--gsutil', default='', help='Location of gsutil') |
513 parser.add_option('-c', '--gsutil_archive', default='', | 549 parser.add_option('-c', '--gsutil_archive', default='', |
514 help='Datastore archive location') | 550 help='Datastore archive location') |
515 parser.add_option('-a', '--acl', default='private', | 551 parser.add_option('-a', '--acl', default='private', |
516 help='ACL to set on GSD archives') | 552 help='ACL to set on GSD archives') |
517 | 553 |
518 (options, args) = parser.parse_args() | 554 (options, args) = parser.parse_args() |
519 | 555 |
520 buildroot = os.path.abspath(options.buildroot) | 556 buildroot = os.path.abspath(options.buildroot) |
521 revisionfile = options.revisionfile | 557 revisionfile = options.revisionfile |
522 tracking_branch = options.tracking_branch | 558 tracking_branch = options.tracking_branch |
| 559 chrome_atom_to_build = None |
523 | 560 |
524 if len(args) >= 1: | 561 if len(args) >= 1: |
525 buildconfig = _GetConfig(args[-1]) | 562 buildconfig = _GetConfig(args[-1]) |
526 else: | 563 else: |
527 Warning('Missing configuration description') | 564 Warning('Missing configuration description') |
528 parser.print_usage() | 565 parser.print_usage() |
529 sys.exit(1) | 566 sys.exit(1) |
530 | 567 |
531 # Calculate list of overlay directories. | 568 # Calculate list of overlay directories. |
532 overlays = _ResolveOverlays(buildroot, buildconfig['overlays']) | 569 overlays = _ResolveOverlays(buildroot, buildconfig['overlays']) |
533 | 570 |
534 try: | 571 try: |
535 _PreFlightRinse(buildroot, buildconfig['board'], tracking_branch, overlays) | 572 _PreFlightRinse(buildroot, buildconfig['board'], tracking_branch, overlays) |
536 if options.clobber or not os.path.isdir(buildroot): | 573 if options.sync: |
537 _FullCheckout(buildroot, tracking_branch, url=options.url) | 574 if options.clobber or not os.path.isdir(buildroot): |
538 else: | 575 _FullCheckout(buildroot, tracking_branch, url=options.url) |
539 _IncrementalCheckout(buildroot) | 576 else: |
| 577 _IncrementalCheckout(buildroot) |
540 | 578 |
541 # Check that all overlays can be found. | 579 # Check that all overlays can be found. |
542 for path in overlays: | 580 for path in overlays: |
543 assert ':' not in path, 'Overlay must not contain colons: %s' % path | 581 assert ':' not in path, 'Overlay must not contain colons: %s' % path |
544 if not os.path.isdir(path): | 582 if not os.path.isdir(path): |
545 Die('Missing overlay: %s' % path) | 583 Die('Missing overlay: %s' % path) |
546 | 584 |
547 chroot_path = os.path.join(buildroot, 'chroot') | 585 chroot_path = os.path.join(buildroot, 'chroot') |
548 if not os.path.isdir(chroot_path): | 586 if not os.path.isdir(chroot_path): |
549 _MakeChroot(buildroot) | 587 _MakeChroot(buildroot) |
550 | 588 |
551 boardpath = os.path.join(chroot_path, 'build', buildconfig['board']) | 589 boardpath = os.path.join(chroot_path, 'build', buildconfig['board']) |
552 if not os.path.isdir(boardpath): | 590 if not os.path.isdir(boardpath): |
553 _SetupBoard(buildroot, board=buildconfig['board']) | 591 _SetupBoard(buildroot, board=buildconfig['board']) |
554 | 592 |
555 if buildconfig['uprev']: | 593 # Perform uprev. If chrome_uprev is set, rev Chrome ebuilds. |
| 594 if options.chrome_rev: |
| 595 chrome_atom_to_build = _MarkChromeAsStable(buildroot, tracking_branch, |
| 596 options.chrome_rev) |
| 597 elif buildconfig['uprev']: |
556 _UprevPackages(buildroot, tracking_branch, revisionfile, | 598 _UprevPackages(buildroot, tracking_branch, revisionfile, |
557 buildconfig['board'], overlays) | 599 buildconfig['board'], overlays) |
558 | 600 |
559 _EnableLocalAccount(buildroot) | 601 _EnableLocalAccount(buildroot) |
560 _Build(buildroot) | 602 # Doesn't rebuild without acquiring more source. |
561 if buildconfig['unittests']: | 603 if options.sync: |
| 604 _Build(buildroot) |
| 605 |
| 606 if chrome_atom_to_build: |
| 607 _BuildChrome(buildroot, buildconfig['board'], chrome_atom_to_build) |
| 608 |
| 609 if buildconfig['unittests'] and options.tests: |
562 _RunUnitTests(buildroot) | 610 _RunUnitTests(buildroot) |
563 | 611 |
564 _BuildImage(buildroot) | 612 _BuildImage(buildroot) |
565 | 613 |
566 if buildconfig['smoke_bvt']: | 614 if buildconfig['smoke_bvt'] and options.tests: |
567 _BuildVMImageForTesting(buildroot) | 615 _BuildVMImageForTesting(buildroot) |
568 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber | 616 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber |
569 try: | 617 try: |
570 _RunSmokeSuite(buildroot, test_results_dir) | 618 _RunSmokeSuite(buildroot, test_results_dir) |
571 finally: | 619 finally: |
572 if not options.debug: | 620 if not options.debug: |
573 archive_full_path=os.path.join(options.gsutil_archive, | 621 archive_full_path=os.path.join(options.gsutil_archive, |
574 str(options.buildnumber)) | 622 str(options.buildnumber)) |
575 _ArchiveTestResults(buildroot, buildconfig['board'], | 623 _ArchiveTestResults(buildroot, buildconfig['board'], |
576 test_results_dir=test_results_dir, | 624 test_results_dir=test_results_dir, |
577 gsutil=options.gsutil, | 625 gsutil=options.gsutil, |
578 archive_dir=archive_full_path, | 626 archive_dir=archive_full_path, |
579 acl=options.acl) | 627 acl=options.acl) |
580 | 628 |
581 if buildconfig['uprev']: | 629 if buildconfig['uprev']: |
582 # Don't push changes for developers. | 630 # Don't push changes for developers. |
583 if not options.debug: | 631 if buildconfig['master']: |
584 if buildconfig['master']: | 632 # Master bot needs to check if the other slaves completed. |
585 # Master bot needs to check if the other slaves completed. | 633 if cbuildbot_comm.HaveSlavesCompleted(config): |
586 if cbuildbot_comm.HaveSlavesCompleted(config): | 634 _UprevPush(buildroot, tracking_branch, buildconfig['board'], |
587 _UprevPush(buildroot, tracking_branch, buildconfig['board'], | 635 overlays, options.debug) |
588 overlays) | 636 else: |
589 else: | 637 Die('CBUILDBOT - One of the slaves has failed!!!') |
590 Die('CBUILDBOT - One of the slaves has failed!!!') | |
591 | 638 |
592 else: | 639 else: |
593 # Publish my status to the master if its expecting it. | 640 # Publish my status to the master if its expecting it. |
594 if buildconfig['important']: | 641 if buildconfig['important'] and not options.debug: |
595 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) | 642 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) |
596 | 643 |
597 except: | 644 except: |
598 # Send failure to master bot. | 645 # Send failure to master bot. |
599 if not buildconfig['master'] and buildconfig['important']: | 646 if not buildconfig['master'] and buildconfig['important']: |
600 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) | 647 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) |
601 | 648 |
602 raise | 649 raise |
603 | 650 |
604 | 651 |
605 if __name__ == '__main__': | 652 if __name__ == '__main__': |
606 main() | 653 main() |
OLD | NEW |