OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
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 hashlib | |
7 import os | |
8 import shutil | |
9 import sys | |
10 | |
11 script_dir = os.path.dirname(os.path.realpath(__file__)) | |
12 src_build_dir = os.path.abspath(os.path.join(script_dir, os.pardir)) | |
13 sys.path.insert(0, src_build_dir) | |
14 | |
15 import vs_toolchain | |
16 | |
17 | |
18 def _HexDigest(file_name): | |
19 hasher = hashlib.sha256() | |
20 afile = open(file_name, 'rb') | |
Dirk Pranke
2016/04/07 21:38:39
nit: you need to close() afile.
| |
21 blocksize = 65536 | |
22 buf = afile.read(blocksize) | |
23 while len(buf) > 0: | |
24 hasher.update(buf) | |
25 buf = afile.read(blocksize) | |
26 return hasher.hexdigest() | |
27 | |
28 | |
29 def _CopyImpl(file_name, target_dir, source_dir, verbose=True): | |
30 """Copy |source| to |target| if it doesn't already exist or if it | |
31 needs to be updated. | |
32 """ | |
33 target = os.path.join(target_dir, file_name) | |
34 source = os.path.join(source_dir, file_name) | |
35 if (os.path.isdir(os.path.dirname(target)) and | |
36 ((not os.path.isfile(target)) or | |
37 _HexDigest(source) != _HexDigest(target))): | |
38 if verbose: | |
39 print 'Copying %s to %s...' % (source, target) | |
40 if os.path.exists(target): | |
41 os.unlink(target) | |
42 shutil.copy(source, target) | |
43 | |
44 | |
45 def _CopyCDBToOutput(output_dir, target_arch): | |
46 """Copies the Windows debugging executable cdb.exe to the output | |
47 directory, which is created if it does not exist. The output | |
48 directory, and target architecture that should be copied, are | |
49 passed. Supported values for the target architecture are the GYP | |
50 values "ia32" and "x64". | |
51 """ | |
52 if not os.path.isdir(output_dir): | |
53 os.makedirs(output_dir) | |
54 vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs() | |
55 win_sdk_dir = os.path.normpath(os.environ['WINDOWSSDKDIR']) | |
56 if target_arch == 'ia32': | |
57 src_arch = 'x86' | |
58 elif target_arch == 'x64': | |
59 src_arch = 'x64' | |
60 else: | |
61 print 'copy_cdb_to_output.py: unknown target_arch %s' % target_arch | |
62 sys.exit(1) | |
63 # We need to copy multiple files, so cache the computed source directory. | |
64 src_dir = os.path.join(win_sdk_dir, 'Debuggers', src_arch) | |
65 # Note that the outputs from the "copy_cdb_to_output" target need to | |
66 # be kept in sync with this list. | |
67 _CopyImpl('cdb.exe', output_dir, src_dir) | |
68 _CopyImpl('dbgeng.dll', output_dir, src_dir) | |
69 _CopyImpl('dbghelp.dll', output_dir, src_dir) | |
70 _CopyImpl('dbgmodel.dll', output_dir, src_dir) | |
71 return 0 | |
72 | |
73 | |
74 def main(): | |
75 if len(sys.argv) < 2: | |
76 print >>sys.stderr, 'Usage: copy_cdb_to_output.py <output_dir> ' + \ | |
77 '<target_arch>' | |
78 return 1 | |
79 return _CopyCDBToOutput(sys.argv[1], sys.argv[2]) | |
80 | |
81 | |
82 if __name__ == '__main__': | |
83 sys.exit(main()) | |
OLD | NEW |