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

Side by Side Diff: prebuilt.py

Issue 4969003: Update cbuildbot.py to upload prebuilts from preflight buildbot. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Created 10 years, 1 month 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
« bin/cbuildbot.py ('K') | « bin/cbuildbot.py ('k') | no next file » | 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 file_lines.append(keyval_str % {'key': key, 'value': value}) 110 file_lines.append(keyval_str % {'key': key, 'value': value})
111 else: 111 else:
112 file_lines.append(keyval_str % {'key': file_var, 'value': file_val}) 112 file_lines.append(keyval_str % {'key': file_var, 'value': file_val})
113 113
114 if not found: 114 if not found:
115 file_lines.append(keyval_str % {'key': key, 'value': value}) 115 file_lines.append(keyval_str % {'key': key, 'value': value})
116 116
117 file_fh.close() 117 file_fh.close()
118 # write out new file 118 # write out new file
119 new_file_fh = open(filename, 'w') 119 new_file_fh = open(filename, 'w')
120 new_file_fh.write('\n'.join(file_lines)) 120 new_file_fh.write('\n'.join(file_lines) + '\n')
121 new_file_fh.close() 121 new_file_fh.close()
122 122
123 123
124 def RevGitPushWithRetry(retries=5): 124 def RevGitPushWithRetry(retries=5):
125 """Repo sync and then push git changes in flight. 125 """Repo sync and then push git changes in flight.
126 126
127 Args: 127 Args:
128 retries: The number of times to retry before giving up, default: 5 128 retries: The number of times to retry before giving up, default: 5
129 129
130 Raises: 130 Raises:
131 GitPushFailed if push was unsuccessful after retries 131 GitPushFailed if push was unsuccessful after retries
132 """ 132 """
133 for retry in range(1, retries+1): 133 for retry in range(1, retries+1):
134 try: 134 try:
135 cros_build_lib.RunCommand('repo sync .', shell=True) 135 cros_build_lib.RunCommand('repo sync .', shell=True)
136 cros_build_lib.RunCommand('git push', shell=True) 136 cros_build_lib.RunCommand('git push', shell=True)
137 break 137 break
138 except cros_build_lib.RunCommandError: 138 except cros_build_lib.RunCommandError:
139 if retry < retries: 139 if retry < retries:
140 print 'Error pushing changes trying again (%s/%s)' % (retry, retries) 140 print 'Error pushing changes trying again (%s/%s)' % (retry, retries)
141 time.sleep(5*retry) 141 time.sleep(5*retry)
142 else: 142 else:
143 raise GitPushFailed('Failed to push change after %s retries' % retries) 143 raise GitPushFailed('Failed to push change after %s retries' % retries)
144 144
145 145
146 def RevGitFile(filename, value, retries=5): 146 def RevGitFile(filename, value, retries=5, key='PORTAGE_BINHOST'):
147 """Update and push the git file. 147 """Update and push the git file.
148 148
149 Args: 149 Args:
150 filename: file to modify that is in a git repo already 150 filename: file to modify that is in a git repo already
151 value: string representing the version of the prebuilt that has been 151 value: string representing the version of the prebuilt that has been
152 uploaded. 152 uploaded.
153 retries: The number of times to retry before giving up, default: 5 153 retries: The number of times to retry before giving up, default: 5
154 key: The variable key to update in the git file.
155 (Default: PORTAGE_BINHOST)
154 """ 156 """
155 prebuilt_branch = 'prebuilt_branch' 157 prebuilt_branch = 'prebuilt_branch'
156 old_cwd = os.getcwd() 158 old_cwd = os.getcwd()
157 os.chdir(os.path.dirname(filename)) 159 os.chdir(os.path.dirname(filename))
158 160
159 cros_build_lib.RunCommand('repo sync .', shell=True) 161 cros_build_lib.RunCommand('repo sync .', shell=True)
160 cros_build_lib.RunCommand('repo start %s .' % prebuilt_branch, shell=True) 162 cros_build_lib.RunCommand('repo start %s .' % prebuilt_branch, shell=True)
161 git_ssh_config_cmd = ( 163 git_ssh_config_cmd = (
162 'git config url.ssh://git@gitrw.chromium.org:9222.pushinsteadof ' 164 'git config url.ssh://git@gitrw.chromium.org:9222.pushinsteadof '
163 'http://git.chromium.org/git') 165 'http://git.chromium.org/git')
164 cros_build_lib.RunCommand(git_ssh_config_cmd, shell=True) 166 cros_build_lib.RunCommand(git_ssh_config_cmd, shell=True)
165 description = 'Update PORTAGE_BINHOST="%s" in %s' % (value, filename) 167 description = 'Update %s="%s" in %s' % (key, value, filename)
166 print description 168 print description
167 try: 169 try:
168 UpdateLocalFile(filename, value) 170 UpdateLocalFile(filename, value, key)
169 cros_build_lib.RunCommand('git config push.default tracking', shell=True) 171 cros_build_lib.RunCommand('git config push.default tracking', shell=True)
170 cros_build_lib.RunCommand('git commit -am "%s"' % description, shell=True) 172 cros_build_lib.RunCommand('git commit -am "%s"' % description, shell=True)
171 RevGitPushWithRetry(retries) 173 RevGitPushWithRetry(retries)
172 finally: 174 finally:
173 cros_build_lib.RunCommand('repo abandon %s .' % prebuilt_branch, shell=True) 175 cros_build_lib.RunCommand('repo abandon %s .' % prebuilt_branch, shell=True)
174 os.chdir(old_cwd) 176 os.chdir(old_cwd)
175 177
176 178
177 def GetVersion(): 179 def GetVersion():
178 """Get the version to put in LATEST and update the git version with.""" 180 """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
399 elif re.match('.*?-\w+', target): 401 elif re.match('.*?-\w+', target):
400 overlay_str = 'overlay-%s' % target 402 overlay_str = 'overlay-%s' % target
401 make_path = os.path.join(_BINHOST_BASE_DIR, overlay_str, 'make.conf') 403 make_path = os.path.join(_BINHOST_BASE_DIR, overlay_str, 'make.conf')
402 else: 404 else:
403 raise UnknownBoardFormat('Unknown format: %s' % target) 405 raise UnknownBoardFormat('Unknown format: %s' % target)
404 406
405 return os.path.join(make_path) 407 return os.path.join(make_path)
406 408
407 409
408 def UploadPrebuilt(build_path, upload_location, version, binhost_base_url, 410 def UploadPrebuilt(build_path, upload_location, version, binhost_base_url,
409 board=None, git_sync=False, git_sync_retries=5): 411 board=None, git_sync=False, git_sync_retries=5,
412 key='PORTAGE_BINHOST'):
410 """Upload Host prebuilt files to Google Storage space. 413 """Upload Host prebuilt files to Google Storage space.
411 414
412 Args: 415 Args:
413 build_path: The path to the root of the chroot. 416 build_path: The path to the root of the chroot.
414 upload_location: The upload location. 417 upload_location: The upload location.
415 board: The board to upload to Google Storage, if this is None upload 418 board: The board to upload to Google Storage, if this is None upload
416 host packages. 419 host packages.
417 git_sync: If set, update make.conf of target to reference the latest 420 git_sync: If set, update make.conf of target to reference the latest
418 prebuilt packages genereated here. 421 prebuilt packages generated here.
419 git_sync_retries: How many times to retry pushing when updating git files. 422 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. 423 This helps avoid failures when multiple bots are modifying the same Repo.
421 default: 5 424 default: 5
425 key: The variable key to update in the git file. (Default: PORTAGE_BINHOST)
422 """ 426 """
423 427
424 if not board: 428 if not board:
425 # We are uploading host packages 429 # We are uploading host packages
426 # TODO(scottz): eventually add support for different host_targets 430 # TODO(scottz): eventually add support for different host_targets
427 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH) 431 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH)
428 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET} 432 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET}
429 package_string = _HOST_TARGET 433 package_string = _HOST_TARGET
430 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET]) 434 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET])
431 else: 435 else:
(...skipping 15 matching lines...) Expand all
447 else: 451 else:
448 ssh_server, remote_path = remote_location.split(':', 1) 452 ssh_server, remote_path = remote_location.split(':', 1)
449 cmds = ['ssh %s mkdir -p %s' % (ssh_server, remote_path), 453 cmds = ['ssh %s mkdir -p %s' % (ssh_server, remote_path),
450 'rsync -av %s/ %s/' % (package_path, remote_location)] 454 'rsync -av %s/ %s/' % (package_path, remote_location)]
451 for cmd in cmds: 455 for cmd in cmds:
452 if not _RetryRun(cmd, shell=True): 456 if not _RetryRun(cmd, shell=True):
453 raise UploadFailed('Could not run %s' % cmd) 457 raise UploadFailed('Could not run %s' % cmd)
454 458
455 if git_sync: 459 if git_sync:
456 url_value = '%s/%s/' % (binhost_base_url, url_suffix) 460 url_value = '%s/%s/' % (binhost_base_url, url_suffix)
457 RevGitFile(git_file, url_value, retries=git_sync_retries) 461 RevGitFile(git_file, url_value, retries=git_sync_retries, key=key)
458 462
459 463
460 def usage(parser, msg): 464 def usage(parser, msg):
461 """Display usage message and parser help then exit with 1.""" 465 """Display usage message and parser help then exit with 1."""
462 print >> sys.stderr, msg 466 print >> sys.stderr, msg
463 parser.print_help() 467 parser.print_help()
464 sys.exit(1) 468 sys.exit(1)
465 469
466 470
467 def main(): 471 def main():
(...skipping 13 matching lines...) Expand all
481 help='Enable git version sync (This commits to a repo)') 485 help='Enable git version sync (This commits to a repo)')
482 parser.add_option('-u', '--upload', dest='upload', 486 parser.add_option('-u', '--upload', dest='upload',
483 default=None, 487 default=None,
484 help='Upload location') 488 help='Upload location')
485 parser.add_option('-V', '--prepend-version', dest='prepend_version', 489 parser.add_option('-V', '--prepend-version', dest='prepend_version',
486 default=None, 490 default=None,
487 help='Add an identifier to the front of the version') 491 help='Add an identifier to the front of the version')
488 parser.add_option('-f', '--filters', dest='filters', action='store_true', 492 parser.add_option('-f', '--filters', dest='filters', action='store_true',
489 default=False, 493 default=False,
490 help='Turn on filtering of private ebuild packages') 494 help='Turn on filtering of private ebuild packages')
495 parser.add_option('-k', '--key', dest='key',
496 default='PORTAGE_BINHOST',
497 help='Key to update in make.conf')
491 498
492 options, args = parser.parse_args() 499 options, args = parser.parse_args()
493 # Setup boto environment for gsutil to use 500 # Setup boto environment for gsutil to use
494 os.environ['BOTO_CONFIG'] = _BOTO_CONFIG 501 os.environ['BOTO_CONFIG'] = _BOTO_CONFIG
495 if not options.build_path: 502 if not options.build_path:
496 usage(parser, 'Error: you need provide a chroot path') 503 usage(parser, 'Error: you need provide a chroot path')
497 504
498 if not options.upload: 505 if not options.upload:
499 usage(parser, 'Error: you need to provide an upload location using -u') 506 usage(parser, 'Error: you need to provide an upload location using -u')
500 507
501 if options.filters: 508 if options.filters:
502 # TODO(davidjames): It might be nice to be able to filter private ebuilds 509 # 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. 510 # from rsync uploads as well, some day. But for now it's not needed.
504 if not options.upload.startswith("gs://"): 511 if not options.upload.startswith("gs://"):
505 usage(parser, 'Error: filtering only works with gs:// paths') 512 usage(parser, 'Error: filtering only works with gs:// paths')
506 LoadPrivateFilters(options.build_path) 513 LoadPrivateFilters(options.build_path)
507 514
508 version = GetVersion() 515 version = GetVersion()
509 if options.prepend_version: 516 if options.prepend_version:
510 version = '%s-%s' % (options.prepend_version, version) 517 version = '%s-%s' % (options.prepend_version, version)
511 518
512 if options.sync_host: 519 if options.sync_host:
513 UploadPrebuilt(options.build_path, options.upload, version, 520 UploadPrebuilt(options.build_path, options.upload, version,
514 options.binhost_base_url, git_sync=options.git_sync) 521 options.binhost_base_url, git_sync=options.git_sync,
522 key=options.key)
515 523
516 if options.board: 524 if options.board:
517 UploadPrebuilt(options.build_path, options.upload, version, 525 UploadPrebuilt(options.build_path, options.upload, version,
518 options.binhost_base_url, board=options.board, 526 options.binhost_base_url, board=options.board,
519 git_sync=options.git_sync) 527 git_sync=options.git_sync, key=options.key)
520 528
521 529
522 if __name__ == '__main__': 530 if __name__ == '__main__':
523 main() 531 main()
OLDNEW
« bin/cbuildbot.py ('K') | « bin/cbuildbot.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698