David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 2 | # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import datetime |
| 7 | import multiprocessing |
| 8 | import optparse |
| 9 | import os |
| 10 | import re |
| 11 | import sys |
| 12 | import tempfile |
| 13 | import time |
| 14 | |
Chris Sosa | 471532a | 2011-02-01 15:10:06 -0800 | [diff] [blame] | 15 | if __name__ == '__main__': |
| 16 | import constants |
| 17 | sys.path.append(constants.SOURCE_ROOT) |
| 18 | |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 19 | from chromite.lib import cros_build_lib |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 20 | from chromite.lib.binpkg import (GrabLocalPackageIndex, GrabRemotePackageIndex) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 21 | """ |
| 22 | This script is used to upload host prebuilts as well as board BINHOSTS. |
| 23 | |
| 24 | If the URL starts with 'gs://', we upload using gsutil to Google Storage. |
| 25 | Otherwise, rsync is used. |
| 26 | |
| 27 | After a build is successfully uploaded a file is updated with the proper |
| 28 | BINHOST version as well as the target board. This file is defined in GIT_FILE |
| 29 | |
| 30 | |
| 31 | To read more about prebuilts/binhost binary packages please refer to: |
| 32 | http://sites/chromeos/for-team-members/engineering/releng/prebuilt-binaries-for-streamlining-the-build-process |
| 33 | |
| 34 | |
| 35 | Example of uploading prebuilt amd64 host files to Google Storage: |
| 36 | ./prebuilt.py -p /b/cbuild/build -s -u gs://chromeos-prebuilt |
| 37 | |
| 38 | Example of uploading x86-dogfood binhosts to Google Storage: |
| 39 | ./prebuilt.py -b x86-dogfood -p /b/cbuild/build/ -u gs://chromeos-prebuilt -g |
| 40 | |
| 41 | Example of uploading prebuilt amd64 host files using rsync: |
| 42 | ./prebuilt.py -p /b/cbuild/build -s -u codf30.jail:/tmp |
| 43 | """ |
| 44 | |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 45 | _RETRIES = 3 |
| 46 | _GSUTIL_BIN = '/b/build/third_party/gsutil/gsutil' |
| 47 | _HOST_PACKAGES_PATH = 'chroot/var/lib/portage/pkgs' |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 48 | _CATEGORIES_PATH = 'chroot/etc/portage/categories' |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 49 | _PYM_PATH = 'chroot/usr/lib/portage/pym' |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 50 | _HOST_TARGET = 'amd64' |
| 51 | _BOARD_PATH = 'chroot/build/%(board)s' |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 52 | # board/board-target/version/' |
| 53 | _REL_BOARD_PATH = 'board/%(board)s/%(version)s' |
| 54 | # host/host-target/version/' |
| 55 | _REL_HOST_PATH = 'host/%(target)s/%(version)s' |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 56 | # Private overlays to look at for builds to filter |
| 57 | # relative to build path |
| 58 | _PRIVATE_OVERLAY_DIR = 'src/private-overlays' |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 59 | _GOOGLESTORAGE_ACL_FILE = 'googlestorage_acl.xml' |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 60 | _BINHOST_BASE_URL = 'http://commondatastorage.googleapis.com/chromeos-prebuilt' |
| 61 | _PREBUILT_BASE_DIR = 'src/third_party/chromiumos-overlay/chromeos/config/' |
| 62 | # Created in the event of new host targets becoming available |
| 63 | _PREBUILT_MAKE_CONF = {'amd64': os.path.join(_PREBUILT_BASE_DIR, |
| 64 | 'make.conf.amd64-host')} |
| 65 | _BINHOST_CONF_DIR = 'src/third_party/chromiumos-overlay/chromeos/binhost' |
| 66 | |
| 67 | |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 68 | class UploadFailed(Exception): |
| 69 | """Raised when one of the files uploaded failed.""" |
| 70 | pass |
| 71 | |
| 72 | class UnknownBoardFormat(Exception): |
| 73 | """Raised when a function finds an unknown board format.""" |
| 74 | pass |
| 75 | |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 76 | |
| 77 | def UpdateLocalFile(filename, value, key='PORTAGE_BINHOST'): |
| 78 | """Update the key in file with the value passed. |
| 79 | File format: |
| 80 | key="value" |
| 81 | Note quotes are added automatically |
| 82 | |
| 83 | Args: |
| 84 | filename: Name of file to modify. |
| 85 | value: Value to write with the key. |
| 86 | key: The variable key to update. (Default: PORTAGE_BINHOST) |
| 87 | """ |
| 88 | if os.path.exists(filename): |
| 89 | file_fh = open(filename) |
| 90 | else: |
| 91 | file_fh = open(filename, 'w+') |
| 92 | file_lines = [] |
| 93 | found = False |
| 94 | keyval_str = '%(key)s=%(value)s' |
| 95 | for line in file_fh: |
| 96 | # Strip newlines from end of line. We already add newlines below. |
| 97 | line = line.rstrip("\n") |
| 98 | |
| 99 | if len(line.split('=')) != 2: |
| 100 | # Skip any line that doesn't fit key=val. |
| 101 | file_lines.append(line) |
| 102 | continue |
| 103 | |
| 104 | file_var, file_val = line.split('=') |
| 105 | if file_var == key: |
| 106 | found = True |
| 107 | print 'Updating %s=%s to %s="%s"' % (file_var, file_val, key, value) |
| 108 | value = '"%s"' % value |
| 109 | file_lines.append(keyval_str % {'key': key, 'value': value}) |
| 110 | else: |
| 111 | file_lines.append(keyval_str % {'key': file_var, 'value': file_val}) |
| 112 | |
| 113 | if not found: |
| 114 | file_lines.append(keyval_str % {'key': key, 'value': value}) |
| 115 | |
| 116 | file_fh.close() |
| 117 | # write out new file |
| 118 | new_file_fh = open(filename, 'w') |
| 119 | new_file_fh.write('\n'.join(file_lines) + '\n') |
| 120 | new_file_fh.close() |
| 121 | |
| 122 | |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 123 | def RevGitFile(filename, value, retries=5, key='PORTAGE_BINHOST'): |
| 124 | """Update and push the git file. |
| 125 | |
| 126 | Args: |
| 127 | filename: file to modify that is in a git repo already |
| 128 | value: string representing the version of the prebuilt that has been |
| 129 | uploaded. |
| 130 | retries: The number of times to retry before giving up, default: 5 |
| 131 | key: The variable key to update in the git file. |
| 132 | (Default: PORTAGE_BINHOST) |
| 133 | """ |
| 134 | prebuilt_branch = 'prebuilt_branch' |
David James | 1b6e67a | 2011-05-19 21:32:38 -0700 | [diff] [blame] | 135 | cwd = os.path.abspath(os.path.dirname(filename)) |
| 136 | commit = cros_build_lib.RunCommand(['git', 'rev-parse', 'HEAD'], cwd=cwd, |
Peter Mayo | fe0e687 | 2011-04-20 00:52:08 -0400 | [diff] [blame] | 137 | redirect_stdout=True).output.rstrip() |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 138 | git_ssh_config_cmd = [ |
| 139 | 'git', |
| 140 | 'config', |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 141 | 'url.ssh://gerrit.chromium.org:29418.pushinsteadof', |
David James | 1b6e67a | 2011-05-19 21:32:38 -0700 | [diff] [blame] | 142 | 'http://git.chromium.org'] |
| 143 | cros_build_lib.RunCommand(git_ssh_config_cmd, cwd=cwd) |
| 144 | cros_build_lib.RunCommand(['git', 'remote', 'update'], cwd=cwd) |
| 145 | cros_build_lib.RunCommand(['repo', 'start', prebuilt_branch, '.'], cwd=cwd) |
David James | 6181b89 | 2011-06-08 16:45:07 -0700 | [diff] [blame] | 146 | |
| 147 | # We want to push our changes to this file to tip of tree, so we should |
| 148 | # make sure the branch is at tip of tree before we apply our change. |
| 149 | push_branch = '%s/%s' % cros_build_lib.GetPushBranch(prebuilt_branch, cwd) |
| 150 | cros_build_lib.RunCommand(['git', 'reset', '--hard', push_branch], cwd=cwd) |
| 151 | |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 152 | description = 'Update %s="%s" in %s' % (key, value, filename) |
| 153 | print description |
| 154 | try: |
| 155 | UpdateLocalFile(filename, value, key) |
David James | 1b6e67a | 2011-05-19 21:32:38 -0700 | [diff] [blame] | 156 | cros_build_lib.RunCommand(['git', 'config', 'push.default', 'tracking'], |
| 157 | cwd=cwd) |
| 158 | cros_build_lib.RunCommand(['git', 'add', filename], cwd=cwd) |
| 159 | cros_build_lib.RunCommand(['git', 'commit', '-m', description], cwd=cwd) |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 160 | cros_build_lib.GitPushWithRetry(prebuilt_branch, cwd=cwd) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 161 | finally: |
David James | 1b6e67a | 2011-05-19 21:32:38 -0700 | [diff] [blame] | 162 | cros_build_lib.RunCommand(['git', 'checkout', commit], cwd=cwd) |
| 163 | cros_build_lib.RunCommand(['repo', 'abandon', 'prebuilt_branch', '.'], |
| 164 | cwd=cwd) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 165 | |
| 166 | |
| 167 | def GetVersion(): |
| 168 | """Get the version to put in LATEST and update the git version with.""" |
| 169 | return datetime.datetime.now().strftime('%d.%m.%y.%H%M%S') |
| 170 | |
| 171 | |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 172 | def _RetryRun(cmd, print_cmd=True, cwd=None): |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 173 | """Run the specified command, retrying if necessary. |
| 174 | |
| 175 | Args: |
| 176 | cmd: The command to run. |
| 177 | print_cmd: Whether to print out the cmd. |
| 178 | shell: Whether to treat the command as a shell. |
| 179 | cwd: Working directory to run command in. |
| 180 | |
| 181 | Returns: |
| 182 | True if the command succeeded. Otherwise, returns False. |
| 183 | """ |
| 184 | |
| 185 | # TODO(scottz): port to use _Run or similar when it is available in |
| 186 | # cros_build_lib. |
| 187 | for attempt in range(_RETRIES): |
| 188 | try: |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 189 | output = cros_build_lib.RunCommand(cmd, print_cmd=print_cmd, |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 190 | cwd=cwd) |
| 191 | return True |
| 192 | except cros_build_lib.RunCommandError: |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 193 | print 'Failed to run %r' % cmd |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 194 | else: |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 195 | print 'Retry failed run %r, giving up' % cmd |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 196 | return False |
| 197 | |
| 198 | |
| 199 | def _GsUpload(args): |
| 200 | """Upload to GS bucket. |
| 201 | |
| 202 | Args: |
David James | fd0b085 | 2011-02-23 11:15:36 -0800 | [diff] [blame] | 203 | args: a tuple of three arguments that contains local_file, remote_file, and |
| 204 | the acl used for uploading the file. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 205 | |
| 206 | Returns: |
| 207 | Return the arg tuple of two if the upload failed |
| 208 | """ |
David James | fd0b085 | 2011-02-23 11:15:36 -0800 | [diff] [blame] | 209 | (local_file, remote_file, acl) = args |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 210 | CANNED_ACLS = ['public-read', 'private', 'bucket-owner-read', |
| 211 | 'authenticated-read', 'bucket-owner-full-control', |
| 212 | 'public-read-write'] |
| 213 | acl_cmd = None |
| 214 | if acl in CANNED_ACLS: |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 215 | cmd = [_GSUTIL_BIN, 'cp', '-a', acl, local_file, remote_file] |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 216 | else: |
| 217 | # For private uploads we assume that the overlay board is set up properly |
| 218 | # and a googlestore_acl.xml is present, if not this script errors |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 219 | cmd = [_GSUTIL_BIN, 'cp', '-a', 'private', local_file, remote_file] |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 220 | if not os.path.exists(acl): |
| 221 | print >> sys.stderr, ('You are specifying either a file that does not ' |
| 222 | 'exist or an unknown canned acl: %s. Aborting ' |
| 223 | 'upload') % acl |
| 224 | # emulate the failing of an upload since we are not uploading the file |
| 225 | return (local_file, remote_file) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 226 | |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 227 | acl_cmd = [_GSUTIL_BIN, 'setacl', acl, remote_file] |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 228 | |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 229 | if not _RetryRun(cmd, print_cmd=False): |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 230 | return (local_file, remote_file) |
| 231 | |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 232 | if acl_cmd: |
| 233 | # Apply the passed in ACL xml file to the uploaded object. |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 234 | _RetryRun(acl_cmd, print_cmd=False) |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 235 | |
| 236 | |
David James | fd0b085 | 2011-02-23 11:15:36 -0800 | [diff] [blame] | 237 | def RemoteUpload(acl, files, pool=10): |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 238 | """Upload to google storage. |
| 239 | |
| 240 | Create a pool of process and call _GsUpload with the proper arguments. |
| 241 | |
| 242 | Args: |
David James | fd0b085 | 2011-02-23 11:15:36 -0800 | [diff] [blame] | 243 | acl: The canned acl used for uploading. acl can be one of: "public-read", |
| 244 | "public-read-write", "authenticated-read", "bucket-owner-read", |
| 245 | "bucket-owner-full-control", or "private". |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 246 | files: dictionary with keys to local files and values to remote path. |
| 247 | pool: integer of maximum proesses to have at the same time. |
| 248 | |
| 249 | Returns: |
| 250 | Return a set of tuple arguments of the failed uploads |
| 251 | """ |
| 252 | # TODO(scottz) port this to use _RunManyParallel when it is available in |
| 253 | # cros_build_lib |
| 254 | pool = multiprocessing.Pool(processes=pool) |
| 255 | workers = [] |
| 256 | for local_file, remote_path in files.iteritems(): |
David James | fd0b085 | 2011-02-23 11:15:36 -0800 | [diff] [blame] | 257 | workers.append((local_file, remote_path, acl)) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 258 | |
| 259 | result = pool.map_async(_GsUpload, workers, chunksize=1) |
| 260 | while True: |
| 261 | try: |
Chris Sosa | 471532a | 2011-02-01 15:10:06 -0800 | [diff] [blame] | 262 | return set(result.get(60 * 60)) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 263 | except multiprocessing.TimeoutError: |
| 264 | pass |
| 265 | |
| 266 | |
| 267 | def GenerateUploadDict(base_local_path, base_remote_path, pkgs): |
| 268 | """Build a dictionary of local remote file key pairs to upload. |
| 269 | |
| 270 | Args: |
| 271 | base_local_path: The base path to the files on the local hard drive. |
| 272 | remote_path: The base path to the remote paths. |
| 273 | pkgs: The packages to upload. |
| 274 | |
| 275 | Returns: |
| 276 | Returns a dictionary of local_path/remote_path pairs |
| 277 | """ |
| 278 | upload_files = {} |
| 279 | for pkg in pkgs: |
| 280 | suffix = pkg['CPV'] + '.tbz2' |
| 281 | local_path = os.path.join(base_local_path, suffix) |
| 282 | assert os.path.exists(local_path) |
| 283 | remote_path = '%s/%s' % (base_remote_path.rstrip('/'), suffix) |
| 284 | upload_files[local_path] = remote_path |
| 285 | |
| 286 | return upload_files |
| 287 | |
| 288 | def GetBoardPathFromCrosOverlayList(build_path, target): |
| 289 | """Use the cros_overlay_list to determine the path to the board overlay |
| 290 | Args: |
| 291 | build_path: The path to the root of the build directory |
| 292 | target: The target that we are looking for, could consist of board and |
| 293 | board_variant, we handle that properly |
| 294 | Returns: |
| 295 | The last line from cros_overlay_list as a string |
| 296 | """ |
Chris Sosa | 471532a | 2011-02-01 15:10:06 -0800 | [diff] [blame] | 297 | script_dir = os.path.join(build_path, 'src/platform/dev/host') |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 298 | cmd = ['./cros_overlay_list'] |
| 299 | if re.match('.*?_.*', target): |
| 300 | (board, variant) = target.split('_') |
| 301 | cmd += ['--board', board, '--variant', variant] |
| 302 | elif re.match('.*?-\w+', target): |
| 303 | cmd += ['--board', target] |
| 304 | else: |
| 305 | raise UnknownBoardFormat('Unknown format: %s' % target) |
| 306 | |
| 307 | cmd_output = cros_build_lib.RunCommand(cmd, redirect_stdout=True, |
| 308 | cwd=script_dir) |
| 309 | # We only care about the last entry |
| 310 | return cmd_output.output.splitlines().pop() |
| 311 | |
| 312 | |
| 313 | def DeterminePrebuiltConfFile(build_path, target): |
| 314 | """Determine the prebuilt.conf file that needs to be updated for prebuilts. |
| 315 | |
| 316 | Args: |
| 317 | build_path: The path to the root of the build directory |
| 318 | target: String representation of the board. This includes host and board |
| 319 | targets |
| 320 | |
| 321 | Returns |
| 322 | A string path to a prebuilt.conf file to be updated. |
| 323 | """ |
| 324 | if _HOST_TARGET == target: |
| 325 | # We are host. |
| 326 | # Without more examples of hosts this is a kludge for now. |
| 327 | # TODO(Scottz): as new host targets come online expand this to |
| 328 | # work more like boards. |
Chris Sosa | 471532a | 2011-02-01 15:10:06 -0800 | [diff] [blame] | 329 | make_path = _PREBUILT_MAKE_CONF[target] |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 330 | else: |
| 331 | # We are a board |
| 332 | board = GetBoardPathFromCrosOverlayList(build_path, target) |
| 333 | make_path = os.path.join(board, 'prebuilt.conf') |
| 334 | |
| 335 | return make_path |
| 336 | |
| 337 | |
| 338 | def UpdateBinhostConfFile(path, key, value): |
| 339 | """Update binhost config file file with key=value. |
| 340 | |
| 341 | Args: |
| 342 | path: Filename to update. |
| 343 | key: Key to update. |
| 344 | value: New value for key. |
| 345 | """ |
| 346 | cwd = os.path.dirname(os.path.abspath(path)) |
| 347 | filename = os.path.basename(path) |
| 348 | if not os.path.isdir(cwd): |
| 349 | os.makedirs(cwd) |
| 350 | if not os.path.isfile(path): |
| 351 | config_file = file(path, 'w') |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 352 | config_file.close() |
| 353 | UpdateLocalFile(path, value, key) |
Chris Sosa | c13bba5 | 2011-05-24 15:14:09 -0700 | [diff] [blame] | 354 | cros_build_lib.RunCommand(['git', 'add', filename], cwd=cwd) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 355 | description = 'Update %s=%s in %s' % (key, value, filename) |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 356 | cros_build_lib.RunCommand(['git', 'commit', '-m', description], cwd=cwd) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 357 | |
| 358 | |
David James | ce093af | 2011-02-23 15:21:58 -0800 | [diff] [blame] | 359 | def _GrabAllRemotePackageIndexes(binhost_urls): |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 360 | """Grab all of the packages files associated with a list of binhost_urls. |
| 361 | |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 362 | Args: |
| 363 | binhost_urls: The URLs for the directories containing the Packages files we |
| 364 | want to grab. |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 365 | |
| 366 | Returns: |
| 367 | A list of PackageIndex objects. |
| 368 | """ |
| 369 | pkg_indexes = [] |
| 370 | for url in binhost_urls: |
| 371 | pkg_index = GrabRemotePackageIndex(url) |
| 372 | if pkg_index: |
| 373 | pkg_indexes.append(pkg_index) |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 374 | return pkg_indexes |
| 375 | |
| 376 | |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 377 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 378 | class PrebuiltUploader(object): |
| 379 | """Synchronize host and board prebuilts.""" |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 380 | |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 381 | def __init__(self, upload_location, acl, binhost_base_url, |
| 382 | pkg_indexes, build_path, packages): |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 383 | """Constructor for prebuilt uploader object. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 384 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 385 | This object can upload host or prebuilt files to Google Storage. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 386 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 387 | Args: |
| 388 | upload_location: The upload location. |
David James | fd0b085 | 2011-02-23 11:15:36 -0800 | [diff] [blame] | 389 | acl: The canned acl used for uploading to Google Storage. acl can be one |
| 390 | of: "public-read", "public-read-write", "authenticated-read", |
| 391 | "bucket-owner-read", "bucket-owner-full-control", or "private". If |
| 392 | we are not uploading to Google Storage, this parameter is unused. |
| 393 | binhost_base_url: The URL used for downloading the prebuilts. |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 394 | pkg_indexes: Old uploaded prebuilts to compare against. Instead of |
| 395 | uploading duplicate files, we just link to the old files. |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 396 | build_path: The path to the directory containing the chroot. |
| 397 | packages: Packages to upload. |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 398 | """ |
| 399 | self._upload_location = upload_location |
David James | fd0b085 | 2011-02-23 11:15:36 -0800 | [diff] [blame] | 400 | self._acl = acl |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 401 | self._binhost_base_url = binhost_base_url |
| 402 | self._pkg_indexes = pkg_indexes |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 403 | self._build_path = build_path |
| 404 | self._packages = set(packages) |
| 405 | |
| 406 | def _ShouldFilterPackage(self, pkg): |
| 407 | if not self._packages: |
| 408 | return False |
| 409 | pym_path = os.path.abspath(os.path.join(self._build_path, _PYM_PATH)) |
| 410 | sys.path.append(pym_path) |
| 411 | import portage.versions |
| 412 | cat, pkgname = portage.versions.catpkgsplit(pkg['CPV'])[0:2] |
| 413 | cp = '%s/%s' % (cat, pkgname) |
| 414 | return pkgname not in self._packages and cp not in self._packages |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 415 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 416 | def _UploadPrebuilt(self, package_path, url_suffix): |
| 417 | """Upload host or board prebuilt files to Google Storage space. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 418 | |
David James | a3bba14 | 2011-05-26 21:24:20 -0700 | [diff] [blame] | 419 | This function checks to see if we have any new binaries, and, if so, |
| 420 | uploads them. |
| 421 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 422 | Args: |
| 423 | package_path: The path to the packages dir. |
David James | ce093af | 2011-02-23 15:21:58 -0800 | [diff] [blame] | 424 | url_suffix: The remote subdirectory where we should upload the packages. |
David James | a3bba14 | 2011-05-26 21:24:20 -0700 | [diff] [blame] | 425 | |
| 426 | Returns: |
| 427 | True if any prebuilts were uploaded. |
| 428 | False otherwise. |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 429 | """ |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 430 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 431 | # Process Packages file, removing duplicates and filtered packages. |
| 432 | pkg_index = GrabLocalPackageIndex(package_path) |
| 433 | pkg_index.SetUploadLocation(self._binhost_base_url, url_suffix) |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 434 | pkg_index.RemoveFilteredPackages(self._ShouldFilterPackage) |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 435 | uploads = pkg_index.ResolveDuplicateUploads(self._pkg_indexes) |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 436 | |
David James | a3bba14 | 2011-05-26 21:24:20 -0700 | [diff] [blame] | 437 | if not uploads: |
| 438 | return False |
| 439 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 440 | # Write Packages file. |
| 441 | tmp_packages_file = pkg_index.WriteToNamedTemporaryFile() |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 442 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 443 | remote_location = '%s/%s' % (self._upload_location.rstrip('/'), url_suffix) |
| 444 | if remote_location.startswith('gs://'): |
| 445 | # Build list of files to upload. |
| 446 | upload_files = GenerateUploadDict(package_path, remote_location, uploads) |
| 447 | remote_file = '%s/Packages' % remote_location.rstrip('/') |
| 448 | upload_files[tmp_packages_file.name] = remote_file |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 449 | |
David James | fd0b085 | 2011-02-23 11:15:36 -0800 | [diff] [blame] | 450 | failed_uploads = RemoteUpload(self._acl, upload_files) |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 451 | if len(failed_uploads) > 1 or (None not in failed_uploads): |
David James | f4db112 | 2011-03-17 16:18:05 -0700 | [diff] [blame] | 452 | error_msg = ['%s -> %s\n' % args for args in failed_uploads if args] |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 453 | raise UploadFailed('Error uploading:\n%s' % error_msg) |
| 454 | else: |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 455 | pkgs = [p['CPV'] + '.tbz2' for p in uploads] |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 456 | ssh_server, remote_path = remote_location.split(':', 1) |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 457 | remote_path = remote_path.rstrip('/') |
| 458 | pkg_index = tmp_packages_file.name |
| 459 | remote_location = remote_location.rstrip('/') |
| 460 | remote_packages = '%s/Packages' % remote_location |
| 461 | cmds = [['ssh', ssh_server, 'mkdir', '-p', remote_path], |
| 462 | ['rsync', '-av', '--chmod=a+r', pkg_index, remote_packages]] |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 463 | if pkgs: |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 464 | cmds.append(['rsync', '-Rav'] + pkgs + [remote_location + '/']) |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 465 | for cmd in cmds: |
Peter Mayo | 193f68f | 2011-04-19 19:08:21 -0400 | [diff] [blame] | 466 | if not _RetryRun(cmd, cwd=package_path): |
| 467 | raise UploadFailed('Could not run %r' % cmd) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 468 | |
David James | a3bba14 | 2011-05-26 21:24:20 -0700 | [diff] [blame] | 469 | return True |
| 470 | |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 471 | def _UploadBoardTarball(self, board_path, url_suffix): |
| 472 | """Upload a tarball of the board at the specified path to Google Storage. |
| 473 | |
| 474 | Args: |
| 475 | board_path: The path to the board dir. |
| 476 | url_suffix: The remote subdirectory where we should upload the packages. |
| 477 | """ |
| 478 | remote_location = '%s/%s' % (self._upload_location.rstrip('/'), url_suffix) |
| 479 | assert remote_location.startswith('gs://') |
| 480 | cwd, boardname = os.path.split(board_path.rstrip(os.path.sep)) |
| 481 | tmpdir = tempfile.mkdtemp() |
| 482 | try: |
| 483 | tarfile = os.path.join(tmpdir, '%s.tbz2' % boardname) |
| 484 | cmd = ['sudo', 'tar', '-I', 'pbzip2', '-cf', tarfile] |
| 485 | excluded_paths = ('usr/lib/debug', 'usr/local/autotest', 'packages', |
| 486 | 'tmp') |
| 487 | for path in excluded_paths: |
| 488 | cmd.append('--exclude=%s/%s/*' % (boardname, path)) |
| 489 | cmd.append(boardname) |
| 490 | cros_build_lib.RunCommand(cmd, cwd=cwd) |
| 491 | remote_tarfile = '%s/%s.tbz2' % (remote_location.rstrip('/'), boardname) |
| 492 | if _GsUpload((tarfile, remote_tarfile, self._acl)): |
| 493 | sys.exit(1) |
| 494 | finally: |
| 495 | cros_build_lib.RunCommand(['sudo', 'rm', '-rf', tmpdir], cwd=cwd) |
| 496 | |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 497 | def _SyncHostPrebuilts(self, version, key, git_sync, sync_binhost_conf): |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 498 | """Synchronize host prebuilt files. |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 499 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 500 | This function will sync both the standard host packages, plus the host |
| 501 | packages associated with all targets that have been "setup" with the |
| 502 | current host's chroot. For instance, if this host has been used to build |
| 503 | x86-generic, it will sync the host packages associated with |
| 504 | 'i686-pc-linux-gnu'. If this host has also been used to build arm-generic, |
| 505 | it will also sync the host packages associated with |
| 506 | 'armv7a-cros-linux-gnueabi'. |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 507 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 508 | Args: |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 509 | version: A unique string, intended to be included in the upload path, |
| 510 | which identifies the version number of the uploaded prebuilts. |
| 511 | key: The variable key to update in the git file. |
| 512 | git_sync: If set, update make.conf of target to reference the latest |
| 513 | prebuilt packages generated here. |
| 514 | sync_binhost_conf: If set, update binhost config file in |
| 515 | chromiumos-overlay for the host. |
| 516 | """ |
| 517 | # Upload prebuilts. |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 518 | package_path = os.path.join(self._build_path, _HOST_PACKAGES_PATH) |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 519 | url_suffix = _REL_HOST_PATH % {'version': version, 'target': _HOST_TARGET} |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 520 | packages_url_suffix = '%s/packages' % url_suffix.rstrip('/') |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 521 | |
David James | a3bba14 | 2011-05-26 21:24:20 -0700 | [diff] [blame] | 522 | if self._UploadPrebuilt(package_path, packages_url_suffix): |
| 523 | # Record URL where prebuilts were uploaded. |
| 524 | url_value = '%s/%s/' % (self._binhost_base_url.rstrip('/'), |
| 525 | packages_url_suffix.rstrip('/')) |
| 526 | if git_sync: |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 527 | git_file = os.path.join(self._build_path, |
| 528 | _PREBUILT_MAKE_CONF[_HOST_TARGET]) |
David James | a3bba14 | 2011-05-26 21:24:20 -0700 | [diff] [blame] | 529 | RevGitFile(git_file, url_value, key=key) |
| 530 | if sync_binhost_conf: |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 531 | binhost_conf = os.path.join(self._build_path, _BINHOST_CONF_DIR, |
| 532 | 'host', '%s-%s.conf' % (_HOST_TARGET, key)) |
David James | a3bba14 | 2011-05-26 21:24:20 -0700 | [diff] [blame] | 533 | UpdateBinhostConfFile(binhost_conf, key, url_value) |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 534 | |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 535 | def _SyncBoardPrebuilts(self, board, version, key, git_sync, |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 536 | sync_binhost_conf, upload_board_tarball): |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 537 | """Synchronize board prebuilt files. |
| 538 | |
| 539 | Args: |
| 540 | board: The board to upload to Google Storage. |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 541 | version: A unique string, intended to be included in the upload path, |
| 542 | which identifies the version number of the uploaded prebuilts. |
| 543 | key: The variable key to update in the git file. |
| 544 | git_sync: If set, update make.conf of target to reference the latest |
| 545 | prebuilt packages generated here. |
| 546 | sync_binhost_conf: If set, update binhost config file in |
| 547 | chromiumos-overlay for the current board. |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 548 | upload_board_tarball: Include a tarball of the board in our upload. |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 549 | """ |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 550 | board_path = os.path.join(self._build_path, _BOARD_PATH % {'board': board}) |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 551 | package_path = os.path.join(board_path, 'packages') |
| 552 | url_suffix = _REL_BOARD_PATH % {'board': board, 'version': version} |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 553 | packages_url_suffix = '%s/packages' % url_suffix.rstrip('/') |
| 554 | |
| 555 | # Upload board tarballs in the background. |
| 556 | if upload_board_tarball: |
| 557 | tar_process = multiprocessing.Process(target=self._UploadBoardTarball, |
| 558 | args=(board_path, url_suffix)) |
| 559 | tar_process.start() |
| 560 | |
| 561 | # Upload prebuilts. |
David James | a3bba14 | 2011-05-26 21:24:20 -0700 | [diff] [blame] | 562 | uploaded = self._UploadPrebuilt(package_path, packages_url_suffix) |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 563 | |
| 564 | # Make sure we finished uploading the board tarballs. |
| 565 | if upload_board_tarball: |
| 566 | tar_process.join() |
| 567 | assert tar_process.exitcode == 0 |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 568 | |
David James | a3bba14 | 2011-05-26 21:24:20 -0700 | [diff] [blame] | 569 | if uploaded: |
| 570 | # Record URL where prebuilts were uploaded. |
| 571 | url_value = '%s/%s/' % (self._binhost_base_url.rstrip('/'), |
| 572 | packages_url_suffix.rstrip('/')) |
| 573 | if git_sync: |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 574 | git_file = DeterminePrebuiltConfFile(self._build_path, board) |
David James | a3bba14 | 2011-05-26 21:24:20 -0700 | [diff] [blame] | 575 | RevGitFile(git_file, url_value, key=key) |
| 576 | if sync_binhost_conf: |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 577 | binhost_conf = os.path.join(self._build_path, _BINHOST_CONF_DIR, |
| 578 | 'target', '%s-%s.conf' % (board, key)) |
David James | a3bba14 | 2011-05-26 21:24:20 -0700 | [diff] [blame] | 579 | UpdateBinhostConfFile(binhost_conf, key, url_value) |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 580 | |
| 581 | |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 582 | def usage(parser, msg): |
| 583 | """Display usage message and parser help then exit with 1.""" |
| 584 | print >> sys.stderr, msg |
| 585 | parser.print_help() |
| 586 | sys.exit(1) |
| 587 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 588 | def ParseOptions(): |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 589 | parser = optparse.OptionParser() |
| 590 | parser.add_option('-H', '--binhost-base-url', dest='binhost_base_url', |
| 591 | default=_BINHOST_BASE_URL, |
| 592 | help='Base URL to use for binhost in make.conf updates') |
| 593 | parser.add_option('', '--previous-binhost-url', action='append', |
| 594 | default=[], dest='previous_binhost_url', |
| 595 | help='Previous binhost URL') |
| 596 | parser.add_option('-b', '--board', dest='board', default=None, |
| 597 | help='Board type that was built on this machine') |
| 598 | parser.add_option('-p', '--build-path', dest='build_path', |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 599 | help='Path to the directory containing the chroot') |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 600 | parser.add_option('', '--packages', action='append', |
| 601 | default=[], dest='packages', |
| 602 | help='Only include the specified packages. ' |
| 603 | '(Default is to include all packages.)') |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 604 | parser.add_option('-s', '--sync-host', dest='sync_host', |
| 605 | default=False, action='store_true', |
| 606 | help='Sync host prebuilts') |
| 607 | parser.add_option('-g', '--git-sync', dest='git_sync', |
| 608 | default=False, action='store_true', |
| 609 | help='Enable git version sync (This commits to a repo)') |
| 610 | parser.add_option('-u', '--upload', dest='upload', |
| 611 | default=None, |
| 612 | help='Upload location') |
| 613 | parser.add_option('-V', '--prepend-version', dest='prepend_version', |
| 614 | default=None, |
| 615 | help='Add an identifier to the front of the version') |
| 616 | parser.add_option('-f', '--filters', dest='filters', action='store_true', |
| 617 | default=False, |
| 618 | help='Turn on filtering of private ebuild packages') |
| 619 | parser.add_option('-k', '--key', dest='key', |
| 620 | default='PORTAGE_BINHOST', |
| 621 | help='Key to update in make.conf / binhost.conf') |
| 622 | parser.add_option('', '--sync-binhost-conf', dest='sync_binhost_conf', |
| 623 | default=False, action='store_true', |
| 624 | help='Update binhost.conf') |
David James | fd0b085 | 2011-02-23 11:15:36 -0800 | [diff] [blame] | 625 | parser.add_option('-P', '--private', dest='private', action='store_true', |
| 626 | default=False, help='Mark gs:// uploads as private.') |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 627 | parser.add_option('', '--upload-board-tarball', dest='upload_board_tarball', |
| 628 | action='store_true', default=False, |
| 629 | help='Upload board tarball to Google Storage.') |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 630 | |
| 631 | options, args = parser.parse_args() |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 632 | if not options.build_path: |
| 633 | usage(parser, 'Error: you need provide a chroot path') |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 634 | if not options.upload: |
| 635 | usage(parser, 'Error: you need to provide an upload location using -u') |
David James | 9417f27 | 2011-05-26 13:24:47 -0700 | [diff] [blame] | 636 | if args: |
| 637 | usage(parser, 'Error: invalid arguments passed to prebuilt.py: %r' % args) |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 638 | |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 639 | |
| 640 | if options.upload_board_tarball and not options.upload.startswith('gs://'): |
| 641 | usage(parser, 'Error: --upload-board-tarball only works with gs:// URLs.\n' |
| 642 | '--upload must be a gs:// URL.') |
| 643 | |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 644 | if options.private: |
| 645 | if options.sync_host: |
| 646 | usage(parser, 'Error: --private and --sync-host/-s cannot be specified ' |
| 647 | 'together, we do not support private host prebuilts') |
| 648 | |
| 649 | if not options.upload.startswith('gs://'): |
| 650 | usage(parser, 'Error: --private is only valid for gs:// URLs.\n' |
| 651 | '--upload must be a gs:// URL.') |
| 652 | |
| 653 | if options.binhost_base_url != _BINHOST_BASE_URL: |
| 654 | usage(parser, 'Error: when using --private the --binhost-base-url ' |
| 655 | 'is automatically derived.') |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 656 | return options |
| 657 | |
| 658 | def main(): |
David James | db40107 | 2011-06-10 12:17:16 -0700 | [diff] [blame] | 659 | # Set umask to a sane value so that files created as root are readable. |
| 660 | os.umask(022) |
| 661 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 662 | options = ParseOptions() |
| 663 | |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 664 | # Calculate a list of Packages index files to compare against. Whenever we |
| 665 | # upload a package, we check to make sure it's not already stored in one of |
| 666 | # the packages files we uploaded. This list of packages files might contain |
| 667 | # both board and host packages. |
David James | ce093af | 2011-02-23 15:21:58 -0800 | [diff] [blame] | 668 | pkg_indexes = _GrabAllRemotePackageIndexes(options.previous_binhost_url) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 669 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 670 | version = GetVersion() |
| 671 | if options.prepend_version: |
| 672 | version = '%s-%s' % (options.prepend_version, version) |
| 673 | |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 674 | acl = 'public-read' |
| 675 | binhost_base_url = options.binhost_base_url |
| 676 | |
| 677 | if options.private: |
| 678 | binhost_base_url = options.upload |
| 679 | board_path = GetBoardPathFromCrosOverlayList(options.build_path, |
| 680 | options.board) |
| 681 | acl = os.path.join(board_path, _GOOGLESTORAGE_ACL_FILE) |
| 682 | |
| 683 | uploader = PrebuiltUploader(options.upload, acl, binhost_base_url, |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 684 | pkg_indexes, options.build_path, |
| 685 | options.packages) |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 686 | |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 687 | if options.sync_host: |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 688 | uploader._SyncHostPrebuilts(version, options.key, options.git_sync, |
| 689 | options.sync_binhost_conf) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 690 | |
| 691 | if options.board: |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 692 | uploader._SyncBoardPrebuilts(options.board, version, |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 693 | options.key, options.git_sync, |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 694 | options.sync_binhost_conf, |
| 695 | options.upload_board_tarball) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 696 | |
| 697 | if __name__ == '__main__': |
| 698 | main() |