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

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 review comments. 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
« no previous file with comments | « 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)
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 make_path = os.path.join(_BINHOST_BASE_DIR, overlay_str, 'make.conf') 401 make_path = os.path.join(_BINHOST_BASE_DIR, overlay_str, 'make.conf')
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
411 def UpdateBinhostConfFile(path, key, value):
412 """Update binhost config file file with key=value.
413
414 Args:
415 path: Filename to update.
416 key: Key to update.
417 value: New value for key.
418 """
419 cwd = os.path.dirname(os.path.abspath(path))
420 filename = os.path.basename(path)
421 if not os.path.isdir(cwd):
422 os.makedirs(cwd)
423 if not os.path.isfile(path):
424 config_file = file(path, 'w')
425 config_file.write('FULL_BINHOST="$PORTAGE_BINHOST"\n')
426 config_file.close()
427 UpdateLocalFile(path, value, key)
428 cros_build_lib.RunCommand('git add %s' % filename, cwd=cwd, shell=True)
429 description = 'Update %s=%s in %s' % (key, value, filename)
430 cros_build_lib.RunCommand('git commit -m "%s"' % description, cwd=cwd,
431 shell=True)
432
433
408 def UploadPrebuilt(build_path, upload_location, version, binhost_base_url, 434 def UploadPrebuilt(build_path, upload_location, version, binhost_base_url,
409 board=None, git_sync=False, git_sync_retries=5): 435 board=None, git_sync=False, git_sync_retries=5,
436 key='PORTAGE_BINHOST', sync_binhost_conf=False):
410 """Upload Host prebuilt files to Google Storage space. 437 """Upload Host prebuilt files to Google Storage space.
411 438
412 Args: 439 Args:
413 build_path: The path to the root of the chroot. 440 build_path: The path to the root of the chroot.
414 upload_location: The upload location. 441 upload_location: The upload location.
415 board: The board to upload to Google Storage, if this is None upload 442 board: The board to upload to Google Storage, if this is None upload
416 host packages. 443 host packages.
417 git_sync: If set, update make.conf of target to reference the latest 444 git_sync: If set, update make.conf of target to reference the latest
418 prebuilt packages genereated here. 445 prebuilt packages generated here.
419 git_sync_retries: How many times to retry pushing when updating git files. 446 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. 447 This helps avoid failures when multiple bots are modifying the same Repo.
421 default: 5 448 default: 5
449 key: The variable key to update in the git file. (Default: PORTAGE_BINHOST)
450 sync_binhost_conf: If set, update binhost config file in chromiumos-overlay
451 for the current board or host.
422 """ 452 """
423 453
424 if not board: 454 if not board:
425 # We are uploading host packages 455 # We are uploading host packages
426 # TODO(scottz): eventually add support for different host_targets 456 # TODO(scottz): eventually add support for different host_targets
427 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH) 457 package_path = os.path.join(build_path, _HOST_PACKAGES_PATH)
428 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET} 458 url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET}
429 package_string = _HOST_TARGET 459 package_string = _HOST_TARGET
430 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET]) 460 git_file = os.path.join(build_path, _PREBUILT_MAKE_CONF[_HOST_TARGET])
461 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'host',
462 '%s.conf' % _HOST_TARGET)
431 else: 463 else:
432 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board}) 464 board_path = os.path.join(build_path, _BOARD_PATH % {'board': board})
433 package_path = os.path.join(board_path, 'packages') 465 package_path = os.path.join(board_path, 'packages')
434 package_string = board 466 package_string = board
435 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version} 467 url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version}
436 git_file = os.path.join(build_path, DetermineMakeConfFile(board)) 468 git_file = os.path.join(build_path, DetermineMakeConfFile(board))
469 binhost_conf = os.path.join(build_path, _BINHOST_CONF_DIR, 'target',
470 '%s.conf' % board)
437 remote_location = os.path.join(upload_location, url_suffix) 471 remote_location = os.path.join(upload_location, url_suffix)
438 472
439 if upload_location.startswith('gs://'): 473 if upload_location.startswith('gs://'):
440 upload_files = GenerateUploadDict(package_path, remote_location) 474 upload_files = GenerateUploadDict(package_path, remote_location)
441 475
442 print 'Uploading %s' % package_string 476 print 'Uploading %s' % package_string
443 failed_uploads = RemoteUpload(upload_files) 477 failed_uploads = RemoteUpload(upload_files)
444 if len(failed_uploads) > 1 or (None not in failed_uploads): 478 if len(failed_uploads) > 1 or (None not in failed_uploads):
445 error_msg = ['%s -> %s\n' % args for args in failed_uploads] 479 error_msg = ['%s -> %s\n' % args for args in failed_uploads]
446 raise UploadFailed('Error uploading:\n%s' % error_msg) 480 raise UploadFailed('Error uploading:\n%s' % error_msg)
447 else: 481 else:
448 ssh_server, remote_path = remote_location.split(':', 1) 482 ssh_server, remote_path = remote_location.split(':', 1)
449 cmds = ['ssh %s mkdir -p %s' % (ssh_server, remote_path), 483 cmds = ['ssh %s mkdir -p %s' % (ssh_server, remote_path),
450 'rsync -av %s/ %s/' % (package_path, remote_location)] 484 'rsync -av %s/ %s/' % (package_path, remote_location)]
451 for cmd in cmds: 485 for cmd in cmds:
452 if not _RetryRun(cmd, shell=True): 486 if not _RetryRun(cmd, shell=True):
453 raise UploadFailed('Could not run %s' % cmd) 487 raise UploadFailed('Could not run %s' % cmd)
454 488
489 url_value = '%s/%s/' % (binhost_base_url, url_suffix)
490
455 if git_sync: 491 if git_sync:
456 url_value = '%s/%s/' % (binhost_base_url, url_suffix) 492 RevGitFile(git_file, url_value, retries=git_sync_retries, key=key)
457 RevGitFile(git_file, url_value, retries=git_sync_retries)
458 493
494 if sync_binhost_conf:
495 UpdateBinhostConfFile(binhost_conf, key, url_value)
459 496
460 def usage(parser, msg): 497 def usage(parser, msg):
461 """Display usage message and parser help then exit with 1.""" 498 """Display usage message and parser help then exit with 1."""
462 print >> sys.stderr, msg 499 print >> sys.stderr, msg
463 parser.print_help() 500 parser.print_help()
464 sys.exit(1) 501 sys.exit(1)
465 502
466 503
467 def main(): 504 def main():
468 parser = optparse.OptionParser() 505 parser = optparse.OptionParser()
(...skipping 12 matching lines...) Expand all
481 help='Enable git version sync (This commits to a repo)') 518 help='Enable git version sync (This commits to a repo)')
482 parser.add_option('-u', '--upload', dest='upload', 519 parser.add_option('-u', '--upload', dest='upload',
483 default=None, 520 default=None,
484 help='Upload location') 521 help='Upload location')
485 parser.add_option('-V', '--prepend-version', dest='prepend_version', 522 parser.add_option('-V', '--prepend-version', dest='prepend_version',
486 default=None, 523 default=None,
487 help='Add an identifier to the front of the version') 524 help='Add an identifier to the front of the version')
488 parser.add_option('-f', '--filters', dest='filters', action='store_true', 525 parser.add_option('-f', '--filters', dest='filters', action='store_true',
489 default=False, 526 default=False,
490 help='Turn on filtering of private ebuild packages') 527 help='Turn on filtering of private ebuild packages')
528 parser.add_option('-k', '--key', dest='key',
529 default='PORTAGE_BINHOST',
530 help='Key to update in make.conf / binhost.conf')
531 parser.add_option('', '--sync-binhost-conf', dest='sync_binhost_conf',
532 default=False, action='store_true',
533 help='Update binhost.conf')
491 534
492 options, args = parser.parse_args() 535 options, args = parser.parse_args()
493 # Setup boto environment for gsutil to use 536 # Setup boto environment for gsutil to use
494 os.environ['BOTO_CONFIG'] = _BOTO_CONFIG 537 os.environ['BOTO_CONFIG'] = _BOTO_CONFIG
495 if not options.build_path: 538 if not options.build_path:
496 usage(parser, 'Error: you need provide a chroot path') 539 usage(parser, 'Error: you need provide a chroot path')
497 540
498 if not options.upload: 541 if not options.upload:
499 usage(parser, 'Error: you need to provide an upload location using -u') 542 usage(parser, 'Error: you need to provide an upload location using -u')
500 543
501 if options.filters: 544 if options.filters:
502 # TODO(davidjames): It might be nice to be able to filter private ebuilds 545 # 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. 546 # from rsync uploads as well, some day. But for now it's not needed.
504 if not options.upload.startswith("gs://"): 547 if not options.upload.startswith("gs://"):
505 usage(parser, 'Error: filtering only works with gs:// paths') 548 usage(parser, 'Error: filtering only works with gs:// paths')
506 LoadPrivateFilters(options.build_path) 549 LoadPrivateFilters(options.build_path)
507 550
508 version = GetVersion() 551 version = GetVersion()
509 if options.prepend_version: 552 if options.prepend_version:
510 version = '%s-%s' % (options.prepend_version, version) 553 version = '%s-%s' % (options.prepend_version, version)
511 554
512 if options.sync_host: 555 if options.sync_host:
513 UploadPrebuilt(options.build_path, options.upload, version, 556 UploadPrebuilt(options.build_path, options.upload, version,
514 options.binhost_base_url, git_sync=options.git_sync) 557 options.binhost_base_url, git_sync=options.git_sync,
558 key=options.key,
559 sync_binhost_conf=options.sync_binhost_conf)
515 560
516 if options.board: 561 if options.board:
517 UploadPrebuilt(options.build_path, options.upload, version, 562 UploadPrebuilt(options.build_path, options.upload, version,
518 options.binhost_base_url, board=options.board, 563 options.binhost_base_url, board=options.board,
519 git_sync=options.git_sync) 564 git_sync=options.git_sync, key=options.key,
565 sync_binhost_conf=options.sync_binhost_conf)
520 566
521 567
522 if __name__ == '__main__': 568 if __name__ == '__main__':
523 main() 569 main()
OLDNEW
« no previous file with comments | « bin/cbuildbot_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698