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\... |
11 - C:\Program Files (x86)\Windows Kits\10\... | 11 - C:\Program Files (x86)\Windows Kits\10\... |
12 | 12 |
13 1. Start from a fresh Win7 VM image. | 13 1. Start from a fresh Win7 VM image. |
14 2. Install VS Pro. Deselect everything except MFC. | 14 2. Install VS Pro. Deselect everything except MFC. |
15 3. Install Windows 10 SDK. Select only the Windows SDK and Debugging Tools for | 15 3. Install Windows 10 SDK. Select only the Windows SDK and Debugging Tools for |
16 Windows. | 16 Windows. |
17 4. Run this script, which will build a <sha1>.zip. | 17 4. Run this script, which will build a <sha1>.zip. |
18 | 18 |
19 Express is not yet supported by this script, but patches welcome (it's not too | 19 Express is not yet supported by this script, but patches welcome (it's not too |
20 useful as the resulting zip can't be redistributed, and most will presumably | 20 useful as the resulting zip can't be redistributed, and most will presumably |
21 have a Pro license anyway). | 21 have a Pro license anyway). |
22 """ | 22 """ |
23 | 23 |
| 24 import collections |
24 import glob | 25 import glob |
| 26 import json |
25 import optparse | 27 import optparse |
26 import os | 28 import os |
27 import platform | 29 import platform |
28 import shutil | 30 import shutil |
29 import sys | 31 import sys |
30 import tempfile | 32 import tempfile |
31 import zipfile | 33 import zipfile |
32 | 34 |
33 import get_toolchain_if_necessary | 35 import get_toolchain_if_necessary |
34 | 36 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 ['..', '..', 'win_sdk', 'Include', WIN_VERSION, 'shared'], | 209 ['..', '..', 'win_sdk', 'Include', WIN_VERSION, 'shared'], |
208 ['..', '..', 'win_sdk', 'Include', WIN_VERSION, 'winrt'], | 210 ['..', '..', 'win_sdk', 'Include', WIN_VERSION, 'winrt'], |
209 ] | 211 ] |
210 if VS_VERSION == '2015': | 212 if VS_VERSION == '2015': |
211 include_dirs.append(['..', '..', 'win_sdk', 'Include', WIN_VERSION, 'ucrt']) | 213 include_dirs.append(['..', '..', 'win_sdk', 'Include', WIN_VERSION, 'ucrt']) |
212 include_dirs.extend([ | 214 include_dirs.extend([ |
213 ['..', '..', 'VC', 'include'], | 215 ['..', '..', 'VC', 'include'], |
214 ['..', '..', 'VC', 'atlmfc', 'include'], | 216 ['..', '..', 'VC', 'atlmfc', 'include'], |
215 ]) | 217 ]) |
216 # Common to x86 and x64 | 218 # Common to x86 and x64 |
217 env = [ | 219 env = collections.OrderedDict([ |
218 # Yuck: These two have a trailing \ character. No good way to represent this | 220 # Yuck: These two have a trailing \ character. No good way to represent this |
219 # in an OS-independent way. | 221 # in an OS-independent way. |
220 ('VSINSTALLDIR', [['..', '..\\']]), | 222 ('VSINSTALLDIR', [['..', '..\\']]), |
221 ('VCINSTALLDIR', [['..', '..', 'VC\\']]), | 223 ('VCINSTALLDIR', [['..', '..', 'VC\\']]), |
222 ('INCLUDE', include_dirs), | 224 ('INCLUDE', include_dirs), |
223 ] | 225 ]) |
224 # x86. Always use amd64_x86 cross, not x86 on x86. | 226 # x86. Always use amd64_x86 cross, not x86 on x86. |
225 env_x86 = [ | 227 env_x86 = collections.OrderedDict([ |
226 ('PATH', [ | 228 ('PATH', [ |
227 ['..', '..', 'win_sdk', 'bin', 'x86'], | 229 ['..', '..', 'win_sdk', 'bin', 'x86'], |
228 ['..', '..', 'VC', 'bin', 'amd64_x86'], | 230 ['..', '..', 'VC', 'bin', 'amd64_x86'], |
229 ['..', '..', 'VC', 'bin', 'amd64'], # Needed for mspdb1x0.dll. | 231 ['..', '..', 'VC', 'bin', 'amd64'], # Needed for mspdb1x0.dll. |
230 ]), | 232 ]), |
231 ('LIB', [ | 233 ('LIB', [ |
232 ['..', '..', 'VC', 'lib'], | 234 ['..', '..', 'VC', 'lib'], |
233 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'um', 'x86'], | 235 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'um', 'x86'], |
234 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'ucrt', 'x86'], # VS 2015 | 236 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'ucrt', 'x86'], # VS 2015 |
235 ['..', '..', 'VC', 'atlmfc', 'lib'], | 237 ['..', '..', 'VC', 'atlmfc', 'lib'], |
236 ]), | 238 ]), |
237 ] | 239 ]) |
238 # x64. | 240 # x64. |
239 env_x64 = [ | 241 env_x64 = collections.OrderedDict([ |
240 ('PATH', [ | 242 ('PATH', [ |
241 ['..', '..', 'win_sdk', 'bin', 'x64'], | 243 ['..', '..', 'win_sdk', 'bin', 'x64'], |
242 ['..', '..', 'VC', 'bin', 'amd64'], | 244 ['..', '..', 'VC', 'bin', 'amd64'], |
243 ]), | 245 ]), |
244 ('LIB', [ | 246 ('LIB', [ |
245 ['..', '..', 'VC', 'lib', 'amd64'], | 247 ['..', '..', 'VC', 'lib', 'amd64'], |
246 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'um', 'x64'], | 248 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'um', 'x64'], |
247 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'ucrt', 'x64'], # VS 2015 | 249 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'ucrt', 'x64'], # VS 2015 |
248 ['..', '..', 'VC', 'atlmfc', 'lib', 'amd64'], | 250 ['..', '..', 'VC', 'atlmfc', 'lib', 'amd64'], |
249 ]), | 251 ]), |
250 ] | 252 ]) |
251 def BatDirs(dirs): | 253 def BatDirs(dirs): |
252 return ';'.join(['%~dp0' + os.path.join(*d) for d in dirs]) | 254 return ';'.join(['%~dp0' + os.path.join(*d) for d in dirs]) |
253 with open(os.path.join(target_dir, r'win_sdk\bin\SetEnv.cmd'), 'w') as f: | 255 set_env_prefix = os.path.join(target_dir, r'win_sdk\bin\SetEnv') |
| 256 with open(set_env_prefix + '.cmd', 'w') as f: |
254 f.write('@echo off\n' | 257 f.write('@echo off\n' |
255 ':: Generated by win_toolchain\\package_from_installed.py.\n') | 258 ':: Generated by win_toolchain\\package_from_installed.py.\n') |
256 for var, dirs in env: | 259 for var, dirs in env.iteritems(): |
257 f.write('set %s=%s\n' % (var, BatDirs(dirs))) | 260 f.write('set %s=%s\n' % (var, BatDirs(dirs))) |
258 f.write('if "%1"=="/x64" goto x64\n') | 261 f.write('if "%1"=="/x64" goto x64\n') |
259 | 262 |
260 for var, dirs in env_x86: | 263 for var, dirs in env_x86.iteritems(): |
261 f.write('set %s=%s%s\n' % ( | 264 f.write('set %s=%s%s\n' % ( |
262 var, BatDirs(dirs), ';%PATH%' if var == 'PATH' else '')) | 265 var, BatDirs(dirs), ';%PATH%' if var == 'PATH' else '')) |
263 f.write('goto :EOF\n') | 266 f.write('goto :EOF\n') |
264 | 267 |
265 f.write(':x64\n') | 268 f.write(':x64\n') |
266 for var, dirs in env_x64: | 269 for var, dirs in env_x64.iteritems(): |
267 f.write('set %s=%s%s\n' % ( | 270 f.write('set %s=%s%s\n' % ( |
268 var, BatDirs(dirs), ';%PATH%' if var == 'PATH' else '')) | 271 var, BatDirs(dirs), ';%PATH%' if var == 'PATH' else '')) |
| 272 with open(set_env_prefix + '.x86.json', 'wb') as f: |
| 273 assert not set(env.keys()) & set(env_x86.keys()), 'dupe keys' |
| 274 json.dump(collections.OrderedDict(env.items() + env_x86.items()), f) |
| 275 with open(set_env_prefix + '.x64.json', 'wb') as f: |
| 276 assert not set(env.keys()) & set(env_x64.keys()), 'dupe keys' |
| 277 json.dump(collections.OrderedDict(env.items() + env_x64.items()), f) |
269 | 278 |
270 | 279 |
271 def AddEnvSetup(files): | 280 def AddEnvSetup(files): |
272 """We need to generate this file in the same way that the "from pieces" | 281 """We need to generate this file in the same way that the "from pieces" |
273 script does, so pull that in here.""" | 282 script does, so pull that in here.""" |
274 tempdir = tempfile.mkdtemp() | 283 tempdir = tempfile.mkdtemp() |
275 os.makedirs(os.path.join(tempdir, 'win_sdk', 'bin')) | 284 os.makedirs(os.path.join(tempdir, 'win_sdk', 'bin')) |
276 GenerateSetEnvCmd(tempdir) | 285 GenerateSetEnvCmd(tempdir) |
277 files.append((os.path.join(tempdir, 'win_sdk', 'bin', 'SetEnv.cmd'), | 286 files.append((os.path.join(tempdir, 'win_sdk', 'bin', 'SetEnv.cmd'), |
278 'win_sdk\\bin\\SetEnv.cmd')) | 287 'win_sdk\\bin\\SetEnv.cmd')) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 sys.stdout.write('\rWrote to %s.%s\n' % (output, ' '*50)) | 379 sys.stdout.write('\rWrote to %s.%s\n' % (output, ' '*50)) |
371 sys.stdout.flush() | 380 sys.stdout.flush() |
372 | 381 |
373 RenameToSha1(output) | 382 RenameToSha1(output) |
374 | 383 |
375 return 0 | 384 return 0 |
376 | 385 |
377 | 386 |
378 if __name__ == '__main__': | 387 if __name__ == '__main__': |
379 sys.exit(main()) | 388 sys.exit(main()) |
OLD | NEW |