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

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: Address comments by dianders Created 10 years 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_unittest.py ('K') | « bin/cbuildbot_unittest.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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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'
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
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)
sosa 2010/11/23 23:56:21 Only indent by 2 here (see above)
davidjames 2010/11/24 00:29:23 Done.
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
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)
sosa 2010/11/23 23:56:21 sync_binhost_conf?
422 """ 427 """
423 428
424 if not board: 429 if not board:
425 # We are uploading host packages 430 # We are uploading host packages
426 # TODO(scottz): eventually add support for different host_targets 431 # TODO(scottz): eventually add support for different host_targets
427 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH) 432 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH)
428 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET} 433 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET}
429 package_string = _HOST_TARGET 434 package_string = _HOST_TARGET
430 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET]) 435 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET])
436 binhost_conf = os.path.join(build_path,
437 '%s/host/%s.conf' % (_BINHOST_CONF_DIR, _HOST_TARGET))
431 else: 438 else:
432 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board}) 439 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board})
433 package_path = os.path.join(board_path, 'packages') 440 package_path = os.path.join(board_path, 'packages')
434 package_string = board 441 package_string = board
435 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version} 442 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version}
436 git_file = os.path.join(build_path, DetermineMakeConfFile(board)) 443 git_file = os.path.join(build_path, DetermineMakeConfFile(board))
444 binhost_conf = os.path.join(build_path,
445 '%s/target/%s.conf' % (_BINHOST_CONF_DIR, board))
437 remote_location = os.path.join(upload_location, url_suffix) 446 remote_location = os.path.join(upload_location, url_suffix)
438 447
439 if upload_location.startswith('gs://'): 448 if upload_location.startswith('gs://'):
440 upload_files = GenerateUploadDict(package_path, remote_location) 449 upload_files = GenerateUploadDict(package_path, remote_location)
441 450
442 print 'Uploading %s' % package_string 451 print 'Uploading %s' % package_string
443 failed_uploads = RemoteUpload(upload_files) 452 failed_uploads = RemoteUpload(upload_files)
444 if len(failed_uploads) > 1 or (None not in failed_uploads): 453 if len(failed_uploads) > 1 or (None not in failed_uploads):
445 error_msg = ['%s -> %s\n' % args for args in failed_uploads] 454 error_msg = ['%s -> %s\n' % args for args in failed_uploads]
446 raise UploadFailed('Error uploading:\n%s' % error_msg) 455 raise UploadFailed('Error uploading:\n%s' % error_msg)
447 else: 456 else:
448 ssh_server, remote_path = remote_location.split(':', 1) 457 ssh_server, remote_path = remote_location.split(':', 1)
449 cmds = ['ssh %s mkdir -p %s' % (ssh_server, remote_path), 458 cmds = ['ssh %s mkdir -p %s' % (ssh_server, remote_path),
450 'rsync -av %s/ %s/' % (package_path, remote_location)] 459 'rsync -av %s/ %s/' % (package_path, remote_location)]
451 for cmd in cmds: 460 for cmd in cmds:
452 if not _RetryRun(cmd, shell=True): 461 if not _RetryRun(cmd, shell=True):
453 raise UploadFailed('Could not run %s' % cmd) 462 raise UploadFailed('Could not run %s' % cmd)
454 463
464 url_value = '%s/%s/' % (binhost_base_url, url_suffix)
465
455 if git_sync: 466 if git_sync:
456 url_value = '%s/%s/' % (binhost_base_url, url_suffix) 467 RevGitFile(git_file, url_value, retries=git_sync_retries, key=key)
457 RevGitFile(git_file, url_value, retries=git_sync_retries) 468
469 if sync_binhost_conf:
470 binhost_dir = os.path.dirname(os.path.abspath(binhost_conf))
471 binhost_filename = os.path.basename(binhost_conf)
472 if not os.path.isdir(binhost_dir):
473 os.makedirs(binhost_dir)
474 if not os.path.isfile(binhost_conf):
475 f = file(binhost_conf, 'w')
476 f.write('FULL_BINHOST="$PORTAGE_BINHOST"\n')
477 f.close()
478 UpdateLocalFile(binhost_conf, url_value, key)
479 cros_build_lib.RunCommand('git add %s' % binhost_filename, cwd=binhost_dir,
480 shell=True)
481 description = 'Update %s=%s in %s' % (key, url_value, binhost_filename)
482 cros_build_lib.RunCommand('git commit -m "%s"' % description,
483 cwd=binhost_dir, shell=True)
458 484
459 485
460 def usage(parser, msg): 486 def usage(parser, msg):
461 """Display usage message and parser help then exit with 1.""" 487 """Display usage message and parser help then exit with 1."""
462 print >> sys.stderr, msg 488 print >> sys.stderr, msg
463 parser.print_help() 489 parser.print_help()
464 sys.exit(1) 490 sys.exit(1)
465 491
466 492
467 def main(): 493 def main():
(...skipping 13 matching lines...) Expand all
481 help='Enable git version sync (This commits to a repo)') 507 help='Enable git version sync (This commits to a repo)')
482 parser.add_option('-u', '--upload', dest='upload', 508 parser.add_option('-u', '--upload', dest='upload',
483 default=None, 509 default=None,
484 help='Upload location') 510 help='Upload location')
485 parser.add_option('-V', '--prepend-version', dest='prepend_version', 511 parser.add_option('-V', '--prepend-version', dest='prepend_version',
486 default=None, 512 default=None,
487 help='Add an identifier to the front of the version') 513 help='Add an identifier to the front of the version')
488 parser.add_option('-f', '--filters', dest='filters', action='store_true', 514 parser.add_option('-f', '--filters', dest='filters', action='store_true',
489 default=False, 515 default=False,
490 help='Turn on filtering of private ebuild packages') 516 help='Turn on filtering of private ebuild packages')
517 parser.add_option('-k', '--key', dest='key',
518 default='PORTAGE_BINHOST',
519 help='Key to update in make.conf / binhost.conf')
520 parser.add_option('', '--sync-binhost-conf', dest='sync_binhost_conf',
521 default=False, action='store_true',
522 help='Update binhost.conf')
491 523
492 options, args = parser.parse_args() 524 options, args = parser.parse_args()
493 # Setup boto environment for gsutil to use 525 # Setup boto environment for gsutil to use
494 os.environ['BOTO_CONFIG'] = _BOTO_CONFIG 526 os.environ['BOTO_CONFIG'] = _BOTO_CONFIG
495 if not options.build_path: 527 if not options.build_path:
496 usage(parser, 'Error: you need provide a chroot path') 528 usage(parser, 'Error: you need provide a chroot path')
497 529
498 if not options.upload: 530 if not options.upload:
499 usage(parser, 'Error: you need to provide an upload location using -u') 531 usage(parser, 'Error: you need to provide an upload location using -u')
500 532
501 if options.filters: 533 if options.filters:
502 # TODO(davidjames): It might be nice to be able to filter private ebuilds 534 # 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. 535 # from rsync uploads as well, some day. But for now it's not needed.
504 if not options.upload.startswith("gs://"): 536 if not options.upload.startswith("gs://"):
505 usage(parser, 'Error: filtering only works with gs:// paths') 537 usage(parser, 'Error: filtering only works with gs:// paths')
506 LoadPrivateFilters(options.build_path) 538 LoadPrivateFilters(options.build_path)
507 539
508 version = GetVersion() 540 version = GetVersion()
509 if options.prepend_version: 541 if options.prepend_version:
510 version = '%s-%s' % (options.prepend_version, version) 542 version = '%s-%s' % (options.prepend_version, version)
511 543
512 if options.sync_host: 544 if options.sync_host:
513 UploadPrebuilt(options.build_path, options.upload, version, 545 UploadPrebuilt(options.build_path, options.upload, version,
514 options.binhost_base_url, git_sync=options.git_sync) 546 options.binhost_base_url, git_sync=options.git_sync,
547 key=options.key,
548 sync_binhost_conf=options.sync_binhost_conf)
515 549
516 if options.board: 550 if options.board:
517 UploadPrebuilt(options.build_path, options.upload, version, 551 UploadPrebuilt(options.build_path, options.upload, version,
518 options.binhost_base_url, board=options.board, 552 options.binhost_base_url, board=options.board,
519 git_sync=options.git_sync) 553 git_sync=options.git_sync, key=options.key,
554 sync_binhost_conf=options.sync_binhost_conf)
520 555
521 556
522 if __name__ == '__main__': 557 if __name__ == '__main__':
523 main() 558 main()
OLDNEW
« bin/cbuildbot_unittest.py ('K') | « bin/cbuildbot_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698