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 glob | |
7 import hashlib | |
8 import os | |
9 import shutil | |
10 import sys | |
11 | |
12 script_dir = os.path.dirname(os.path.realpath(__file__)) | |
13 src_build_dir = os.path.abspath(os.path.join(script_dir, os.pardir)) | |
14 sys.path.insert(0, src_build_dir) | |
15 | |
16 import vs_toolchain | |
17 | |
18 | |
19 def _HexDigest(file_name): | |
20 hasher = hashlib.sha256() | |
21 afile = open(file_name, 'rb') | |
22 blocksize = 65536 | |
23 buf = afile.read(blocksize) | |
24 while len(buf) > 0: | |
25 hasher.update(buf) | |
26 buf = afile.read(blocksize) | |
27 afile.close() | |
28 return hasher.hexdigest() | |
29 | |
30 | |
31 def _CopyImpl(file_name, target_dir, source_dir, verbose=False): | |
32 """Copy |source| to |target| if it doesn't already exist or if it | |
33 needs to be updated. | |
34 """ | |
35 target = os.path.join(target_dir, file_name) | |
36 source = os.path.join(source_dir, file_name) | |
37 if (os.path.isdir(os.path.dirname(target)) and | |
38 ((not os.path.isfile(target)) or | |
39 _HexDigest(source) != _HexDigest(target))): | |
40 if verbose: | |
41 print 'Copying %s to %s...' % (source, target) | |
42 if os.path.exists(target): | |
43 os.unlink(target) | |
44 shutil.copy(source, target) | |
45 | |
46 | |
47 def _ConditionalMkdir(output_dir): | |
48 if not os.path.isdir(output_dir): | |
49 os.makedirs(output_dir) | |
50 | |
51 | |
52 def _CopyCDBToOutput(output_dir, target_arch): | |
53 """Copies the Windows debugging executable cdb.exe to the output | |
54 directory, which is created if it does not exist. The output | |
55 directory, and target architecture that should be copied, are | |
56 passed. Supported values for the target architecture are the GYP | |
57 values "ia32" and "x64" and the GN values "x86" and "x64". | |
58 """ | |
59 _ConditionalMkdir(output_dir) | |
60 vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs() | |
61 # If WINDOWSSDKDIR is not set use the default SDK path. This will be the case | |
62 # when DEPOT_TOOLS_WIN_TOOLCHAIN=0 and vcvarsall.bat has not been run. | |
63 win_sdk_dir = os.path.normpath( | |
64 os.environ.get('WINDOWSSDKDIR', | |
65 'C:\\Program Files (x86)\\Windows Kits\\10')) | |
66 if target_arch == 'ia32' or target_arch == 'x86': | |
67 src_arch = 'x86' | |
68 elif target_arch == 'x64': | |
69 src_arch = 'x64' | |
70 else: | |
71 print 'copy_cdb_to_output.py: unknown target_arch %s' % target_arch | |
72 sys.exit(1) | |
73 # We need to copy multiple files, so cache the computed source directory. | |
74 src_dir = os.path.join(win_sdk_dir, 'Debuggers', src_arch) | |
75 # We need to copy some helper DLLs to get access to the !uniqstack | |
76 # command to dump all threads' stacks. | |
77 src_winext_dir = os.path.join(src_dir, 'winext') | |
78 dst_winext_dir = os.path.join(output_dir, 'winext') | |
79 src_winxp_dir = os.path.join(src_dir, 'winxp') | |
80 dst_winxp_dir = os.path.join(output_dir, 'winxp') | |
81 src_crt_dir = os.path.join(win_sdk_dir, r'Redist\ucrt\DLLs', src_arch) | |
82 _ConditionalMkdir(dst_winext_dir) | |
83 _ConditionalMkdir(dst_winxp_dir) | |
84 # Note that the outputs from the "copy_cdb_to_output" target need to | |
85 # be kept in sync with this list. | |
86 _CopyImpl('cdb.exe', output_dir, src_dir) | |
87 _CopyImpl('dbgeng.dll', output_dir, src_dir) | |
88 _CopyImpl('dbghelp.dll', output_dir, src_dir) | |
89 _CopyImpl('dbgmodel.dll', output_dir, src_dir) | |
90 _CopyImpl('ext.dll', dst_winext_dir, src_winext_dir) | |
91 _CopyImpl('uext.dll', dst_winext_dir, src_winext_dir) | |
92 _CopyImpl('exts.dll', dst_winxp_dir, src_winxp_dir) | |
93 _CopyImpl('ntsdexts.dll', dst_winxp_dir, src_winxp_dir) | |
94 for dll_path in glob.glob(os.path.join(src_crt_dir, 'api-ms-win-*.dll')): | |
95 _CopyImpl(os.path.split(dll_path)[1], output_dir, src_crt_dir) | |
96 _CopyImpl('ucrtbase.dll', output_dir, src_crt_dir) | |
97 return 0 | |
98 | |
99 | |
100 def main(): | |
101 if len(sys.argv) < 2: | |
102 print >>sys.stderr, 'Usage: copy_cdb_to_output.py <output_dir> ' + \ | |
103 '<target_arch>' | |
104 return 1 | |
105 return _CopyCDBToOutput(sys.argv[1], sys.argv[2]) | |
106 | |
107 | |
108 if __name__ == '__main__': | |
109 sys.exit(main()) | |
OLD | NEW |