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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 """Wrapper around make_chroot.""" | 310 """Wrapper around make_chroot.""" |
311 cwd = os.path.join(buildroot, 'src', 'scripts') | 311 cwd = os.path.join(buildroot, 'src', 'scripts') |
312 RunCommand(['./make_chroot', '--fast'], cwd=cwd) | 312 RunCommand(['./make_chroot', '--fast'], cwd=cwd) |
313 | 313 |
314 | 314 |
315 def _GetPortageEnvVar(buildroot, board, envvar): | 315 def _GetPortageEnvVar(buildroot, board, envvar): |
316 """Get a portage environment variable for the specified board, if any. | 316 """Get a portage environment variable for the specified board, if any. |
317 | 317 |
318 buildroot: The root directory where the build occurs. Must be an absolute | 318 buildroot: The root directory where the build occurs. Must be an absolute |
319 path. | 319 path. |
320 board: Board type that was built on this machine. E.g. x86-generic. | 320 board: Board type that was built on this machine. E.g. x86-generic. If this |
321 envvar: The environment variable to get. E.g. "PORTAGE_BINHOST". | 321 is None, get the env var from the host. |
| 322 envvar: The environment variable to get. E.g. 'PORTAGE_BINHOST'. |
322 | 323 |
323 Returns: | 324 Returns: |
324 The value of the environment variable, as a string. If no such variable | 325 The value of the environment variable, as a string. If no such variable |
325 can be found, return the empty string. | 326 can be found, return the empty string. |
326 """ | 327 """ |
327 cwd = os.path.join(buildroot, 'src', 'scripts') | 328 cwd = os.path.join(buildroot, 'src', 'scripts') |
328 binhost = RunCommand(['portageq-%s' % board, 'envvar', envvar], | 329 portageq = 'portageq' |
329 cwd=cwd, redirect_stdout=True, enter_chroot=True, | 330 if board: |
330 error_ok=True) | 331 portageq += '-%s' % board |
| 332 binhost = RunCommand([portageq, 'envvar', envvar], cwd=cwd, |
| 333 redirect_stdout=True, enter_chroot=True, error_ok=True) |
331 return binhost.rstrip('\n') | 334 return binhost.rstrip('\n') |
332 | 335 |
333 | 336 |
334 def _SetupBoard(buildroot, board='x86-generic'): | 337 def _SetupBoard(buildroot, board='x86-generic'): |
335 """Wrapper around setup_board.""" | 338 """Wrapper around setup_board.""" |
336 cwd = os.path.join(buildroot, 'src', 'scripts') | 339 cwd = os.path.join(buildroot, 'src', 'scripts') |
337 RunCommand(['./setup_board', '--fast', '--default', '--board=%s' % board], | 340 RunCommand(['./setup_board', '--fast', '--default', '--board=%s' % board], |
338 cwd=cwd, enter_chroot=True) | 341 cwd=cwd, enter_chroot=True) |
339 | 342 |
340 | 343 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 paths = [private_overlay] | 529 paths = [private_overlay] |
527 elif overlays == 'public': | 530 elif overlays == 'public': |
528 paths = [public_overlay] | 531 paths = [public_overlay] |
529 elif overlays == 'both': | 532 elif overlays == 'both': |
530 paths = [public_overlay, private_overlay] | 533 paths = [public_overlay, private_overlay] |
531 else: | 534 else: |
532 Die('Incorrect overlay configuration: %s' % overlays) | 535 Die('Incorrect overlay configuration: %s' % overlays) |
533 return paths | 536 return paths |
534 | 537 |
535 | 538 |
536 def _UploadPrebuilts(buildroot, board, overlay_config): | 539 def _UploadPrebuilts(buildroot, board, overlay_config, binhosts): |
537 """Upload prebuilts. | 540 """Upload prebuilts. |
538 | 541 |
539 Args: | 542 Args: |
540 buildroot: The root directory where the build occurs. | 543 buildroot: The root directory where the build occurs. |
541 board: Board type that was built on this machine | 544 board: Board type that was built on this machine |
542 overlay_config: A string describing which overlays you want. | 545 overlay_config: A string describing which overlays you want. |
543 'private': Just the private overlay. | 546 'private': Just the private overlay. |
544 'public': Just the public overlay. | 547 'public': Just the public overlay. |
545 'both': Both the public and private overlays. | 548 'both': Both the public and private overlays. |
| 549 binhosts: The URLs of the current binhosts. Binaries that are already |
| 550 present will not be uploaded twice. Empty URLs will be ignored. |
546 """ | 551 """ |
547 | 552 |
548 cwd = os.path.join(buildroot, 'src', 'scripts') | 553 cwd = os.path.join(buildroot, 'src', 'scripts') |
549 cmd = [os.path.join(cwd, 'prebuilt.py'), | 554 cmd = [os.path.join(cwd, 'prebuilt.py'), |
550 '--sync-binhost-conf', | 555 '--sync-binhost-conf', |
551 '--build-path', buildroot, | 556 '--build-path', buildroot, |
552 '--board', board, | 557 '--board', board, |
553 '--prepend-version', 'preflight', | 558 '--prepend-version', 'preflight', |
554 '--key', _PREFLIGHT_BINHOST] | 559 '--key', _PREFLIGHT_BINHOST] |
| 560 for binhost in binhosts: |
| 561 if binhost: |
| 562 cmd.extend(['--previous-binhost-url', binhost]) |
555 if overlay_config == 'public': | 563 if overlay_config == 'public': |
556 cmd.extend(['--upload', 'gs://chromeos-prebuilt']) | 564 cmd.extend(['--upload', 'gs://chromeos-prebuilt']) |
557 else: | 565 else: |
558 assert overlay_config in ('private', 'both') | 566 assert overlay_config in ('private', 'both') |
559 cmd.extend(['--upload', 'chromeos-images:/var/www/prebuilt/', | 567 cmd.extend(['--upload', 'chromeos-images:/var/www/prebuilt/', |
560 '--binhost-base-url', 'http://chromeos-prebuilt']) | 568 '--binhost-base-url', 'http://chromeos-prebuilt']) |
561 | 569 |
562 RunCommand(cmd, cwd=cwd) | 570 RunCommand(cmd, cwd=cwd) |
563 | 571 |
564 | 572 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 buildconfig = _GetConfig(args[-1]) | 618 buildconfig = _GetConfig(args[-1]) |
611 else: | 619 else: |
612 Warning('Missing configuration description') | 620 Warning('Missing configuration description') |
613 parser.print_usage() | 621 parser.print_usage() |
614 sys.exit(1) | 622 sys.exit(1) |
615 | 623 |
616 try: | 624 try: |
617 # Calculate list of overlay directories. | 625 # Calculate list of overlay directories. |
618 overlays = _ResolveOverlays(buildroot, buildconfig['overlays']) | 626 overlays = _ResolveOverlays(buildroot, buildconfig['overlays']) |
619 board = buildconfig['board'] | 627 board = buildconfig['board'] |
| 628 old_binhost = None |
620 | 629 |
621 _PreFlightRinse(buildroot, buildconfig['board'], tracking_branch, overlays) | 630 _PreFlightRinse(buildroot, buildconfig['board'], tracking_branch, overlays) |
622 chroot_path = os.path.join(buildroot, 'chroot') | 631 chroot_path = os.path.join(buildroot, 'chroot') |
623 boardpath = os.path.join(chroot_path, 'build', board) | 632 boardpath = os.path.join(chroot_path, 'build', board) |
624 if options.sync: | 633 if options.sync: |
625 if options.clobber or not os.path.isdir(buildroot): | 634 if options.clobber or not os.path.isdir(buildroot): |
626 _FullCheckout(buildroot, tracking_branch, url=options.url) | 635 _FullCheckout(buildroot, tracking_branch, url=options.url) |
627 else: | 636 else: |
628 old_binhost = _GetPortageEnvVar(buildroot, board, _FULL_BINHOST) | 637 old_binhost = _GetPortageEnvVar(buildroot, board, _FULL_BINHOST) |
629 _IncrementalCheckout(buildroot) | 638 _IncrementalCheckout(buildroot) |
630 new_binhost = _GetPortageEnvVar(buildroot, board, _FULL_BINHOST) | 639 |
631 if old_binhost != new_binhost: | 640 new_binhost = _GetPortageEnvVar(buildroot, board, _FULL_BINHOST) |
632 RunCommand(['sudo', 'rm', '-rf', boardpath]) | 641 if old_binhost and old_binhost != new_binhost: |
| 642 RunCommand(['sudo', 'rm', '-rf', boardpath]) |
633 | 643 |
634 # Check that all overlays can be found. | 644 # Check that all overlays can be found. |
635 for path in overlays: | 645 for path in overlays: |
636 assert ':' not in path, 'Overlay must not contain colons: %s' % path | 646 assert ':' not in path, 'Overlay must not contain colons: %s' % path |
637 if not os.path.isdir(path): | 647 if not os.path.isdir(path): |
638 Die('Missing overlay: %s' % path) | 648 Die('Missing overlay: %s' % path) |
639 | 649 |
640 if not os.path.isdir(chroot_path): | 650 if not os.path.isdir(chroot_path): |
641 _MakeChroot(buildroot) | 651 _MakeChroot(buildroot) |
642 | 652 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 test_results_dir=test_results_dir, | 687 test_results_dir=test_results_dir, |
678 gsutil=options.gsutil, | 688 gsutil=options.gsutil, |
679 archive_dir=archive_full_path, | 689 archive_dir=archive_full_path, |
680 acl=options.acl) | 690 acl=options.acl) |
681 | 691 |
682 if buildconfig['uprev']: | 692 if buildconfig['uprev']: |
683 # Don't push changes for developers. | 693 # Don't push changes for developers. |
684 if buildconfig['master']: | 694 if buildconfig['master']: |
685 # Master bot needs to check if the other slaves completed. | 695 # Master bot needs to check if the other slaves completed. |
686 if cbuildbot_comm.HaveSlavesCompleted(config): | 696 if cbuildbot_comm.HaveSlavesCompleted(config): |
687 _UploadPrebuilts(buildroot, board, buildconfig['overlays']) | 697 _UploadPrebuilts(buildroot, board, buildconfig['overlays'], |
| 698 [new_binhost]) |
688 _UprevPush(buildroot, tracking_branch, buildconfig['board'], | 699 _UprevPush(buildroot, tracking_branch, buildconfig['board'], |
689 overlays, options.debug) | 700 overlays, options.debug) |
690 else: | 701 else: |
691 Die('CBUILDBOT - One of the slaves has failed!!!') | 702 Die('CBUILDBOT - One of the slaves has failed!!!') |
692 | 703 |
693 else: | 704 else: |
694 # Publish my status to the master if its expecting it. | 705 # Publish my status to the master if its expecting it. |
695 if buildconfig['important'] and not options.debug: | 706 if buildconfig['important'] and not options.debug: |
696 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) | 707 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_COMPLETE) |
697 | 708 |
698 except: | 709 except: |
699 # Send failure to master bot. | 710 # Send failure to master bot. |
700 if not buildconfig['master'] and buildconfig['important']: | 711 if not buildconfig['master'] and buildconfig['important']: |
701 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) | 712 cbuildbot_comm.PublishStatus(cbuildbot_comm.STATUS_BUILD_FAILED) |
702 | 713 |
703 raise | 714 raise |
704 | 715 |
705 | 716 |
706 if __name__ == '__main__': | 717 if __name__ == '__main__': |
707 main() | 718 main() |
OLD | NEW |