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

Side by Side Diff: build/get_syzygy_binaries.py

Issue 2365893002: Automatically copy the DIA DLL in the Syzygy binaries directory. (Closed)
Patch Set: Fix Created 4 years, 2 months 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
« no previous file with comments | « DEPS ('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/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 fnmatch
10 import json 11 import json
11 import logging 12 import logging
12 import optparse 13 import optparse
13 import os 14 import os
14 import re 15 import re
15 import shutil 16 import shutil
16 import stat 17 import stat
17 import sys 18 import sys
18 import subprocess 19 import subprocess
19 import tempfile 20 import tempfile
(...skipping 21 matching lines...) Expand all
41 # List of reources to be downloaded and installed. These are tuples with the 42 # List of reources to be downloaded and installed. These are tuples with the
42 # following format: 43 # following format:
43 # (basename, logging name, relative installation path, extraction filter) 44 # (basename, logging name, relative installation path, extraction filter)
44 _RESOURCES = [ 45 _RESOURCES = [
45 ('benchmark.zip', 'benchmark', '', None), 46 ('benchmark.zip', 'benchmark', '', None),
46 ('binaries.zip', 'binaries', 'exe', None), 47 ('binaries.zip', 'binaries', 'exe', None),
47 ('symbols.zip', 'symbols', 'exe', 48 ('symbols.zip', 'symbols', 'exe',
48 lambda x: x.filename.endswith('.dll.pdb'))] 49 lambda x: x.filename.endswith('.dll.pdb'))]
49 50
50 51
52 # Name of the MS DIA dll that we need to copy to the binaries directory.
53 _DIA_DLL_NAME = "msdia140.dll"
54
55
51 def _LoadState(output_dir): 56 def _LoadState(output_dir):
52 """Loads the contents of the state file for a given |output_dir|, returning 57 """Loads the contents of the state file for a given |output_dir|, returning
53 None if it doesn't exist. 58 None if it doesn't exist.
54 """ 59 """
55 path = os.path.join(output_dir, _STATE) 60 path = os.path.join(output_dir, _STATE)
56 if not os.path.exists(path): 61 if not os.path.exists(path):
57 _LOGGER.debug('No state file found.') 62 _LOGGER.debug('No state file found.')
58 return None 63 return None
59 with open(path, 'rb') as f: 64 with open(path, 'rb') as f:
60 _LOGGER.debug('Reading state file: %s', path) 65 _LOGGER.debug('Reading state file: %s', path)
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 280
276 def _Download(resource): 281 def _Download(resource):
277 """Downloads the given GS resource to a temporary file, returning its path.""" 282 """Downloads the given GS resource to a temporary file, returning its path."""
278 tmp = tempfile.mkstemp(suffix='syzygy_archive') 283 tmp = tempfile.mkstemp(suffix='syzygy_archive')
279 os.close(tmp[0]) 284 os.close(tmp[0])
280 url = 'gs://syzygy-archive' + resource 285 url = 'gs://syzygy-archive' + resource
281 _GsUtil('cp', url, tmp[1]) 286 _GsUtil('cp', url, tmp[1])
282 return tmp[1] 287 return tmp[1]
283 288
284 289
290 def _MaybeCopyDIABinaries(options, contents):
scottmg 2016/10/03 21:47:03 I guess it shouldn't be called "Maybe..." any more
Sébastien Marchand 2016/10/03 21:57:08 Ha good point, initially this function was only a
291 """Try to copy the DIA DLL to the binaries exe directory.
292
293 This doesn't check if the toolchain version of this DLL is the same as the
294 one used by the Syzygy binaries, so this will only be useful if Chrome and
295 Syzygy are using the same revision of the toolchain.
296 """
297 toolchain_data_file = os.path.join(os.path.dirname(__file__),
298 'win_toolchain.json')
299 if not os.path.exists(toolchain_data_file):
300 _LOGGER.debug('Toolchain JSON data file doesn\'t exist.')
301 return
302 _LOGGER.debug('%s exists' % toolchain_data_file)
303 with open(toolchain_data_file) as temp_f:
304 toolchain_data = json.load(temp_f)
305 if not os.path.isdir(toolchain_data['path']):
306 _LOGGER.error('The toolchain JSON file is invalid.')
307 return
308 dia_sdk_binaries_dir = os.path.join(toolchain_data['path'], 'DIA SDK', 'bin')
309 dia_dll = os.path.join(dia_sdk_binaries_dir, _DIA_DLL_NAME)
310 if not os.path.exists(dia_dll):
311 raise Exception('%s is missing.')
312 dia_dll_dest = os.path.join(options.output_dir, 'exe', _DIA_DLL_NAME)
313 _LOGGER.debug('Copying %s to %s.' % (dia_dll, dia_dll_dest))
314 if not options.dry_run:
315 shutil.copy(dia_dll, dia_dll_dest)
316 contents[os.path.relpath(dia_dll_dest, options.output_dir)] = (
317 _Md5(dia_dll_dest))
318
319
285 def _InstallBinaries(options, deleted={}): 320 def _InstallBinaries(options, deleted={}):
286 """Installs Syzygy binaries. This assumes that the output directory has 321 """Installs Syzygy binaries. This assumes that the output directory has
287 already been cleaned, as it will refuse to overwrite existing files.""" 322 already been cleaned, as it will refuse to overwrite existing files."""
288 contents = {} 323 contents = {}
289 state = { 'revision': options.revision, 'contents': contents } 324 state = { 'revision': options.revision, 'contents': contents }
290 archive_path = _SYZYGY_ARCHIVE_PATH % { 'revision': options.revision } 325 archive_path = _SYZYGY_ARCHIVE_PATH % { 'revision': options.revision }
291 if options.resources: 326 if options.resources:
292 resources = [(resource, resource, '', None) 327 resources = [(resource, resource, '', None)
293 for resource in options.resources] 328 for resource in options.resources]
294 else: 329 else:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 if not options.dry_run: 364 if not options.dry_run:
330 archive.extract(entry.filename, fulldir) 365 archive.extract(entry.filename, fulldir)
331 md5 = _Md5(fullpath) 366 md5 = _Md5(fullpath)
332 contents[relpath] = md5 367 contents[relpath] = md5
333 if sys.platform == 'cygwin': 368 if sys.platform == 'cygwin':
334 os.chmod(fullpath, os.stat(fullpath).st_mode | stat.S_IXUSR) 369 os.chmod(fullpath, os.stat(fullpath).st_mode | stat.S_IXUSR)
335 370
336 _LOGGER.debug('Removing temporary file "%s".', path) 371 _LOGGER.debug('Removing temporary file "%s".', path)
337 os.remove(path) 372 os.remove(path)
338 373
374 if options.copy_dia_binaries:
375 # Try to copy the DIA binaries to the binaries directory.
376 _MaybeCopyDIABinaries(options, contents)
377
339 return state 378 return state
340 379
341 380
342 def _ParseCommandLine(): 381 def _ParseCommandLine():
343 """Parses the command-line and returns an options structure.""" 382 """Parses the command-line and returns an options structure."""
344 option_parser = optparse.OptionParser() 383 option_parser = optparse.OptionParser()
345 option_parser.add_option('--dry-run', action='store_true', default=False, 384 option_parser.add_option('--dry-run', action='store_true', default=False,
346 help='If true then will simply list actions that would be performed.') 385 help='If true then will simply list actions that would be performed.')
347 option_parser.add_option('--force', action='store_true', default=False, 386 option_parser.add_option('--force', action='store_true', default=False,
348 help='Force an installation even if the binaries are up to date.') 387 help='Force an installation even if the binaries are up to date.')
(...skipping 11 matching lines...) Expand all
360 option_parser.add_option('--revision-file', type='string', 399 option_parser.add_option('--revision-file', type='string',
361 help='A text file containing an SVN revision or GIT hash.') 400 help='A text file containing an SVN revision or GIT hash.')
362 option_parser.add_option('--resource', type='string', action='append', 401 option_parser.add_option('--resource', type='string', action='append',
363 dest='resources', help='A resource to be downloaded.') 402 dest='resources', help='A resource to be downloaded.')
364 option_parser.add_option('--verbose', dest='log_level', action='store_const', 403 option_parser.add_option('--verbose', dest='log_level', action='store_const',
365 default=logging.INFO, const=logging.DEBUG, 404 default=logging.INFO, const=logging.DEBUG,
366 help='Enables verbose logging.') 405 help='Enables verbose logging.')
367 option_parser.add_option('--quiet', dest='log_level', action='store_const', 406 option_parser.add_option('--quiet', dest='log_level', action='store_const',
368 default=logging.INFO, const=logging.ERROR, 407 default=logging.INFO, const=logging.ERROR,
369 help='Disables all output except for errors.') 408 help='Disables all output except for errors.')
409 option_parser.add_option('--copy-dia-binaries', action='store_true',
410 default=False, help='If true then the DIA dll will get copied into the '
411 'binaries directory if it\'s available.')
370 options, args = option_parser.parse_args() 412 options, args = option_parser.parse_args()
371 if args: 413 if args:
372 option_parser.error('Unexpected arguments: %s' % args) 414 option_parser.error('Unexpected arguments: %s' % args)
373 if not options.output_dir: 415 if not options.output_dir:
374 option_parser.error('Must specify --output-dir.') 416 option_parser.error('Must specify --output-dir.')
375 if not options.revision and not options.revision_file: 417 if not options.revision and not options.revision_file:
376 option_parser.error('Must specify one of --revision or --revision-file.') 418 option_parser.error('Must specify one of --revision or --revision-file.')
377 if options.revision and options.revision_file: 419 if options.revision and options.revision_file:
378 option_parser.error('Must not specify both --revision and --revision-file.') 420 option_parser.error('Must not specify both --revision and --revision-file.')
379 421
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 # Install the new binaries. In a dry-run this will actually download the 520 # Install the new binaries. In a dry-run this will actually download the
479 # archives, but it won't write anything to disk. 521 # archives, but it won't write anything to disk.
480 state = _InstallBinaries(options, deleted) 522 state = _InstallBinaries(options, deleted)
481 523
482 # Build and save the state for the directory. 524 # Build and save the state for the directory.
483 _SaveState(options.output_dir, state, options.dry_run) 525 _SaveState(options.output_dir, state, options.dry_run)
484 526
485 527
486 if __name__ == '__main__': 528 if __name__ == '__main__':
487 main() 529 main()
OLDNEW
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698