Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium 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 """A utility script for downloading versioned Syzygy binaries.""" | 6 """A utility script for downloading versioned Syzygy binaries.""" |
| 7 | 7 |
| 8 import hashlib | 8 import hashlib |
| 9 import errno | 9 import errno |
| 10 import json | 10 import json |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 # List of reources to be downloaded and installed. These are tuples with the | 41 # List of reources to be downloaded and installed. These are tuples with the |
| 42 # following format: | 42 # following format: |
| 43 # (basename, logging name, relative installation path, extraction filter) | 43 # (basename, logging name, relative installation path, extraction filter) |
| 44 _RESOURCES = [ | 44 _RESOURCES = [ |
| 45 ('benchmark.zip', 'benchmark', '', None), | 45 ('benchmark.zip', 'benchmark', '', None), |
| 46 ('binaries.zip', 'binaries', 'exe', None), | 46 ('binaries.zip', 'binaries', 'exe', None), |
| 47 ('symbols.zip', 'symbols', 'exe', | 47 ('symbols.zip', 'symbols', 'exe', |
| 48 lambda x: x.filename.endswith('.dll.pdb'))] | 48 lambda x: x.filename.endswith('.dll.pdb'))] |
| 49 | 49 |
| 50 | 50 |
| 51 # Name of the MS DIA dll that we need to copy to the binaries directory. | |
| 52 _DIA_DLL_NAME = "msdia140.dll" | |
| 53 | |
| 54 | |
| 51 def _LoadState(output_dir): | 55 def _LoadState(output_dir): |
| 52 """Loads the contents of the state file for a given |output_dir|, returning | 56 """Loads the contents of the state file for a given |output_dir|, returning |
| 53 None if it doesn't exist. | 57 None if it doesn't exist. |
| 54 """ | 58 """ |
| 55 path = os.path.join(output_dir, _STATE) | 59 path = os.path.join(output_dir, _STATE) |
| 56 if not os.path.exists(path): | 60 if not os.path.exists(path): |
| 57 _LOGGER.debug('No state file found.') | 61 _LOGGER.debug('No state file found.') |
| 58 return None | 62 return None |
| 59 with open(path, 'rb') as f: | 63 with open(path, 'rb') as f: |
| 60 _LOGGER.debug('Reading state file: %s', path) | 64 _LOGGER.debug('Reading state file: %s', path) |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 | 279 |
| 276 def _Download(resource): | 280 def _Download(resource): |
| 277 """Downloads the given GS resource to a temporary file, returning its path.""" | 281 """Downloads the given GS resource to a temporary file, returning its path.""" |
| 278 tmp = tempfile.mkstemp(suffix='syzygy_archive') | 282 tmp = tempfile.mkstemp(suffix='syzygy_archive') |
| 279 os.close(tmp[0]) | 283 os.close(tmp[0]) |
| 280 url = 'gs://syzygy-archive' + resource | 284 url = 'gs://syzygy-archive' + resource |
| 281 _GsUtil('cp', url, tmp[1]) | 285 _GsUtil('cp', url, tmp[1]) |
| 282 return tmp[1] | 286 return tmp[1] |
| 283 | 287 |
| 284 | 288 |
| 289 def _MaybeCopyDIABinaries(options, contents): | |
| 290 """Try to copy the DIA DLL to the binaries exe directory.""" | |
| 291 toolchain_data_file = os.path.join(os.path.dirname(__file__), | |
| 292 'win_toolchain.json') | |
| 293 if not os.path.exists(toolchain_data_file): | |
| 294 _LOGGER.debug('Toolchain JSON data file doesn\'t exist, skipping.') | |
| 295 return | |
| 296 with open(toolchain_data_file) as temp_f: | |
| 297 toolchain_data = json.load(temp_f) | |
| 298 if not os.path.isdir(toolchain_data['path']): | |
| 299 _LOGGER.error('The toolchain JSON file is invalid.') | |
| 300 return | |
| 301 dia_sdk_binaries_dir = os.path.join(toolchain_data['path'], 'DIA SDK', 'bin') | |
| 302 dia_dll = os.path.join(dia_sdk_binaries_dir, _DIA_DLL_NAME) | |
| 303 if not os.path.exists(dia_dll): | |
| 304 _LOGGER.debug('%s is missing, skipping.') | |
| 305 return | |
| 306 dia_dll_dest = os.path.join(options.output_dir, 'exe', _DIA_DLL_NAME) | |
| 307 _LOGGER.debug('Copying %s to %s.' % (dia_dll, dia_dll_dest)) | |
| 308 if not options.dry_run: | |
| 309 shutil.copy(dia_dll, dia_dll_dest) | |
| 310 contents[os.path.relpath(dia_dll_dest, options.output_dir)] = ( | |
| 311 _Md5(dia_dll_dest)) | |
| 312 | |
| 313 | |
| 285 def _InstallBinaries(options, deleted={}): | 314 def _InstallBinaries(options, deleted={}): |
| 286 """Installs Syzygy binaries. This assumes that the output directory has | 315 """Installs Syzygy binaries. This assumes that the output directory has |
| 287 already been cleaned, as it will refuse to overwrite existing files.""" | 316 already been cleaned, as it will refuse to overwrite existing files.""" |
| 288 contents = {} | 317 contents = {} |
| 289 state = { 'revision': options.revision, 'contents': contents } | 318 state = { 'revision': options.revision, 'contents': contents } |
| 290 archive_path = _SYZYGY_ARCHIVE_PATH % { 'revision': options.revision } | 319 archive_path = _SYZYGY_ARCHIVE_PATH % { 'revision': options.revision } |
| 291 if options.resources: | 320 if options.resources: |
| 292 resources = [(resource, resource, '', None) | 321 resources = [(resource, resource, '', None) |
| 293 for resource in options.resources] | 322 for resource in options.resources] |
| 294 else: | 323 else: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 if not options.dry_run: | 358 if not options.dry_run: |
| 330 archive.extract(entry.filename, fulldir) | 359 archive.extract(entry.filename, fulldir) |
| 331 md5 = _Md5(fullpath) | 360 md5 = _Md5(fullpath) |
| 332 contents[relpath] = md5 | 361 contents[relpath] = md5 |
| 333 if sys.platform == 'cygwin': | 362 if sys.platform == 'cygwin': |
| 334 os.chmod(fullpath, os.stat(fullpath).st_mode | stat.S_IXUSR) | 363 os.chmod(fullpath, os.stat(fullpath).st_mode | stat.S_IXUSR) |
| 335 | 364 |
| 336 _LOGGER.debug('Removing temporary file "%s".', path) | 365 _LOGGER.debug('Removing temporary file "%s".', path) |
| 337 os.remove(path) | 366 os.remove(path) |
| 338 | 367 |
| 368 if options.copy_dia_binaries: | |
| 369 # Try to copy the DIA binaries to the binaries directory. | |
| 370 _MaybeCopyDIABinaries(options, contents) | |
| 371 | |
| 339 return state | 372 return state |
| 340 | 373 |
| 341 | 374 |
| 342 def _ParseCommandLine(): | 375 def _ParseCommandLine(): |
| 343 """Parses the command-line and returns an options structure.""" | 376 """Parses the command-line and returns an options structure.""" |
| 344 option_parser = optparse.OptionParser() | 377 option_parser = optparse.OptionParser() |
| 345 option_parser.add_option('--dry-run', action='store_true', default=False, | 378 option_parser.add_option('--dry-run', action='store_true', default=False, |
| 346 help='If true then will simply list actions that would be performed.') | 379 help='If true then will simply list actions that would be performed.') |
| 347 option_parser.add_option('--force', action='store_true', default=False, | 380 option_parser.add_option('--force', action='store_true', default=False, |
| 348 help='Force an installation even if the binaries are up to date.') | 381 help='Force an installation even if the binaries are up to date.') |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 360 option_parser.add_option('--revision-file', type='string', | 393 option_parser.add_option('--revision-file', type='string', |
| 361 help='A text file containing an SVN revision or GIT hash.') | 394 help='A text file containing an SVN revision or GIT hash.') |
| 362 option_parser.add_option('--resource', type='string', action='append', | 395 option_parser.add_option('--resource', type='string', action='append', |
| 363 dest='resources', help='A resource to be downloaded.') | 396 dest='resources', help='A resource to be downloaded.') |
| 364 option_parser.add_option('--verbose', dest='log_level', action='store_const', | 397 option_parser.add_option('--verbose', dest='log_level', action='store_const', |
| 365 default=logging.INFO, const=logging.DEBUG, | 398 default=logging.INFO, const=logging.DEBUG, |
| 366 help='Enables verbose logging.') | 399 help='Enables verbose logging.') |
| 367 option_parser.add_option('--quiet', dest='log_level', action='store_const', | 400 option_parser.add_option('--quiet', dest='log_level', action='store_const', |
| 368 default=logging.INFO, const=logging.ERROR, | 401 default=logging.INFO, const=logging.ERROR, |
| 369 help='Disables all output except for errors.') | 402 help='Disables all output except for errors.') |
| 403 option_parser.add_option('--copy-dia-binaries', action='store_true', | |
| 404 default=False, help='If true then the DIA dll will get copied into the ' | |
| 405 'binaries directory if it\'s available.') | |
|
chrisha
2016/10/04 15:14:36
update this comment to reflect that it will *try*.
Sébastien Marchand
2016/10/04 15:18:50
It already mention "If it's available", isn't it e
| |
| 370 options, args = option_parser.parse_args() | 406 options, args = option_parser.parse_args() |
| 371 if args: | 407 if args: |
| 372 option_parser.error('Unexpected arguments: %s' % args) | 408 option_parser.error('Unexpected arguments: %s' % args) |
| 373 if not options.output_dir: | 409 if not options.output_dir: |
| 374 option_parser.error('Must specify --output-dir.') | 410 option_parser.error('Must specify --output-dir.') |
| 375 if not options.revision and not options.revision_file: | 411 if not options.revision and not options.revision_file: |
| 376 option_parser.error('Must specify one of --revision or --revision-file.') | 412 option_parser.error('Must specify one of --revision or --revision-file.') |
| 377 if options.revision and options.revision_file: | 413 if options.revision and options.revision_file: |
| 378 option_parser.error('Must not specify both --revision and --revision-file.') | 414 option_parser.error('Must not specify both --revision and --revision-file.') |
| 379 | 415 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 # Install the new binaries. In a dry-run this will actually download the | 514 # Install the new binaries. In a dry-run this will actually download the |
| 479 # archives, but it won't write anything to disk. | 515 # archives, but it won't write anything to disk. |
| 480 state = _InstallBinaries(options, deleted) | 516 state = _InstallBinaries(options, deleted) |
| 481 | 517 |
| 482 # Build and save the state for the directory. | 518 # Build and save the state for the directory. |
| 483 _SaveState(options.output_dir, state, options.dry_run) | 519 _SaveState(options.output_dir, state, options.dry_run) |
| 484 | 520 |
| 485 | 521 |
| 486 if __name__ == '__main__': | 522 if __name__ == '__main__': |
| 487 main() | 523 main() |
| OLD | NEW |