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

Side by Side Diff: buildbot/prebuilt.py

Issue 6851021: Update prebuilt.py to support uploading a board tarball to Google Storage. (Closed) Base URL: http://git.chromium.org/git/chromite.git@master
Patch Set: Address review feedback. Created 9 years, 8 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 | buildbot/prebuilt_unittest.py » ('j') | no next file with comments »
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 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import datetime 6 import datetime
7 import multiprocessing 7 import multiprocessing
8 import optparse 8 import optparse
9 import os 9 import os
10 import re 10 import re
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 """ 44 """
45 45
46 # as per http://crosbug.com/5855 always filter the below packages 46 # as per http://crosbug.com/5855 always filter the below packages
47 _FILTER_PACKAGES = set() 47 _FILTER_PACKAGES = set()
48 _RETRIES = 3 48 _RETRIES = 3
49 _GSUTIL_BIN = '/b/build/third_party/gsutil/gsutil' 49 _GSUTIL_BIN = '/b/build/third_party/gsutil/gsutil'
50 _HOST_PACKAGES_PATH = 'chroot/var/lib/portage/pkgs' 50 _HOST_PACKAGES_PATH = 'chroot/var/lib/portage/pkgs'
51 _CATEGORIES_PATH = 'chroot/etc/portage/categories' 51 _CATEGORIES_PATH = 'chroot/etc/portage/categories'
52 _HOST_TARGET = 'amd64' 52 _HOST_TARGET = 'amd64'
53 _BOARD_PATH = 'chroot/build/%(board)s' 53 _BOARD_PATH = 'chroot/build/%(board)s'
54 # board/board-target/version/packages/' 54 # board/board-target/version/'
55 _REL_BOARD_PATH = 'board/%(board)s/%(version)s/packages' 55 _REL_BOARD_PATH = 'board/%(board)s/%(version)s'
56 # host/host-target/version/packages/' 56 # host/host-target/version/'
57 _REL_HOST_PATH = 'host/%(target)s/%(version)s/packages' 57 _REL_HOST_PATH = 'host/%(target)s/%(version)s'
58 # Private overlays to look at for builds to filter 58 # Private overlays to look at for builds to filter
59 # relative to build path 59 # relative to build path
60 _PRIVATE_OVERLAY_DIR = 'src/private-overlays' 60 _PRIVATE_OVERLAY_DIR = 'src/private-overlays'
61 _GOOGLESTORAGE_ACL_FILE = 'googlestorage_acl.xml' 61 _GOOGLESTORAGE_ACL_FILE = 'googlestorage_acl.xml'
62 _BINHOST_BASE_URL = 'http://commondatastorage.googleapis.com/chromeos-prebuilt' 62 _BINHOST_BASE_URL = 'http://commondatastorage.googleapis.com/chromeos-prebuilt'
63 _PREBUILT_BASE_DIR = 'src/third_party/chromiumos-overlay/chromeos/config/' 63 _PREBUILT_BASE_DIR = 'src/third_party/chromiumos-overlay/chromeos/config/'
64 # Created in the event of new host targets becoming available 64 # Created in the event of new host targets becoming available
65 _PREBUILT_MAKE_CONF = {'amd64': os.path.join(_PREBUILT_BASE_DIR, 65 _PREBUILT_MAKE_CONF = {'amd64': os.path.join(_PREBUILT_BASE_DIR,
66 'make.conf.amd64-host')} 66 'make.conf.amd64-host')}
67 _BINHOST_CONF_DIR = 'src/third_party/chromiumos-overlay/chromeos/binhost' 67 _BINHOST_CONF_DIR = 'src/third_party/chromiumos-overlay/chromeos/binhost'
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 'remote_location': remote_location.rstrip('/'), 508 'remote_location': remote_location.rstrip('/'),
509 'ssh_server': ssh_server } 509 'ssh_server': ssh_server }
510 cmds = ['ssh %(ssh_server)s mkdir -p %(remote_path)s' % d, 510 cmds = ['ssh %(ssh_server)s mkdir -p %(remote_path)s' % d,
511 'rsync -av --chmod=a+r %(pkg_index)s %(remote_packages)s' % d] 511 'rsync -av --chmod=a+r %(pkg_index)s %(remote_packages)s' % d]
512 if pkgs: 512 if pkgs:
513 cmds.append('rsync -Rav %(pkgs)s %(remote_location)s/' % d) 513 cmds.append('rsync -Rav %(pkgs)s %(remote_location)s/' % d)
514 for cmd in cmds: 514 for cmd in cmds:
515 if not _RetryRun(cmd, shell=True, cwd=package_path): 515 if not _RetryRun(cmd, shell=True, cwd=package_path):
516 raise UploadFailed('Could not run %s' % cmd) 516 raise UploadFailed('Could not run %s' % cmd)
517 517
518 def _UploadBoardTarball(self, board_path, url_suffix):
519 """Upload a tarball of the board at the specified path to Google Storage.
520
521 Args:
522 board_path: The path to the board dir.
523 url_suffix: The remote subdirectory where we should upload the packages.
524 """
525 remote_location = '%s/%s' % (self._upload_location.rstrip('/'), url_suffix)
526 assert remote_location.startswith('gs://')
527 cwd, boardname = os.path.split(board_path.rstrip(os.path.sep))
528 tmpdir = tempfile.mkdtemp()
529 try:
530 tarfile = os.path.join(tmpdir, '%s.tbz2' % boardname)
531 cmd = ['sudo', 'tar', '-I', 'pbzip2', '-cf', tarfile]
532 excluded_paths = ('usr/lib/debug', 'usr/local/autotest', 'packages',
533 'tmp')
534 for path in excluded_paths:
535 cmd.append('--exclude=%s/%s/*' % (boardname, path))
536 cmd.append(boardname)
537 cros_build_lib.RunCommand(cmd, cwd=cwd)
538 remote_tarfile = '%s/%s.tbz2' % (remote_location.rstrip('/'), boardname)
539 if _GsUpload((tarfile, remote_tarfile, self._acl)):
540 sys.exit(1)
541 finally:
542 cros_build_lib.RunCommand(['sudo', 'rm', '-rf', tmpdir], cwd=cwd)
543
518 def _SyncHostPrebuilts(self, build_path, version, key, git_sync, 544 def _SyncHostPrebuilts(self, build_path, version, key, git_sync,
519 sync_binhost_conf): 545 sync_binhost_conf):
520 """Synchronize host prebuilt files. 546 """Synchronize host prebuilt files.
521 547
522 This function will sync both the standard host packages, plus the host 548 This function will sync both the standard host packages, plus the host
523 packages associated with all targets that have been "setup" with the 549 packages associated with all targets that have been "setup" with the
524 current host's chroot. For instance, if this host has been used to build 550 current host's chroot. For instance, if this host has been used to build
525 x86-generic, it will sync the host packages associated with 551 x86-generic, it will sync the host packages associated with
526 'i686-pc-linux-gnu'. If this host has also been used to build arm-generic, 552 'i686-pc-linux-gnu'. If this host has also been used to build arm-generic,
527 it will also sync the host packages associated with 553 it will also sync the host packages associated with
528 'armv7a-cros-linux-gnueabi'. 554 'armv7a-cros-linux-gnueabi'.
529 555
530 Args: 556 Args:
531 build_path: The path to the directory containing the chroot. 557 build_path: The path to the directory containing the chroot.
532 version: A unique string, intended to be included in the upload path, 558 version: A unique string, intended to be included in the upload path,
533 which identifies the version number of the uploaded prebuilts. 559 which identifies the version number of the uploaded prebuilts.
534 key: The variable key to update in the git file. 560 key: The variable key to update in the git file.
535 git_sync: If set, update make.conf of target to reference the latest 561 git_sync: If set, update make.conf of target to reference the latest
536 prebuilt packages generated here. 562 prebuilt packages generated here.
537 sync_binhost_conf: If set, update binhost config file in 563 sync_binhost_conf: If set, update binhost config file in
538 chromiumos-overlay for the host. 564 chromiumos-overlay for the host.
539 """ 565 """
540 # Upload prebuilts. 566 # Upload prebuilts.
541 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH) 567 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH)
542 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET} 568 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET}
543 self._UploadPrebuilt(package_path, url_suffix) 569 packages_url_suffix = '%s/packages' % url_suffix.rstrip('/')
570 self._UploadPrebuilt(package_path, packages_url_suffix)
544 571
545 # Record URL where prebuilts were uploaded. 572 # Record URL where prebuilts were uploaded.
546 url_value = '%s/%s/' % (self._binhost_base_url.rstrip('/'), 573 url_value = '%s/%s/' % (self._binhost_base_url.rstrip('/'),
547 url_suffix.rstrip('/')) 574 url_suffix.rstrip('/'))
548 if git_sync: 575 if git_sync:
549 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET]) 576 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET])
550 RevGitFile(git_file, url_value, key=key) 577 RevGitFile(git_file, url_value, key=key)
551 if sync_binhost_conf: 578 if sync_binhost_conf:
552 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'host', 579 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'host',
553 '%s-%s.conf' % (_HOST_TARGET, key)) 580 '%s-%s.conf' % (_HOST_TARGET, key))
554 UpdateBinhostConfFile(binhost_conf, key, url_value) 581 UpdateBinhostConfFile(binhost_conf, key, url_value)
555 582
556 def _SyncBoardPrebuilts(self, board, build_path, version, key, git_sync, 583 def _SyncBoardPrebuilts(self, board, build_path, version, key, git_sync,
557 sync_binhost_conf): 584 sync_binhost_conf, upload_board_tarball):
558 """Synchronize board prebuilt files. 585 """Synchronize board prebuilt files.
559 586
560 Args: 587 Args:
561 board: The board to upload to Google Storage. 588 board: The board to upload to Google Storage.
562 build_path: The path to the directory containing the chroot. 589 build_path: The path to the directory containing the chroot.
563 version: A unique string, intended to be included in the upload path, 590 version: A unique string, intended to be included in the upload path,
564 which identifies the version number of the uploaded prebuilts. 591 which identifies the version number of the uploaded prebuilts.
565 key: The variable key to update in the git file. 592 key: The variable key to update in the git file.
566 git_sync: If set, update make.conf of target to reference the latest 593 git_sync: If set, update make.conf of target to reference the latest
567 prebuilt packages generated here. 594 prebuilt packages generated here.
568 sync_binhost_conf: If set, update binhost config file in 595 sync_binhost_conf: If set, update binhost config file in
569 chromiumos-overlay for the current board. 596 chromiumos-overlay for the current board.
597 upload_board_tarball: Include a tarball of the board in our upload.
570 """ 598 """
571 # Upload prebuilts.
572 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board}) 599 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board})
573 package_path = os.path.join(board_path, 'packages') 600 package_path = os.path.join(board_path, 'packages')
574 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version} 601 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version}
575 self._UploadPrebuilt(package_path, url_suffix) 602 packages_url_suffix = '%s/packages' % url_suffix.rstrip('/')
603
604 # Upload board tarballs in the background.
605 if upload_board_tarball:
606 tar_process = multiprocessing.Process(target=self._UploadBoardTarball,
607 args=(board_path, url_suffix))
608 tar_process.start()
609
610 # Upload prebuilts.
611 self._UploadPrebuilt(package_path, packages_url_suffix)
612
613 # Make sure we finished uploading the board tarballs.
614 if upload_board_tarball:
615 tar_process.join()
616 assert tar_process.exitcode == 0
576 617
577 # Record URL where prebuilts were uploaded. 618 # Record URL where prebuilts were uploaded.
578 url_value = '%s/%s/' % (self._binhost_base_url.rstrip('/'), 619 url_value = '%s/%s/' % (self._binhost_base_url.rstrip('/'),
579 url_suffix.rstrip('/')) 620 url_suffix.rstrip('/'))
580 if git_sync: 621 if git_sync:
581 git_file = DeterminePrebuiltConfFile(build_path, board) 622 git_file = DeterminePrebuiltConfFile(build_path, board)
582 RevGitFile(git_file, url_value, key=key) 623 RevGitFile(git_file, url_value, key=key)
583 if sync_binhost_conf: 624 if sync_binhost_conf:
584 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'target', 625 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'target',
585 '%s-%s.conf' % (board, key)) 626 '%s-%s.conf' % (board, key))
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 default=False, 661 default=False,
621 help='Turn on filtering of private ebuild packages') 662 help='Turn on filtering of private ebuild packages')
622 parser.add_option('-k', '--key', dest='key', 663 parser.add_option('-k', '--key', dest='key',
623 default='PORTAGE_BINHOST', 664 default='PORTAGE_BINHOST',
624 help='Key to update in make.conf / binhost.conf') 665 help='Key to update in make.conf / binhost.conf')
625 parser.add_option('', '--sync-binhost-conf', dest='sync_binhost_conf', 666 parser.add_option('', '--sync-binhost-conf', dest='sync_binhost_conf',
626 default=False, action='store_true', 667 default=False, action='store_true',
627 help='Update binhost.conf') 668 help='Update binhost.conf')
628 parser.add_option('-P', '--private', dest='private', action='store_true', 669 parser.add_option('-P', '--private', dest='private', action='store_true',
629 default=False, help='Mark gs:// uploads as private.') 670 default=False, help='Mark gs:// uploads as private.')
671 parser.add_option('', '--upload-board-tarball', dest='upload_board_tarball',
672 action='store_true', default=False,
673 help='Upload board tarball to Google Storage.')
630 674
631 options, args = parser.parse_args() 675 options, args = parser.parse_args()
632 if not options.build_path: 676 if not options.build_path:
633 usage(parser, 'Error: you need provide a chroot path') 677 usage(parser, 'Error: you need provide a chroot path')
634 if not options.upload: 678 if not options.upload:
635 usage(parser, 'Error: you need to provide an upload location using -u') 679 usage(parser, 'Error: you need to provide an upload location using -u')
636 680
681
682 if options.upload_board_tarball and not options.upload.startswith('gs://'):
683 usage(parser, 'Error: --upload-board-tarball only works with gs:// URLs.\n'
684 '--upload must be a gs:// URL.')
685
637 if options.private: 686 if options.private:
638 if options.sync_host: 687 if options.sync_host:
639 usage(parser, 'Error: --private and --sync-host/-s cannot be specified ' 688 usage(parser, 'Error: --private and --sync-host/-s cannot be specified '
640 'together, we do not support private host prebuilts') 689 'together, we do not support private host prebuilts')
641 690
642 if not options.upload.startswith('gs://'): 691 if not options.upload.startswith('gs://'):
643 usage(parser, 'Error: --private is only valid for gs:// URLs.\n' 692 usage(parser, 'Error: --private is only valid for gs:// URLs.\n'
644 '--upload must be a gs:// URL.') 693 '--upload must be a gs:// URL.')
645 694
646 if options.binhost_base_url != _BINHOST_BASE_URL: 695 if options.binhost_base_url != _BINHOST_BASE_URL:
(...skipping 30 matching lines...) Expand all
677 uploader = PrebuiltUploader(options.upload, acl, binhost_base_url, 726 uploader = PrebuiltUploader(options.upload, acl, binhost_base_url,
678 pkg_indexes) 727 pkg_indexes)
679 728
680 if options.sync_host: 729 if options.sync_host:
681 uploader._SyncHostPrebuilts(options.build_path, version, options.key, 730 uploader._SyncHostPrebuilts(options.build_path, version, options.key,
682 options.git_sync, options.sync_binhost_conf) 731 options.git_sync, options.sync_binhost_conf)
683 732
684 if options.board: 733 if options.board:
685 uploader._SyncBoardPrebuilts(options.board, options.build_path, version, 734 uploader._SyncBoardPrebuilts(options.board, options.build_path, version,
686 options.key, options.git_sync, 735 options.key, options.git_sync,
687 options.sync_binhost_conf) 736 options.sync_binhost_conf,
737 options.upload_board_tarball)
688 738
689 if __name__ == '__main__': 739 if __name__ == '__main__':
690 main() 740 main()
OLDNEW
« no previous file with comments | « no previous file | buildbot/prebuilt_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698