Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1899)

Side by Side Diff: bin/cbuildbot.py

Issue 6317014: Add buildbot functionality to cbuildbot. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | bin/cbuildbot_config.py » ('j') | bin/cbuildbot_config.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 """Performs a checkout without clobbering previous checkout.""" 322 """Performs a checkout without clobbering previous checkout."""
323 RepoSync(buildroot, retries) 323 RepoSync(buildroot, retries)
324 324
325 325
326 def _MakeChroot(buildroot): 326 def _MakeChroot(buildroot):
327 """Wrapper around make_chroot.""" 327 """Wrapper around make_chroot."""
328 cwd = os.path.join(buildroot, 'src', 'scripts') 328 cwd = os.path.join(buildroot, 'src', 'scripts')
329 RunCommand(['./make_chroot', '--fast'], cwd=cwd) 329 RunCommand(['./make_chroot', '--fast'], cwd=cwd)
330 330
331 331
332 def _CachePackages(buildroot, board, package_cache, restore):
sosa 2011/01/25 22:54:48 As per discussion, let's remove this.
dgarrett 2011/01/25 23:38:51 Done.
333 """Copy pre-built packages from the pre-flight into our chroot
334
335 buildroot: The root directory where the build occurs. Must be an absolute
336 path.
337
338 package_cache: Directory into which built packages are copied off or
339 restored from. Usually /var/buildbot-package-cache.
340
341 restore: Boolean. True to restore packages, False to save them off.
342 """
343 chroot_host_dir = os.path.join(buildroot,
344 'chroot/var/lib/portage/pkgs/')
345 chroot_board_dir = os.path.join(buildroot,
346 'chroot/build/',
347 board,
348 'packages/')
349
350 cache_host_dir = os.path.join(package_cache, 'host/')
351 cache_board_dir = os.path.join(package_cache, board+'/')
352
353 if restore:
354 copies = { cache_host_dir : chroot_host_dir,
355 cache_board_dir : chroot_board_dir }
356 else:
357 copies = { chroot_host_dir : cache_host_dir,
358 chroot_board_dir : cache_board_dir }
359
360 for src, dest in copies.items():
361
362 print "*** _CachePackages %s %s" % (src, dest)
363
364 if not os.path.exists(src):
365 continue
366
367 # Make sure the src permissions work
368 # Make sure the dest exists
369 # copy the files
370 RunCommand(['sudo', 'chmod', 'a+rwx', src])
371 RunCommand(['sudo', 'mkdir', '-p', dest])
372 RunCommand(['sudo', 'rsync', '-az', src, dest])
373
374
332 def _GetPortageEnvVar(buildroot, board, envvar): 375 def _GetPortageEnvVar(buildroot, board, envvar):
333 """Get a portage environment variable for the specified board, if any. 376 """Get a portage environment variable for the specified board, if any.
334 377
335 buildroot: The root directory where the build occurs. Must be an absolute 378 buildroot: The root directory where the build occurs. Must be an absolute
336 path. 379 path.
337 board: Board type that was built on this machine. E.g. x86-generic. If this 380 board: Board type that was built on this machine. E.g. x86-generic. If this
338 is None, get the env var from the host. 381 is None, get the env var from the host.
339 envvar: The environment variable to get. E.g. 'PORTAGE_BINHOST'. 382 envvar: The environment variable to get. E.g. 'PORTAGE_BINHOST'.
340 383
341 Returns: 384 Returns:
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 '--overlays=%s' % ':'.join(overlays), 521 '--overlays=%s' % ':'.join(overlays),
479 '--tracking_branch=%s' % tracking_branch 522 '--tracking_branch=%s' % tracking_branch
480 ] 523 ]
481 if dryrun: 524 if dryrun:
482 cmd.append('--dryrun') 525 cmd.append('--dryrun')
483 526
484 cmd.append('push') 527 cmd.append('push')
485 RunCommand(cmd, cwd=cwd) 528 RunCommand(cmd, cwd=cwd)
486 529
487 530
531 def _ArchiveBuild(bot_id, buildconfig, buildnumber):
sosa 2011/01/25 22:54:48 Can you rename to _OldArchiveBuild or LegacyArchiv
dgarrett 2011/01/25 23:38:51 Done.
532 """Adds a step to the factory to archive a build."""
533
534 # Fixed properties
535 keep_max = 3
536 gsutil_archive = 'gs://chromeos-archive/' + bot_id
537
538 # TODO: Currently, --to is based on a known config for the buildbot
sosa 2011/01/25 22:54:48 Remove this TODO. It is obselete (we use gsutil f
539 # slaves storing their build results locally. When we can store the
540 # results on chrome-web (after open source release), this needs
541 # refactoring.
542
543 cmd = ['./archive_build.sh',
544 '--build_number', str(buildnumber),
545 '--to', '/var/www/archive/' + bot_id,
546 '--keep_max', str(keep_max),
547 '--prebuilt_upload',
548 '--board', buildconfig['board'],
549
550 '--acl', '/home/chrome-bot/slave_archive_acl',
551 '--gsutil_archive', gsutil_archive,
552 '--gsd_gen_index',
553 '/b/scripts/gsd_generate_index/gsd_generate_index.py',
554 '--gsutil', '/b/scripts/slave/gsutil',
555 '--test_mod'
556 ]
557
558 if buildconfig.get('test_mod', True):
sosa 2011/01/25 22:54:48 isn't this equivalent to buildconfig.get('testmod'
dgarrett 2011/01/25 23:38:51 No. This gives it a default value, so that it does
559 cmd += ['--test_mod']
sosa 2011/01/25 22:54:48 append rather than +=
dgarrett 2011/01/25 23:38:51 Done.
560
561 if buildconfig.get('factory_install_mod', True):
562 cmd += ['--factory_install_mod']
sosa 2011/01/25 22:54:48 append rather than +=
dgarrett 2011/01/25 23:38:51 Done.
563
564 if buildconfig.get('factory_test_mod', True):
565 cmd += ['--factory_test_mod']
sosa 2011/01/25 22:54:48 append rather than +=
dgarrett 2011/01/25 23:38:51 Done.
566
567 Warning('***** ***** ArchiveBuild CMD: ' + ' '.join(cmd))
568 #RunCommand(cmd)
sosa 2011/01/25 22:54:48 if not debug rather than comment out
dgarrett 2011/01/25 23:38:51 Makes sense.
569
488 def _ArchiveTestResults(buildroot, board, test_results_dir, 570 def _ArchiveTestResults(buildroot, board, test_results_dir,
489 gsutil, archive_dir, acl): 571 gsutil, archive_dir, acl):
490 """Archives the test results into Google Storage 572 """Archives the test results into Google Storage
491 573
492 Takes the results from the test_results_dir and the last qemu image and 574 Takes the results from the test_results_dir and the last qemu image and
493 uploads them to Google Storage. 575 uploads them to Google Storage.
494 576
495 Arguments: 577 Arguments:
496 buildroot: Root directory where build occurs 578 buildroot: Root directory where build occurs
497 board: Board to find the qemu image. 579 board: Board to find the qemu image.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 683
602 RunCommand(cmd, cwd=cwd) 684 RunCommand(cmd, cwd=cwd)
603 685
604 686
605 def main(): 687 def main():
606 # Parse options 688 # Parse options
607 usage = "usage: %prog [options] cbuildbot_config" 689 usage = "usage: %prog [options] cbuildbot_config"
608 parser = optparse.OptionParser(usage=usage) 690 parser = optparse.OptionParser(usage=usage)
609 parser.add_option('-a', '--acl', default='private', 691 parser.add_option('-a', '--acl', default='private',
610 help='ACL to set on GSD archives') 692 help='ACL to set on GSD archives')
693 parser.add_option('--archive_build', action='store_true', default=False,
694 help='Run the archive_build script.')
611 parser.add_option('-r', '--buildroot', 695 parser.add_option('-r', '--buildroot',
612 help='root directory where build occurs', default=".") 696 help='root directory where build occurs', default=".")
613 parser.add_option('-n', '--buildnumber', 697 parser.add_option('-n', '--buildnumber',
614 help='build number', type='int', default=0) 698 help='build number', type='int', default=0)
615 parser.add_option('--chrome_rev', default=None, type='string', 699 parser.add_option('--chrome_rev', default=None, type='string',
616 dest='chrome_rev', 700 dest='chrome_rev',
617 help=('Chrome_rev of type [tot|latest_release|' 701 help=('Chrome_rev of type [tot|latest_release|'
618 'sticky_release]')) 702 'sticky_release]'))
619 parser.add_option('-g', '--gsutil', default='', help='Location of gsutil') 703 parser.add_option('-g', '--gsutil', default='', help='Location of gsutil')
620 parser.add_option('-c', '--gsutil_archive', default='', 704 parser.add_option('-c', '--gsutil_archive', default='',
621 help='Datastore archive location') 705 help='Datastore archive location')
622 parser.add_option('--clobber', action='store_true', dest='clobber', 706 parser.add_option('--clobber', action='store_true', dest='clobber',
623 default=False, 707 default=False,
624 help='Clobbers an old checkout before syncing') 708 help='Clobbers an old checkout before syncing')
625 parser.add_option('--debug', action='store_true', dest='debug', 709 parser.add_option('--debug', action='store_true', dest='debug',
626 default=False, 710 default=False,
627 help='Override some options to run as a developer.') 711 help='Override some options to run as a developer.')
712 parser.add_option('--nobuild', action='store_false', dest='build',
713 default=True,
714 help="Don't actually build (for cbuildbot devel")
sosa 2011/01/25 22:54:48 dev*
dgarrett 2011/01/25 23:38:51 Done.
628 parser.add_option('--noprebuilts', action='store_false', dest='prebuilts', 715 parser.add_option('--noprebuilts', action='store_false', dest='prebuilts',
629 default=True, 716 default=True,
630 help="Don't upload prebuilts.") 717 help="Don't upload prebuilts.")
631 parser.add_option('--nosync', action='store_false', dest='sync', 718 parser.add_option('--nosync', action='store_false', dest='sync',
632 default=True, 719 default=True,
633 help="Don't sync before building.") 720 help="Don't sync before building.")
634 parser.add_option('--notests', action='store_false', dest='tests', 721 parser.add_option('--notests', action='store_false', dest='tests',
635 default=True, 722 default=True,
636 help='Override values from buildconfig and run no tests.') 723 help='Override values from buildconfig and run no tests.')
724 parser.add_option('--package-cache', dest='package_cache',
sosa 2011/01/25 22:54:48 As per our discussions with scottz / raja ... let'
dgarrett 2011/01/25 23:38:51 Done.
725 default=None,
726 help='Directory to save/restore packages (for buildbot).')
637 parser.add_option('-f', '--revisionfile', 727 parser.add_option('-f', '--revisionfile',
638 help='file where new revisions are stored') 728 help='file where new revisions are stored')
639 parser.add_option('-t', '--tracking-branch', dest='tracking_branch', 729 parser.add_option('-t', '--tracking-branch', dest='tracking_branch',
640 default='cros/master', help='Run the buildbot on a branch') 730 default='cros/master', help='Run the buildbot on a branch')
641 parser.add_option('-u', '--url', dest='url', 731 parser.add_option('-u', '--url', dest='url',
642 default='http://git.chromium.org/git/manifest', 732 default='http://git.chromium.org/git/manifest',
643 help='Run the buildbot on internal manifest') 733 help='Run the buildbot on internal manifest')
644 734
645 (options, args) = parser.parse_args() 735 (options, args) = parser.parse_args()
646 736
647 buildroot = os.path.abspath(options.buildroot) 737 buildroot = os.path.abspath(options.buildroot)
648 revisionfile = options.revisionfile 738 revisionfile = options.revisionfile
649 tracking_branch = options.tracking_branch 739 tracking_branch = options.tracking_branch
650 chrome_atom_to_build = None 740 chrome_atom_to_build = None
651 741
652 if len(args) >= 1: 742 if len(args) >= 1:
653 buildconfig = _GetConfig(args[-1]) 743 bot_id = args[-1]
744 buildconfig = _GetConfig(bot_id)
654 else: 745 else:
655 Warning('Missing configuration description') 746 Warning('Missing configuration description')
656 parser.print_usage() 747 parser.print_usage()
657 sys.exit(1) 748 sys.exit(1)
658 749
659 try: 750 try:
660 # Calculate list of overlay directories. 751 # Calculate list of overlay directories.
661 rev_overlays = _ResolveOverlays(buildroot, buildconfig['rev_overlays']) 752 rev_overlays = _ResolveOverlays(buildroot, buildconfig['rev_overlays'])
662 push_overlays = _ResolveOverlays(buildroot, buildconfig['push_overlays']) 753 push_overlays = _ResolveOverlays(buildroot, buildconfig['push_overlays'])
663 # We cannot push to overlays that we don't rev. 754 # We cannot push to overlays that we don't rev.
(...skipping 19 matching lines...) Expand all
683 emptytree = (old_binhost and old_binhost != new_binhost) 774 emptytree = (old_binhost and old_binhost != new_binhost)
684 775
685 # Check that all overlays can be found. 776 # Check that all overlays can be found.
686 for path in rev_overlays: 777 for path in rev_overlays:
687 if not os.path.isdir(path): 778 if not os.path.isdir(path):
688 Die('Missing overlay: %s' % path) 779 Die('Missing overlay: %s' % path)
689 780
690 if not os.path.isdir(chroot_path): 781 if not os.path.isdir(chroot_path):
691 _MakeChroot(buildroot) 782 _MakeChroot(buildroot)
692 783
784 if options.package_cache:
785 _CachePackages(buildroot, board,
sosa 2011/01/25 22:54:48 Remove
dgarrett 2011/01/25 23:38:51 Done.
786 options.package_cache,
787 restore=True)
788
693 if not os.path.isdir(boardpath): 789 if not os.path.isdir(boardpath):
694 _SetupBoard(buildroot, board=buildconfig['board']) 790 _SetupBoard(buildroot, board=buildconfig['board'])
695 791
696 # Perform uprev. If chrome_uprev is set, rev Chrome ebuilds. 792 # Perform uprev. If chrome_uprev is set, rev Chrome ebuilds.
697 if options.chrome_rev: 793 if options.chrome_rev:
698 chrome_atom_to_build = _MarkChromeAsStable(buildroot, tracking_branch, 794 chrome_atom_to_build = _MarkChromeAsStable(buildroot, tracking_branch,
699 options.chrome_rev, board) 795 options.chrome_rev, board)
700 # If we found nothing to rev, we're done here. 796 # If we found nothing to rev, we're done here.
701 if not chrome_atom_to_build: 797 if not chrome_atom_to_build:
702 return 798 return
703 799
704 elif buildconfig['uprev']: 800 elif buildconfig['uprev']:
705 _UprevPackages(buildroot, tracking_branch, revisionfile, 801 _UprevPackages(buildroot, tracking_branch, revisionfile,
706 buildconfig['board'], rev_overlays) 802 buildconfig['board'], rev_overlays)
707 803
708 _EnableLocalAccount(buildroot) 804 _EnableLocalAccount(buildroot)
709 _Build(buildroot, emptytree) 805
806 if options.build:
807 _Build(buildroot, emptytree)
808
809 if options.package_cache:
sosa 2011/01/25 22:54:48 Remove
dgarrett 2011/01/25 23:38:51 Done.
810 _CachePackages(buildroot, board,
811 options.package_cache,
812 restore=False)
710 813
711 if buildconfig['unittests'] and options.tests: 814 if buildconfig['unittests'] and options.tests:
712 _RunUnitTests(buildroot) 815 _RunUnitTests(buildroot)
713 816
714 _BuildImage(buildroot) 817 if options.build:
sosa 2011/01/25 22:54:48 Merge into other build cmd
dgarrett 2011/01/25 23:38:51 Done.
818 _BuildImage(buildroot)
715 819
716 if buildconfig['tests'] and options.tests: 820 if buildconfig['tests'] and options.tests:
717 _BuildVMImageForTesting(buildroot) 821 _BuildVMImageForTesting(buildroot)
718 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber 822 test_results_dir = '/tmp/run_remote_tests.%s' % options.buildnumber
719 try: 823 try:
720 _RunSmokeSuite(buildroot, test_results_dir) 824 _RunSmokeSuite(buildroot, test_results_dir)
721 _RunAUTest(buildroot, buildconfig['board']) 825 _RunAUTest(buildroot, buildconfig['board'])
722 finally: 826 finally:
723 if not options.debug: 827 if not options.debug:
724 archive_full_path = os.path.join(options.gsutil_archive, 828 archive_full_path = os.path.join(options.gsutil_archive,
(...skipping 14 matching lines...) Expand all
739 [new_binhost]) 843 [new_binhost])
740 _UprevPush(buildroot, tracking_branch, buildconfig['board'], 844 _UprevPush(buildroot, tracking_branch, buildconfig['board'],
741 push_overlays, options.debug) 845 push_overlays, options.debug)
742 else: 846 else:
743 Die('CBUILDBOT - One of the slaves has failed!!!') 847 Die('CBUILDBOT - One of the slaves has failed!!!')
744 848
745 else: 849 else:
746 # Publish my status to the master if its expecting it. 850 # Publish my status to the master if its expecting it.
747 if buildconfig['important'] and not options.debug: 851 if buildconfig['important'] and not options.debug:
748 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) 852 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE)
749 853
854 if options.archive_build:
855 _ArchiveBuild(bot_id, buildconfig, options.buildnumber)
750 except: 856 except:
751 # Send failure to master bot. 857 # Send failure to master bot.
752 if not buildconfig['master'] and buildconfig['important']: 858 if not buildconfig['master'] and buildconfig['important']:
753 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) 859 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED)
754 860
755 raise 861 raise
756 862
757 863
758 if __name__ == '__main__': 864 if __name__ == '__main__':
759 main() 865 main()
OLDNEW
« no previous file with comments | « no previous file | bin/cbuildbot_config.py » ('j') | bin/cbuildbot_config.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698