Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 # Private overlays to look at for builds to filter | 52 # Private overlays to look at for builds to filter |
| 53 # relative to build path | 53 # relative to build path |
| 54 _PRIVATE_OVERLAY_DIR = 'src/private-overlays' | 54 _PRIVATE_OVERLAY_DIR = 'src/private-overlays' |
| 55 _BINHOST_BASE_DIR = 'src/overlays' | 55 _BINHOST_BASE_DIR = 'src/overlays' |
| 56 #_BINHOST_BASE_URL = 'http://commondatastorage.googleapis.com/chromeos-prebuilt' | 56 #_BINHOST_BASE_URL = 'http://commondatastorage.googleapis.com/chromeos-prebuilt' |
| 57 _BINHOST_BASE_URL = 'http://gsdview.appspot.com/chromeos-prebuilt' | 57 _BINHOST_BASE_URL = 'http://gsdview.appspot.com/chromeos-prebuilt' |
| 58 _PREBUILT_BASE_DIR = 'src/third_party/chromiumos-overlay/chromeos/config/' | 58 _PREBUILT_BASE_DIR = 'src/third_party/chromiumos-overlay/chromeos/config/' |
| 59 # Created in the event of new host targets becoming available | 59 # Created in the event of new host targets becoming available |
| 60 _PREBUILT_MAKE_CONF = {'amd64': os.path.join(_PREBUILT_BASE_DIR, | 60 _PREBUILT_MAKE_CONF = {'amd64': os.path.join(_PREBUILT_BASE_DIR, |
| 61 'make.conf.amd64-host')} | 61 'make.conf.amd64-host')} |
| 62 _BINHOST_CONF_DIR = 'src/third_party/chromiumos-overlay/chromeos/binhost' | |
|
sosa
2010/11/24 00:40:02
As an FYI this list is sorta getting out of hand.
scottz
2010/11/29 17:56:39
+1
On 2010/11/24 00:40:02, sosa wrote:
| |
| 62 | 63 |
| 63 | 64 |
| 64 class FiltersEmpty(Exception): | 65 class FiltersEmpty(Exception): |
| 65 """Raised when filters are used but none are found.""" | 66 """Raised when filters are used but none are found.""" |
| 66 pass | 67 pass |
| 67 | 68 |
| 68 | 69 |
| 69 class UploadFailed(Exception): | 70 class UploadFailed(Exception): |
| 70 """Raised when one of the files uploaded failed.""" | 71 """Raised when one of the files uploaded failed.""" |
| 71 pass | 72 pass |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 85 Note quotes are added automatically | 86 Note quotes are added automatically |
| 86 | 87 |
| 87 Args: | 88 Args: |
| 88 filename: Name of file to modify. | 89 filename: Name of file to modify. |
| 89 value: Value to write with the key. | 90 value: Value to write with the key. |
| 90 key: The variable key to update. (Default: PORTAGE_BINHOST) | 91 key: The variable key to update. (Default: PORTAGE_BINHOST) |
| 91 """ | 92 """ |
| 92 file_fh = open(filename) | 93 file_fh = open(filename) |
| 93 file_lines = [] | 94 file_lines = [] |
| 94 found = False | 95 found = False |
| 96 keyval_str = '%(key)s=%(value)s' | |
| 95 for line in file_fh: | 97 for line in file_fh: |
| 96 # Strip newlines from end of line. We already add newlines below. | 98 # Strip newlines from end of line. We already add newlines below. |
| 97 line = line.rstrip("\n") | 99 line = line.rstrip("\n") |
| 98 | 100 |
| 99 if len(line.split('=')) != 2: | 101 if len(line.split('=')) != 2: |
| 100 # Skip any line that doesn't fit key=val. | 102 # Skip any line that doesn't fit key=val. |
| 101 file_lines.append(line) | 103 file_lines.append(line) |
| 102 continue | 104 continue |
| 103 | 105 |
| 104 file_var, file_val = line.split('=') | 106 file_var, file_val = line.split('=') |
| 105 keyval_str = '%(key)s=%(value)s' | |
| 106 if file_var == key: | 107 if file_var == key: |
| 107 found = True | 108 found = True |
| 108 print 'Updating %s=%s to %s="%s"' % (file_var, file_val, key, value) | 109 print 'Updating %s=%s to %s="%s"' % (file_var, file_val, key, value) |
| 109 value = '"%s"' % value | 110 value = '"%s"' % value |
| 110 file_lines.append(keyval_str % {'key': key, 'value': value}) | 111 file_lines.append(keyval_str % {'key': key, 'value': value}) |
| 111 else: | 112 else: |
| 112 file_lines.append(keyval_str % {'key': file_var, 'value': file_val}) | 113 file_lines.append(keyval_str % {'key': file_var, 'value': file_val}) |
| 113 | 114 |
| 114 if not found: | 115 if not found: |
| 115 file_lines.append(keyval_str % {'key': key, 'value': value}) | 116 file_lines.append(keyval_str % {'key': key, 'value': value}) |
| 116 | 117 |
| 117 file_fh.close() | 118 file_fh.close() |
| 118 # write out new file | 119 # write out new file |
| 119 new_file_fh = open(filename, 'w') | 120 new_file_fh = open(filename, 'w') |
| 120 new_file_fh.write('\n'.join(file_lines)) | 121 new_file_fh.write('\n'.join(file_lines) + '\n') |
| 121 new_file_fh.close() | 122 new_file_fh.close() |
| 122 | 123 |
| 123 | 124 |
| 124 def RevGitPushWithRetry(retries=5): | 125 def RevGitPushWithRetry(retries=5): |
| 125 """Repo sync and then push git changes in flight. | 126 """Repo sync and then push git changes in flight. |
| 126 | 127 |
| 127 Args: | 128 Args: |
| 128 retries: The number of times to retry before giving up, default: 5 | 129 retries: The number of times to retry before giving up, default: 5 |
| 129 | 130 |
| 130 Raises: | 131 Raises: |
| 131 GitPushFailed if push was unsuccessful after retries | 132 GitPushFailed if push was unsuccessful after retries |
| 132 """ | 133 """ |
| 133 for retry in range(1, retries+1): | 134 for retry in range(1, retries+1): |
| 134 try: | 135 try: |
| 135 cros_build_lib.RunCommand('repo sync .', shell=True) | 136 cros_build_lib.RunCommand('repo sync .', shell=True) |
| 136 cros_build_lib.RunCommand('git push', shell=True) | 137 cros_build_lib.RunCommand('git push', shell=True) |
| 137 break | 138 break |
| 138 except cros_build_lib.RunCommandError: | 139 except cros_build_lib.RunCommandError: |
| 139 if retry < retries: | 140 if retry < retries: |
| 140 print 'Error pushing changes trying again (%s/%s)' % (retry, retries) | 141 print 'Error pushing changes trying again (%s/%s)' % (retry, retries) |
| 141 time.sleep(5*retry) | 142 time.sleep(5*retry) |
| 142 else: | 143 else: |
| 143 raise GitPushFailed('Failed to push change after %s retries' % retries) | 144 raise GitPushFailed('Failed to push change after %s retries' % retries) |
| 144 | 145 |
| 145 | 146 |
| 146 def RevGitFile(filename, value, retries=5): | 147 def RevGitFile(filename, value, retries=5, key='PORTAGE_BINHOST'): |
| 147 """Update and push the git file. | 148 """Update and push the git file. |
| 148 | 149 |
| 149 Args: | 150 Args: |
| 150 filename: file to modify that is in a git repo already | 151 filename: file to modify that is in a git repo already |
| 151 value: string representing the version of the prebuilt that has been | 152 value: string representing the version of the prebuilt that has been |
| 152 uploaded. | 153 uploaded. |
| 153 retries: The number of times to retry before giving up, default: 5 | 154 retries: The number of times to retry before giving up, default: 5 |
| 155 key: The variable key to update in the git file. | |
| 156 (Default: PORTAGE_BINHOST) | |
| 154 """ | 157 """ |
| 155 prebuilt_branch = 'prebuilt_branch' | 158 prebuilt_branch = 'prebuilt_branch' |
| 156 old_cwd = os.getcwd() | 159 old_cwd = os.getcwd() |
| 157 os.chdir(os.path.dirname(filename)) | 160 os.chdir(os.path.dirname(filename)) |
| 158 | 161 |
| 159 cros_build_lib.RunCommand('repo sync .', shell=True) | 162 cros_build_lib.RunCommand('repo sync .', shell=True) |
| 160 cros_build_lib.RunCommand('repo start %s .' % prebuilt_branch, shell=True) | 163 cros_build_lib.RunCommand('repo start %s .' % prebuilt_branch, shell=True) |
| 161 git_ssh_config_cmd = ( | 164 git_ssh_config_cmd = ( |
| 162 'git config url.ssh://git@gitrw.chromium.org:9222.pushinsteadof ' | 165 'git config url.ssh://git@gitrw.chromium.org:9222.pushinsteadof ' |
| 163 'http://git.chromium.org/git') | 166 'http://git.chromium.org/git') |
| 164 cros_build_lib.RunCommand(git_ssh_config_cmd, shell=True) | 167 cros_build_lib.RunCommand(git_ssh_config_cmd, shell=True) |
| 165 description = 'Update PORTAGE_BINHOST="%s" in %s' % (value, filename) | 168 description = 'Update %s="%s" in %s' % (key, value, filename) |
| 166 print description | 169 print description |
| 167 try: | 170 try: |
| 168 UpdateLocalFile(filename, value) | 171 UpdateLocalFile(filename, value, key) |
| 169 cros_build_lib.RunCommand('git config push.default tracking', shell=True) | 172 cros_build_lib.RunCommand('git config push.default tracking', shell=True) |
| 170 cros_build_lib.RunCommand('git commit -am "%s"' % description, shell=True) | 173 cros_build_lib.RunCommand('git commit -am "%s"' % description, shell=True) |
| 171 RevGitPushWithRetry(retries) | 174 RevGitPushWithRetry(retries) |
| 172 finally: | 175 finally: |
| 173 cros_build_lib.RunCommand('repo abandon %s .' % prebuilt_branch, shell=True) | 176 cros_build_lib.RunCommand('repo abandon %s .' % prebuilt_branch, shell=True) |
| 174 os.chdir(old_cwd) | 177 os.chdir(old_cwd) |
| 175 | 178 |
| 176 | 179 |
| 177 def GetVersion(): | 180 def GetVersion(): |
| 178 """Get the version to put in LATEST and update the git version with.""" | 181 """Get the version to put in LATEST and update the git version with.""" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 elif re.match('.*?-\w+', target): | 402 elif re.match('.*?-\w+', target): |
| 400 overlay_str = 'overlay-%s' % target | 403 overlay_str = 'overlay-%s' % target |
| 401 make_path = os.path.join(_BINHOST_BASE_DIR, overlay_str, 'make.conf') | 404 make_path = os.path.join(_BINHOST_BASE_DIR, overlay_str, 'make.conf') |
| 402 else: | 405 else: |
| 403 raise UnknownBoardFormat('Unknown format: %s' % target) | 406 raise UnknownBoardFormat('Unknown format: %s' % target) |
| 404 | 407 |
| 405 return os.path.join(make_path) | 408 return os.path.join(make_path) |
| 406 | 409 |
| 407 | 410 |
| 408 def UploadPrebuilt(build_path, upload_location, version, binhost_base_url, | 411 def UploadPrebuilt(build_path, upload_location, version, binhost_base_url, |
| 409 board=None, git_sync=False, git_sync_retries=5): | 412 board=None, git_sync=False, git_sync_retries=5, |
| 413 key='PORTAGE_BINHOST', sync_binhost_conf=False): | |
| 410 """Upload Host prebuilt files to Google Storage space. | 414 """Upload Host prebuilt files to Google Storage space. |
| 411 | 415 |
| 412 Args: | 416 Args: |
| 413 build_path: The path to the root of the chroot. | 417 build_path: The path to the root of the chroot. |
| 414 upload_location: The upload location. | 418 upload_location: The upload location. |
| 415 board: The board to upload to Google Storage, if this is None upload | 419 board: The board to upload to Google Storage, if this is None upload |
| 416 host packages. | 420 host packages. |
| 417 git_sync: If set, update make.conf of target to reference the latest | 421 git_sync: If set, update make.conf of target to reference the latest |
| 418 prebuilt packages genereated here. | 422 prebuilt packages generated here. |
| 419 git_sync_retries: How many times to retry pushing when updating git files. | 423 git_sync_retries: How many times to retry pushing when updating git files. |
| 420 This helps avoid failures when multiple bots are modifying the same Repo. | 424 This helps avoid failures when multiple bots are modifying the same Repo. |
| 421 default: 5 | 425 default: 5 |
| 426 key: The variable key to update in the git file. (Default: PORTAGE_BINHOST) | |
| 427 sync_binhost_conf: If set, update binhost config file in chromiumos-overlay | |
| 428 for the current board or host. | |
| 422 """ | 429 """ |
| 423 | 430 |
| 424 if not board: | 431 if not board: |
| 425 # We are uploading host packages | 432 # We are uploading host packages |
| 426 # TODO(scottz): eventually add support for different host_targets | 433 # TODO(scottz): eventually add support for different host_targets |
| 427 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH) | 434 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH) |
| 428 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET} | 435 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET} |
| 429 package_string = _HOST_TARGET | 436 package_string = _HOST_TARGET |
| 430 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET]) | 437 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET]) |
| 438 binhost_conf = os.path.join(build_path, | |
| 439 '%s/host/%s.conf' % (_BINHOST_CONF_DIR, _HOST_TARGET)) | |
|
diandersAtChromium
2010/11/24 01:30:31
Just pass 4 params to os.path.join:
os.path.join(
scottz
2010/11/29 17:56:39
Agreed but the last one will still need the .conf
davidjames
2010/11/29 21:18:55
Done.
| |
| 431 else: | 440 else: |
| 432 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board}) | 441 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board}) |
| 433 package_path = os.path.join(board_path, 'packages') | 442 package_path = os.path.join(board_path, 'packages') |
| 434 package_string = board | 443 package_string = board |
| 435 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version} | 444 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version} |
| 436 git_file = os.path.join(build_path, DetermineMakeConfFile(board)) | 445 git_file = os.path.join(build_path, DetermineMakeConfFile(board)) |
| 446 binhost_conf = os.path.join(build_path, | |
| 447 '%s/target/%s.conf' % (_BINHOST_CONF_DIR, board)) | |
|
diandersAtChromium
2010/11/24 01:30:31
Same: 4 params to os.path.join.
davidjames
2010/11/29 21:18:55
Done.
| |
| 437 remote_location = os.path.join(upload_location, url_suffix) | 448 remote_location = os.path.join(upload_location, url_suffix) |
| 438 | 449 |
| 439 if upload_location.startswith('gs://'): | 450 if upload_location.startswith('gs://'): |
| 440 upload_files = GenerateUploadDict(package_path, remote_location) | 451 upload_files = GenerateUploadDict(package_path, remote_location) |
| 441 | 452 |
| 442 print 'Uploading %s' % package_string | 453 print 'Uploading %s' % package_string |
| 443 failed_uploads = RemoteUpload(upload_files) | 454 failed_uploads = RemoteUpload(upload_files) |
| 444 if len(failed_uploads) > 1 or (None not in failed_uploads): | 455 if len(failed_uploads) > 1 or (None not in failed_uploads): |
| 445 error_msg = ['%s -> %s\n' % args for args in failed_uploads] | 456 error_msg = ['%s -> %s\n' % args for args in failed_uploads] |
| 446 raise UploadFailed('Error uploading:\n%s' % error_msg) | 457 raise UploadFailed('Error uploading:\n%s' % error_msg) |
| 447 else: | 458 else: |
| 448 ssh_server, remote_path = remote_location.split(':', 1) | 459 ssh_server, remote_path = remote_location.split(':', 1) |
| 449 cmds = ['ssh %s mkdir -p %s' % (ssh_server, remote_path), | 460 cmds = ['ssh %s mkdir -p %s' % (ssh_server, remote_path), |
| 450 'rsync -av %s/ %s/' % (package_path, remote_location)] | 461 'rsync -av %s/ %s/' % (package_path, remote_location)] |
| 451 for cmd in cmds: | 462 for cmd in cmds: |
| 452 if not _RetryRun(cmd, shell=True): | 463 if not _RetryRun(cmd, shell=True): |
| 453 raise UploadFailed('Could not run %s' % cmd) | 464 raise UploadFailed('Could not run %s' % cmd) |
| 454 | 465 |
| 466 url_value = '%s/%s/' % (binhost_base_url, url_suffix) | |
| 467 | |
| 455 if git_sync: | 468 if git_sync: |
| 456 url_value = '%s/%s/' % (binhost_base_url, url_suffix) | 469 RevGitFile(git_file, url_value, retries=git_sync_retries, key=key) |
| 457 RevGitFile(git_file, url_value, retries=git_sync_retries) | 470 |
| 471 if sync_binhost_conf: | |
|
scottz
2010/11/29 17:56:39
Move this into a function.
davidjames
2010/11/29 21:18:55
Done.
| |
| 472 binhost_dir = os.path.dirname(os.path.abspath(binhost_conf)) | |
| 473 binhost_filename = os.path.basename(binhost_conf) | |
| 474 if not os.path.isdir(binhost_dir): | |
| 475 os.makedirs(binhost_dir) | |
| 476 if not os.path.isfile(binhost_conf): | |
| 477 f = file(binhost_conf, 'w') | |
|
scottz
2010/11/29 17:56:39
Nit, use something better than f please. I know yo
davidjames
2010/11/29 21:18:55
Done.
| |
| 478 f.write('FULL_BINHOST="$PORTAGE_BINHOST"\n') | |
| 479 f.close() | |
| 480 UpdateLocalFile(binhost_conf, url_value, key) | |
| 481 cros_build_lib.RunCommand('git add %s' % binhost_filename, cwd=binhost_dir, | |
| 482 shell=True) | |
| 483 description = 'Update %s=%s in %s' % (key, url_value, binhost_filename) | |
| 484 cros_build_lib.RunCommand('git commit -m "%s"' % description, | |
| 485 cwd=binhost_dir, shell=True) | |
| 458 | 486 |
| 459 | 487 |
| 460 def usage(parser, msg): | 488 def usage(parser, msg): |
| 461 """Display usage message and parser help then exit with 1.""" | 489 """Display usage message and parser help then exit with 1.""" |
| 462 print >> sys.stderr, msg | 490 print >> sys.stderr, msg |
| 463 parser.print_help() | 491 parser.print_help() |
| 464 sys.exit(1) | 492 sys.exit(1) |
| 465 | 493 |
| 466 | 494 |
| 467 def main(): | 495 def main(): |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 481 help='Enable git version sync (This commits to a repo)') | 509 help='Enable git version sync (This commits to a repo)') |
| 482 parser.add_option('-u', '--upload', dest='upload', | 510 parser.add_option('-u', '--upload', dest='upload', |
| 483 default=None, | 511 default=None, |
| 484 help='Upload location') | 512 help='Upload location') |
| 485 parser.add_option('-V', '--prepend-version', dest='prepend_version', | 513 parser.add_option('-V', '--prepend-version', dest='prepend_version', |
| 486 default=None, | 514 default=None, |
| 487 help='Add an identifier to the front of the version') | 515 help='Add an identifier to the front of the version') |
| 488 parser.add_option('-f', '--filters', dest='filters', action='store_true', | 516 parser.add_option('-f', '--filters', dest='filters', action='store_true', |
| 489 default=False, | 517 default=False, |
| 490 help='Turn on filtering of private ebuild packages') | 518 help='Turn on filtering of private ebuild packages') |
| 519 parser.add_option('-k', '--key', dest='key', | |
| 520 default='PORTAGE_BINHOST', | |
| 521 help='Key to update in make.conf / binhost.conf') | |
| 522 parser.add_option('', '--sync-binhost-conf', dest='sync_binhost_conf', | |
| 523 default=False, action='store_true', | |
| 524 help='Update binhost.conf') | |
| 491 | 525 |
| 492 options, args = parser.parse_args() | 526 options, args = parser.parse_args() |
| 493 # Setup boto environment for gsutil to use | 527 # Setup boto environment for gsutil to use |
| 494 os.environ['BOTO_CONFIG'] = _BOTO_CONFIG | 528 os.environ['BOTO_CONFIG'] = _BOTO_CONFIG |
| 495 if not options.build_path: | 529 if not options.build_path: |
| 496 usage(parser, 'Error: you need provide a chroot path') | 530 usage(parser, 'Error: you need provide a chroot path') |
| 497 | 531 |
| 498 if not options.upload: | 532 if not options.upload: |
| 499 usage(parser, 'Error: you need to provide an upload location using -u') | 533 usage(parser, 'Error: you need to provide an upload location using -u') |
| 500 | 534 |
| 501 if options.filters: | 535 if options.filters: |
| 502 # TODO(davidjames): It might be nice to be able to filter private ebuilds | 536 # TODO(davidjames): It might be nice to be able to filter private ebuilds |
| 503 # from rsync uploads as well, some day. But for now it's not needed. | 537 # from rsync uploads as well, some day. But for now it's not needed. |
| 504 if not options.upload.startswith("gs://"): | 538 if not options.upload.startswith("gs://"): |
| 505 usage(parser, 'Error: filtering only works with gs:// paths') | 539 usage(parser, 'Error: filtering only works with gs:// paths') |
| 506 LoadPrivateFilters(options.build_path) | 540 LoadPrivateFilters(options.build_path) |
| 507 | 541 |
| 508 version = GetVersion() | 542 version = GetVersion() |
| 509 if options.prepend_version: | 543 if options.prepend_version: |
| 510 version = '%s-%s' % (options.prepend_version, version) | 544 version = '%s-%s' % (options.prepend_version, version) |
| 511 | 545 |
| 512 if options.sync_host: | 546 if options.sync_host: |
| 513 UploadPrebuilt(options.build_path, options.upload, version, | 547 UploadPrebuilt(options.build_path, options.upload, version, |
| 514 options.binhost_base_url, git_sync=options.git_sync) | 548 options.binhost_base_url, git_sync=options.git_sync, |
| 549 key=options.key, | |
| 550 sync_binhost_conf=options.sync_binhost_conf) | |
| 515 | 551 |
| 516 if options.board: | 552 if options.board: |
| 517 UploadPrebuilt(options.build_path, options.upload, version, | 553 UploadPrebuilt(options.build_path, options.upload, version, |
| 518 options.binhost_base_url, board=options.board, | 554 options.binhost_base_url, board=options.board, |
| 519 git_sync=options.git_sync) | 555 git_sync=options.git_sync, key=options.key, |
| 556 sync_binhost_conf=options.sync_binhost_conf) | |
| 520 | 557 |
| 521 | 558 |
| 522 if __name__ == '__main__': | 559 if __name__ == '__main__': |
| 523 main() | 560 main() |
| OLD | NEW |