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

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: Add more checks 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
scottz 2011/04/15 17:40:46 Args:
davidjames 2011/04/15 19:18:08 Done.
521 board_path: The path to the board dir.
522 url_suffix: The remote subdirectory where we should upload the packages.
523 """
524 remote_location = '%s/%s' % (self._upload_location.rstrip('/'), url_suffix)
525 assert remote_location.startswith('gs://')
526 cwd, boardname = os.path.split(board_path.rstrip(os.path.sep))
527 tarfile = '/tmp/%s.tbz2' % boardname
scottz 2011/04/15 17:40:46 You should use tempfile here. I prefer not to ass
davidjames 2011/04/15 19:18:08 Done. Now that we switched to tempfile, it will h
528 cmd = ['sudo', 'tar', '-I', 'pbzip2', '-cf', tarfile]
529 for path in ('usr/lib/debug', 'usr/local/autotest', 'packages', 'tmp'):
scottz 2011/04/15 17:40:46 Assigning these to a variable excluded_paths would
davidjames 2011/04/15 19:18:08 Done.
530 cmd.append('--exclude=%s/%s/*' % (boardname, path))
531 cmd.append(boardname)
532 cros_build_lib.RunCommand(cmd, cwd=cwd)
scottz 2011/04/15 17:40:46 this should be in your try, if tar fails we are le
davidjames 2011/04/15 19:18:08 Done.
533 remote_tarfile = '%s/%s.tbz2' % (remote_location.rstrip('/'), boardname)
534 try:
535 if _GsUpload((tarfile, remote_tarfile, self._acl)):
536 sys.exit(1)
537 finally:
538 cros_build_lib.RunCommand(['sudo', 'rm', '-f', tarfile], cwd=cwd)
539
518 def _SyncHostPrebuilts(self, build_path, version, key, git_sync, 540 def _SyncHostPrebuilts(self, build_path, version, key, git_sync,
519 sync_binhost_conf): 541 sync_binhost_conf):
520 """Synchronize host prebuilt files. 542 """Synchronize host prebuilt files.
521 543
522 This function will sync both the standard host packages, plus the host 544 This function will sync both the standard host packages, plus the host
523 packages associated with all targets that have been "setup" with the 545 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 546 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 547 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, 548 '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 549 it will also sync the host packages associated with
528 'armv7a-cros-linux-gnueabi'. 550 'armv7a-cros-linux-gnueabi'.
529 551
530 Args: 552 Args:
531 build_path: The path to the directory containing the chroot. 553 build_path: The path to the directory containing the chroot.
532 version: A unique string, intended to be included in the upload path, 554 version: A unique string, intended to be included in the upload path,
533 which identifies the version number of the uploaded prebuilts. 555 which identifies the version number of the uploaded prebuilts.
534 key: The variable key to update in the git file. 556 key: The variable key to update in the git file.
535 git_sync: If set, update make.conf of target to reference the latest 557 git_sync: If set, update make.conf of target to reference the latest
536 prebuilt packages generated here. 558 prebuilt packages generated here.
537 sync_binhost_conf: If set, update binhost config file in 559 sync_binhost_conf: If set, update binhost config file in
538 chromiumos-overlay for the host. 560 chromiumos-overlay for the host.
539 """ 561 """
540 # Upload prebuilts. 562 # Upload prebuilts.
541 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH) 563 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH)
542 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET} 564 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET}
543 self._UploadPrebuilt(package_path, url_suffix) 565 packages_url_suffix = '%s/packages' % url_suffix.rstrip('/')
566 self._UploadPrebuilt(package_path, packages_url_suffix)
544 567
545 # Record URL where prebuilts were uploaded. 568 # Record URL where prebuilts were uploaded.
546 url_value = '%s/%s/' % (self._binhost_base_url.rstrip('/'), 569 url_value = '%s/%s/' % (self._binhost_base_url.rstrip('/'),
547 url_suffix.rstrip('/')) 570 url_suffix.rstrip('/'))
548 if git_sync: 571 if git_sync:
549 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET]) 572 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET])
550 RevGitFile(git_file, url_value, key=key) 573 RevGitFile(git_file, url_value, key=key)
551 if sync_binhost_conf: 574 if sync_binhost_conf:
552 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'host', 575 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'host',
553 '%s-%s.conf' % (_HOST_TARGET, key)) 576 '%s-%s.conf' % (_HOST_TARGET, key))
554 UpdateBinhostConfFile(binhost_conf, key, url_value) 577 UpdateBinhostConfFile(binhost_conf, key, url_value)
555 578
556 def _SyncBoardPrebuilts(self, board, build_path, version, key, git_sync, 579 def _SyncBoardPrebuilts(self, board, build_path, version, key, git_sync,
557 sync_binhost_conf): 580 sync_binhost_conf, upload_board_tarball):
558 """Synchronize board prebuilt files. 581 """Synchronize board prebuilt files.
559 582
560 Args: 583 Args:
561 board: The board to upload to Google Storage. 584 board: The board to upload to Google Storage.
562 build_path: The path to the directory containing the chroot. 585 build_path: The path to the directory containing the chroot.
563 version: A unique string, intended to be included in the upload path, 586 version: A unique string, intended to be included in the upload path,
564 which identifies the version number of the uploaded prebuilts. 587 which identifies the version number of the uploaded prebuilts.
565 key: The variable key to update in the git file. 588 key: The variable key to update in the git file.
566 git_sync: If set, update make.conf of target to reference the latest 589 git_sync: If set, update make.conf of target to reference the latest
567 prebuilt packages generated here. 590 prebuilt packages generated here.
568 sync_binhost_conf: If set, update binhost config file in 591 sync_binhost_conf: If set, update binhost config file in
569 chromiumos-overlay for the current board. 592 chromiumos-overlay for the current board.
593 upload_board_tarball: Include a tarball of the board in our upload.
570 """ 594 """
571 # Upload prebuilts. 595 # Upload prebuilts.
572 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board}) 596 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board})
573 package_path = os.path.join(board_path, 'packages') 597 package_path = os.path.join(board_path, 'packages')
574 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version} 598 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version}
575 self._UploadPrebuilt(package_path, url_suffix) 599 packages_url_suffix = '%s/packages' % url_suffix.rstrip('/')
600
601 if upload_board_tarball:
scottz 2011/04/15 17:40:46 Please add a comment about you uploading board tar
davidjames 2011/04/15 19:18:08 Done.
602 p = multiprocessing.Process(target=self._UploadBoardTarball,
scottz 2011/04/15 17:40:46 Please consider using something other than p. tar_
davidjames 2011/04/15 19:18:08 Done.
603 args=(board_path, url_suffix))
604 p.start()
605
606 self._UploadPrebuilt(package_path, packages_url_suffix)
607
608 if upload_board_tarball:
609 p.join()
610 assert p.exitcode == 0
576 611
577 # Record URL where prebuilts were uploaded. 612 # Record URL where prebuilts were uploaded.
578 url_value = '%s/%s/' % (self._binhost_base_url.rstrip('/'), 613 url_value = '%s/%s/' % (self._binhost_base_url.rstrip('/'),
579 url_suffix.rstrip('/')) 614 url_suffix.rstrip('/'))
580 if git_sync: 615 if git_sync:
581 git_file = DeterminePrebuiltConfFile(build_path, board) 616 git_file = DeterminePrebuiltConfFile(build_path, board)
582 RevGitFile(git_file, url_value, key=key) 617 RevGitFile(git_file, url_value, key=key)
583 if sync_binhost_conf: 618 if sync_binhost_conf:
584 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'target', 619 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'target',
585 '%s-%s.conf' % (board, key)) 620 '%s-%s.conf' % (board, key))
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 default=False, 655 default=False,
621 help='Turn on filtering of private ebuild packages') 656 help='Turn on filtering of private ebuild packages')
622 parser.add_option('-k', '--key', dest='key', 657 parser.add_option('-k', '--key', dest='key',
623 default='PORTAGE_BINHOST', 658 default='PORTAGE_BINHOST',
624 help='Key to update in make.conf / binhost.conf') 659 help='Key to update in make.conf / binhost.conf')
625 parser.add_option('', '--sync-binhost-conf', dest='sync_binhost_conf', 660 parser.add_option('', '--sync-binhost-conf', dest='sync_binhost_conf',
626 default=False, action='store_true', 661 default=False, action='store_true',
627 help='Update binhost.conf') 662 help='Update binhost.conf')
628 parser.add_option('-P', '--private', dest='private', action='store_true', 663 parser.add_option('-P', '--private', dest='private', action='store_true',
629 default=False, help='Mark gs:// uploads as private.') 664 default=False, help='Mark gs:// uploads as private.')
665 parser.add_option('', '--upload-board-tarball', dest='upload_board_tarball',
666 action='store_true', default=False,
667 help='Upload board tarball to Google Storage.')
630 668
631 options, args = parser.parse_args() 669 options, args = parser.parse_args()
632 if not options.build_path: 670 if not options.build_path:
633 usage(parser, 'Error: you need provide a chroot path') 671 usage(parser, 'Error: you need provide a chroot path')
634 if not options.upload: 672 if not options.upload:
635 usage(parser, 'Error: you need to provide an upload location using -u') 673 usage(parser, 'Error: you need to provide an upload location using -u')
636 674
675
676 if options.upload_board_tarball and not options.upload.startswith('gs://'):
677 usage(parser, 'Error: --upload-board-tarball only works with gs:// URLs.\n'
678 '--upload must be a gs:// URL.')
679
637 if options.private: 680 if options.private:
638 if options.sync_host: 681 if options.sync_host:
639 usage(parser, 'Error: --private and --sync-host/-s cannot be specified ' 682 usage(parser, 'Error: --private and --sync-host/-s cannot be specified '
640 'together, we do not support private host prebuilts') 683 'together, we do not support private host prebuilts')
641 684
642 if not options.upload.startswith('gs://'): 685 if not options.upload.startswith('gs://'):
643 usage(parser, 'Error: --private is only valid for gs:// URLs.\n' 686 usage(parser, 'Error: --private is only valid for gs:// URLs.\n'
644 '--upload must be a gs:// URL.') 687 '--upload must be a gs:// URL.')
645 688
646 if options.binhost_base_url != _BINHOST_BASE_URL: 689 if options.binhost_base_url != _BINHOST_BASE_URL:
(...skipping 30 matching lines...) Expand all
677 uploader = PrebuiltUploader(options.upload, acl, binhost_base_url, 720 uploader = PrebuiltUploader(options.upload, acl, binhost_base_url,
678 pkg_indexes) 721 pkg_indexes)
679 722
680 if options.sync_host: 723 if options.sync_host:
681 uploader._SyncHostPrebuilts(options.build_path, version, options.key, 724 uploader._SyncHostPrebuilts(options.build_path, version, options.key,
682 options.git_sync, options.sync_binhost_conf) 725 options.git_sync, options.sync_binhost_conf)
683 726
684 if options.board: 727 if options.board:
685 uploader._SyncBoardPrebuilts(options.board, options.build_path, version, 728 uploader._SyncBoardPrebuilts(options.board, options.build_path, version,
686 options.key, options.git_sync, 729 options.key, options.git_sync,
687 options.sync_binhost_conf) 730 options.sync_binhost_conf,
731 options.upload_board_tarball)
688 732
689 if __name__ == '__main__': 733 if __name__ == '__main__':
690 main() 734 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