OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """ | 5 """ |
6 From a system-installed copy of the toolchain, packages all the required bits | 6 From a system-installed copy of the toolchain, packages all the required bits |
7 into a .zip file. | 7 into a .zip file. |
8 | 8 |
9 It assumes default install locations for tools, in particular: | 9 It assumes default install locations for tools, in particular: |
10 - C:\Program Files (x86)\Microsoft Visual Studio 12.0\... | 10 - C:\Program Files (x86)\Microsoft Visual Studio 12.0\... |
(...skipping 10 matching lines...) Expand all Loading... |
21 have a Pro license anyway). | 21 have a Pro license anyway). |
22 """ | 22 """ |
23 | 23 |
24 import os | 24 import os |
25 import shutil | 25 import shutil |
26 import sys | 26 import sys |
27 import tempfile | 27 import tempfile |
28 import zipfile | 28 import zipfile |
29 | 29 |
30 import get_toolchain_if_necessary | 30 import get_toolchain_if_necessary |
31 import toolchain2013 # pylint: disable=F0401 | 31 |
| 32 |
| 33 VS_VERSION = None |
32 | 34 |
33 | 35 |
34 def BuildFileList(): | 36 def BuildFileList(): |
35 result = [] | 37 result = [] |
36 | 38 |
37 # Subset of VS corresponding roughly to VC. | 39 # Subset of VS corresponding roughly to VC. |
38 vs_path = r'C:\Program Files (x86)\Microsoft Visual Studio 12.0' | 40 paths = [ |
39 for path in [ | |
40 'DIA SDK/bin', | 41 'DIA SDK/bin', |
41 'DIA SDK/idl', | 42 'DIA SDK/idl', |
42 'DIA SDK/include', | 43 'DIA SDK/include', |
43 'DIA SDK/lib', | 44 'DIA SDK/lib', |
44 'VC/atlmfc', | 45 'VC/atlmfc', |
45 'VC/bin', | 46 'VC/bin', |
46 'VC/crt', | 47 'VC/crt', |
47 'VC/include', | 48 'VC/include', |
48 'VC/lib', | 49 'VC/lib', |
49 'VC/redist', | 50 'VC/redist', |
50 ('VC/redist/x86/Microsoft.VC120.CRT', 'sys32'), | 51 ] |
51 ('VC/redist/x86/Microsoft.VC120.MFC', 'sys32'), | 52 |
52 ('VC/redist/Debug_NonRedist/x86/Microsoft.VC120.DebugCRT', 'sys32'), | 53 if VS_VERSION == '2013': |
53 ('VC/redist/Debug_NonRedist/x86/Microsoft.VC120.DebugMFC', 'sys32'), | 54 paths += [ |
54 ('VC/redist/x64/Microsoft.VC120.CRT', 'sys64'), | 55 ('VC/redist/x86/Microsoft.VC120.CRT', 'sys32'), |
55 ('VC/redist/x64/Microsoft.VC120.MFC', 'sys64'), | 56 ('VC/redist/x86/Microsoft.VC120.MFC', 'sys32'), |
56 ('VC/redist/Debug_NonRedist/x64/Microsoft.VC120.DebugCRT', 'sys64'), | 57 ('VC/redist/Debug_NonRedist/x86/Microsoft.VC120.DebugCRT', 'sys32'), |
57 ('VC/redist/Debug_NonRedist/x64/Microsoft.VC120.DebugMFC', 'sys64'), | 58 ('VC/redist/Debug_NonRedist/x86/Microsoft.VC120.DebugMFC', 'sys32'), |
58 ]: | 59 ('VC/redist/x64/Microsoft.VC120.CRT', 'sys64'), |
| 60 ('VC/redist/x64/Microsoft.VC120.MFC', 'sys64'), |
| 61 ('VC/redist/Debug_NonRedist/x64/Microsoft.VC120.DebugCRT', 'sys64'), |
| 62 ('VC/redist/Debug_NonRedist/x64/Microsoft.VC120.DebugMFC', 'sys64'), |
| 63 ] |
| 64 elif VS_VERSION == '2015': |
| 65 paths += [ |
| 66 ('VC/redist/x86/Microsoft.VC140.CRT', 'sys32'), |
| 67 ('VC/redist/x86/Microsoft.VC140.MFC', 'sys32'), |
| 68 ('VC/redist/debug_nonredist/x86/Microsoft.VC140.DebugCRT', 'sys32'), |
| 69 ('VC/redist/debug_nonredist/x86/Microsoft.VC140.DebugMFC', 'sys32'), |
| 70 ('VC/redist/x64/Microsoft.VC140.CRT', 'sys64'), |
| 71 ('VC/redist/x64/Microsoft.VC140.MFC', 'sys64'), |
| 72 ('VC/redist/debug_nonredist/x64/Microsoft.VC140.DebugCRT', 'sys64'), |
| 73 ('VC/redist/debug_nonredist/x64/Microsoft.VC140.DebugMFC', 'sys64'), |
| 74 ] |
| 75 else: |
| 76 raise ValueError('VS_VERSION %s' % VS_VERSION) |
| 77 |
| 78 if VS_VERSION == '2013': |
| 79 vs_path = r'C:\Program Files (x86)\Microsoft Visual Studio 12.0' |
| 80 else: |
| 81 vs_path = r'C:\Program Files (x86)\Microsoft Visual Studio 14.0' |
| 82 |
| 83 for path in paths: |
59 src = path[0] if isinstance(path, tuple) else path | 84 src = path[0] if isinstance(path, tuple) else path |
60 combined = os.path.join(vs_path, src) | 85 combined = os.path.join(vs_path, src) |
61 assert os.path.exists(combined) and os.path.isdir(combined) | 86 assert os.path.exists(combined) and os.path.isdir(combined) |
62 for root, _, files in os.walk(combined): | 87 for root, _, files in os.walk(combined): |
63 for f in files: | 88 for f in files: |
64 final_from = os.path.normpath(os.path.join(root, f)) | 89 final_from = os.path.normpath(os.path.join(root, f)) |
65 if isinstance(path, tuple): | 90 if isinstance(path, tuple): |
66 result.append( | 91 result.append( |
67 (final_from, os.path.normpath(os.path.join(path[1], f)))) | 92 (final_from, os.path.normpath(os.path.join(path[1], f)))) |
68 else: | 93 else: |
69 assert final_from.startswith(vs_path) | 94 assert final_from.startswith(vs_path) |
70 dest = final_from[len(vs_path) + 1:] | 95 dest = final_from[len(vs_path) + 1:] |
71 if dest.lower().endswith('\\xtree'): | 96 if VS_VERSION == '2013' and dest.lower().endswith('\\xtree'): |
72 # Patch for C4702 in xtree. http://crbug.com/346399. | 97 # Patch for C4702 in xtree on VS2013. http://crbug.com/346399. |
73 (handle, patched) = tempfile.mkstemp() | 98 (handle, patched) = tempfile.mkstemp() |
74 with open(final_from, 'rb') as unpatched_f: | 99 with open(final_from, 'rb') as unpatched_f: |
75 unpatched_contents = unpatched_f.read() | 100 unpatched_contents = unpatched_f.read() |
76 os.write(handle, | 101 os.write(handle, |
77 unpatched_contents.replace('warning(disable: 4127)', | 102 unpatched_contents.replace('warning(disable: 4127)', |
78 'warning(disable: 4127 4702)')) | 103 'warning(disable: 4127 4702)')) |
79 result.append((patched, dest)) | 104 result.append((patched, dest)) |
80 else: | 105 else: |
81 result.append((final_from, dest)) | 106 result.append((final_from, dest)) |
82 | 107 |
83 # Just copy the whole SDK. | 108 # Just copy the whole SDK. |
84 sdk_path = r'C:\Program Files (x86)\Windows Kits\8.1' | 109 sdk_path = r'C:\Program Files (x86)\Windows Kits\8.1' |
85 for root, _, files in os.walk(sdk_path): | 110 for root, _, files in os.walk(sdk_path): |
86 for f in files: | 111 for f in files: |
87 combined = os.path.normpath(os.path.join(root, f)) | 112 combined = os.path.normpath(os.path.join(root, f)) |
88 to = os.path.join('win8sdk', combined[len(sdk_path) + 1:]) | 113 to = os.path.join('win_sdk', combined[len(sdk_path) + 1:]) |
89 result.append((combined, to)) | 114 result.append((combined, to)) |
90 | 115 |
| 116 if VS_VERSION == '2015': |
| 117 for ucrt_path in ( |
| 118 (r'C:\Program Files (x86)\Windows Kits\10\Include', 'Include'), |
| 119 (r'C:\Program Files (x86)\Windows Kits\10\Lib', 'Lib'), |
| 120 (r'C:\Program Files (x86)\Windows Kits\10\Source', 'Source')): |
| 121 src, target = ucrt_path |
| 122 for root, _, files in os.walk(src): |
| 123 for f in files: |
| 124 combined = os.path.normpath(os.path.join(root, f)) |
| 125 to = os.path.join('ucrt', target, combined[len(src) + 1:]) |
| 126 result.append((combined, to)) |
| 127 |
91 # Generically drop all arm stuff that we don't need. | 128 # Generically drop all arm stuff that we don't need. |
92 return [(f, t) for f, t in result if 'arm\\' not in f.lower()] | 129 return [(f, t) for f, t in result if 'arm\\' not in f.lower() and |
| 130 'arm64\\' not in f.lower()] |
| 131 |
| 132 |
| 133 def GenerateSetEnvCmd(target_dir): |
| 134 """Generate a batch file that gyp expects to exist to set up the compiler |
| 135 environment. |
| 136 |
| 137 This is normally generated by a full install of the SDK, but we |
| 138 do it here manually since we do not do a full install.""" |
| 139 with open(os.path.join( |
| 140 target_dir, r'win_sdk\bin\SetEnv.cmd'), 'w') as f: |
| 141 f.write('@echo off\n' |
| 142 ':: Generated by win_toolchain\\package_from_installed.py.\n' |
| 143 # Common to x86 and x64 |
| 144 'set PATH=%~dp0..\\..\\Common7\\IDE;%PATH%\n' |
| 145 'set INCLUDE=%~dp0..\\..\\win_sdk\\Include\\um;' |
| 146 '%~dp0..\\..\\win_sdk\\Include\\shared;' |
| 147 '%~dp0..\\..\\win_sdk\\Include\\winrt;' |
| 148 '%~dp0..\\..\\ucrt\\Include\\10.0.10056.0\\ucrt;' |
| 149 '%~dp0..\\..\\VC\\include;' |
| 150 '%~dp0..\\..\\VC\\atlmfc\\include\n' |
| 151 'if "%1"=="/x64" goto x64\n') |
| 152 |
| 153 # x86. Always use amd64_x86 cross, not x86 on x86. |
| 154 f.write('set PATH=%~dp0..\\..\\win_sdk\\bin\\x86;' |
| 155 '%~dp0..\\..\\VC\\bin\\amd64_x86;' |
| 156 '%~dp0..\\..\\VC\\bin\\amd64;' # Needed for mspdb1x0.dll. |
| 157 '%PATH%\n') |
| 158 f.write('set LIB=%~dp0..\\..\\VC\\lib;' |
| 159 '%~dp0..\\..\\win_sdk\\Lib\\winv6.3\\um\\x86;' |
| 160 '%~dp0..\\..\\ucrt\\Lib\\10.0.10056.0\\ucrt\\x86;' |
| 161 '%~dp0..\\..\\VC\\atlmfc\\lib\n' |
| 162 'goto :EOF\n') |
| 163 |
| 164 # x64. |
| 165 f.write(':x64\n' |
| 166 'set PATH=%~dp0..\\..\\win_sdk\\bin\\x64;' |
| 167 '%~dp0..\\..\\VC\\bin\\amd64;' |
| 168 '%PATH%\n') |
| 169 f.write('set LIB=%~dp0..\\..\\VC\\lib\\amd64;' |
| 170 '%~dp0..\\..\\win_sdk\\Lib\\winv6.3\\um\\x64;' |
| 171 '%~dp0..\\..\\ucrt\\Lib\\10.0.10056.0\\ucrt\\x64;' |
| 172 '%~dp0..\\..\\VC\\atlmfc\\lib\\amd64\n') |
93 | 173 |
94 | 174 |
95 def AddEnvSetup(files): | 175 def AddEnvSetup(files): |
96 """We need to generate this file in the same way that the "from pieces" | 176 """We need to generate this file in the same way that the "from pieces" |
97 script does, so pull that in here.""" | 177 script does, so pull that in here.""" |
98 tempdir = tempfile.mkdtemp() | 178 tempdir = tempfile.mkdtemp() |
99 os.makedirs(os.path.join(tempdir, 'win8sdk', 'bin')) | 179 os.makedirs(os.path.join(tempdir, 'win_sdk', 'bin')) |
100 toolchain2013.GenerateSetEnvCmd(tempdir, True) | 180 GenerateSetEnvCmd(tempdir) |
101 files.append((os.path.join(tempdir, 'win8sdk', 'bin', 'SetEnv.cmd'), | 181 files.append((os.path.join(tempdir, 'win_sdk', 'bin', 'SetEnv.cmd'), |
102 'win8sdk\\bin\\SetEnv.cmd')) | 182 'win_sdk\\bin\\SetEnv.cmd')) |
| 183 vs_version_file = os.path.join(tempdir, 'VS_VERSION') |
| 184 with open(vs_version_file, 'wb') as version: |
| 185 print >>version, VS_VERSION |
| 186 files.append((vs_version_file, 'VS_VERSION')) |
103 | 187 |
104 | 188 |
105 def RenameToSha1(output): | 189 def RenameToSha1(output): |
106 """Determine the hash in the same way that the unzipper does to rename the | 190 """Determine the hash in the same way that the unzipper does to rename the |
107 # .zip file.""" | 191 # .zip file.""" |
108 print 'Extracting to determine hash...' | 192 print 'Extracting to determine hash...' |
109 tempdir = tempfile.mkdtemp() | 193 tempdir = tempfile.mkdtemp() |
110 old_dir = os.getcwd() | 194 old_dir = os.getcwd() |
111 os.chdir(tempdir) | 195 os.chdir(tempdir) |
112 rel_dir = 'vs2013_files' | 196 rel_dir = 'vs_files' |
113 with zipfile.ZipFile( | 197 with zipfile.ZipFile( |
114 os.path.join(old_dir, output), 'r', zipfile.ZIP_DEFLATED, True) as zf: | 198 os.path.join(old_dir, output), 'r', zipfile.ZIP_DEFLATED, True) as zf: |
115 zf.extractall(rel_dir) | 199 zf.extractall(rel_dir) |
116 print 'Hashing...' | 200 print 'Hashing...' |
117 sha1 = get_toolchain_if_necessary.CalculateHash(rel_dir) | 201 sha1 = get_toolchain_if_necessary.CalculateHash(rel_dir) |
118 os.chdir(old_dir) | 202 os.chdir(old_dir) |
119 shutil.rmtree(tempdir) | 203 shutil.rmtree(tempdir) |
120 final_name = sha1 + '.zip' | 204 final_name = sha1 + '.zip' |
121 os.rename(output, final_name) | 205 os.rename(output, final_name) |
122 print 'Renamed %s to %s.' % (output, final_name) | 206 print 'Renamed %s to %s.' % (output, final_name) |
123 | 207 |
124 | 208 |
125 def main(): | 209 def main(): |
| 210 if len(sys.argv) != 2 or sys.argv[1] not in ('2013', '2015'): |
| 211 print 'Usage: package_from_installed.py 2013|2015' |
| 212 return 1 |
| 213 |
| 214 global VS_VERSION |
| 215 VS_VERSION = sys.argv[1] |
| 216 |
126 print 'Building file list...' | 217 print 'Building file list...' |
127 files = BuildFileList() | 218 files = BuildFileList() |
128 | 219 |
129 AddEnvSetup(files) | 220 AddEnvSetup(files) |
130 | 221 |
131 if False: | 222 if False: |
132 for f in files: | 223 for f in files: |
133 print f[0], '->', f[1] | 224 print f[0], '->', f[1] |
134 return 0 | 225 return 0 |
135 | 226 |
(...skipping 10 matching lines...) Expand all Loading... |
146 sys.stdout.write('\rWrote to %s.%s\n' % (output, ' '*50)) | 237 sys.stdout.write('\rWrote to %s.%s\n' % (output, ' '*50)) |
147 sys.stdout.flush() | 238 sys.stdout.flush() |
148 | 239 |
149 RenameToSha1(output) | 240 RenameToSha1(output) |
150 | 241 |
151 return 0 | 242 return 0 |
152 | 243 |
153 | 244 |
154 if __name__ == '__main__': | 245 if __name__ == '__main__': |
155 sys.exit(main()) | 246 sys.exit(main()) |
OLD | NEW |