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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 'arm64\\' not in f.lower() and | 194 'arm64\\' not in f.lower() and |
195 not f.lower().endswith('.msi')] | 195 not f.lower().endswith('.msi')] |
196 | 196 |
197 | 197 |
198 def GenerateSetEnvCmd(target_dir): | 198 def GenerateSetEnvCmd(target_dir): |
199 """Generate a batch file that gyp expects to exist to set up the compiler | 199 """Generate a batch file that gyp expects to exist to set up the compiler |
200 environment. | 200 environment. |
201 | 201 |
202 This is normally generated by a full install of the SDK, but we | 202 This is normally generated by a full install of the SDK, but we |
203 do it here manually since we do not do a full install.""" | 203 do it here manually since we do not do a full install.""" |
204 with open(os.path.join( | 204 # All these paths are relative to the directory containing SetEnv.cmd. |
205 target_dir, r'win_sdk\bin\SetEnv.cmd'), 'w') as f: | 205 include_dirs = [ |
| 206 ['..', '..', 'win_sdk', 'Include', WIN_VERSION, 'um'], |
| 207 ['..', '..', 'win_sdk', 'Include', WIN_VERSION, 'shared'], |
| 208 ['..', '..', 'win_sdk', 'Include', WIN_VERSION, 'winrt'], |
| 209 ] |
| 210 if VS_VERSION == '2015': |
| 211 include_dirs.append(['..', '..', 'win_sdk', 'Include', WIN_VERSION, 'ucrt']) |
| 212 include_dirs.extend([ |
| 213 ['..', '..', 'VC', 'include'], |
| 214 ['..', '..', 'VC', 'atlmfc', 'include'], |
| 215 ]) |
| 216 # Common to x86 and x64 |
| 217 env = [ |
| 218 # Yuck: These two have a trailing \ character. No good way to represent this |
| 219 # in an OS-independent way. |
| 220 ('VSINSTALLDIR', [['..', '..\\']]), |
| 221 ('VCINSTALLDIR', [['..', '..', 'VC\\']]), |
| 222 ('INCLUDE', include_dirs), |
| 223 ] |
| 224 # x86. Always use amd64_x86 cross, not x86 on x86. |
| 225 env_x86 = [ |
| 226 ('PATH', [ |
| 227 ['..', '..', 'win_sdk', 'bin', 'x86'], |
| 228 ['..', '..', 'VC', 'bin', 'amd64_x86'], |
| 229 ['..', '..', 'VC', 'bin', 'amd64'], # Needed for mspdb1x0.dll. |
| 230 ]), |
| 231 ('LIB', [ |
| 232 ['..', '..', 'VC', 'lib'], |
| 233 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'um', 'x86'], |
| 234 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'ucrt', 'x86'], # VS 2015 |
| 235 ['..', '..', 'VC', 'atlmfc', 'lib'], |
| 236 ]), |
| 237 ] |
| 238 # x64. |
| 239 env_x64 = [ |
| 240 ('PATH', [ |
| 241 ['..', '..', 'win_sdk', 'bin', 'x64'], |
| 242 ['..', '..', 'VC', 'bin', 'amd64'], |
| 243 ]), |
| 244 ('LIB', [ |
| 245 ['..', '..', 'VC', 'lib', 'amd64'], |
| 246 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'um', 'x64'], |
| 247 ['..', '..', 'win_sdk', 'Lib', WIN_VERSION, 'ucrt', 'x64'], # VS 2015 |
| 248 ['..', '..', 'VC', 'atlmfc', 'lib', 'amd64'], |
| 249 ]), |
| 250 ] |
| 251 def BatDirs(dirs): |
| 252 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: |
206 f.write('@echo off\n' | 254 f.write('@echo off\n' |
207 ':: Generated by win_toolchain\\package_from_installed.py.\n' | 255 ':: Generated by win_toolchain\\package_from_installed.py.\n') |
208 # Common to x86 and x64 | 256 for var, dirs in env: |
209 'set VSINSTALLDIR=%~dp0..\\..\\\n' | 257 f.write('set %s=%s\n' % (var, BatDirs(dirs))) |
210 'set VCINSTALLDIR=%~dp0..\\..\\VC\\\n' | 258 f.write('if "%1"=="/x64" goto x64\n') |
211 'set INCLUDE=%~dp0..\\..\\win_sdk\\Include\\WINVERSION\\um;' | |
212 '%~dp0..\\..\\win_sdk\\Include\\WINVERSION\\shared;' | |
213 '%~dp0..\\..\\win_sdk\\Include\\WINVERSION\\winrt;'.replace( | |
214 'WINVERSION', WIN_VERSION)) | |
215 if VS_VERSION == '2015': | |
216 f.write('%~dp0..\\..\\win_sdk\\Include\\WINVERSION\\ucrt;'.replace( | |
217 'WINVERSION', WIN_VERSION)) | |
218 f.write('%~dp0..\\..\\VC\\include;' | |
219 '%~dp0..\\..\\VC\\atlmfc\\include\n' | |
220 'if "%1"=="/x64" goto x64\n') | |
221 | 259 |
222 # x86. Always use amd64_x86 cross, not x86 on x86. | 260 for var, dirs in env_x86: |
223 f.write('set PATH=%~dp0..\\..\\win_sdk\\bin\\x86;' | 261 f.write('set %s=%s%s\n' % ( |
224 '%~dp0..\\..\\VC\\bin\\amd64_x86;' | 262 var, BatDirs(dirs), ';%PATH%' if var == 'PATH' else '')) |
225 '%~dp0..\\..\\VC\\bin\\amd64;' # Needed for mspdb1x0.dll. | 263 f.write('goto :EOF\n') |
226 '%PATH%\n') | |
227 f.write('set LIB=%~dp0..\\..\\VC\\lib;' | |
228 '%~dp0..\\..\\win_sdk\\Lib\\WINVERSION\\um\\x86;' | |
229 '%~dp0..\\..\\win_sdk\\Lib\\WINVERSION\\ucrt\\x86;' # VS 2015 | |
230 '%~dp0..\\..\\VC\\atlmfc\\lib\n' | |
231 'goto :EOF\n'.replace('WINVERSION', WIN_VERSION)) | |
232 | 264 |
233 # x64. | 265 f.write(':x64\n') |
234 f.write(':x64\n' | 266 for var, dirs in env_x64: |
235 'set PATH=%~dp0..\\..\\win_sdk\\bin\\x64;' | 267 f.write('set %s=%s%s\n' % ( |
236 '%~dp0..\\..\\VC\\bin\\amd64;' | 268 var, BatDirs(dirs), ';%PATH%' if var == 'PATH' else '')) |
237 '%PATH%\n') | |
238 f.write('set LIB=%~dp0..\\..\\VC\\lib\\amd64;' | |
239 '%~dp0..\\..\\win_sdk\\Lib\\WINVERSION\\um\\x64;' | |
240 '%~dp0..\\..\\win_sdk\\Lib\\WINVERSION\\ucrt\\x64;' # VS 2015 | |
241 '%~dp0..\\..\\VC\\atlmfc\\lib\\amd64\n' | |
242 .replace('WINVERSION', WIN_VERSION)) | |
243 | 269 |
244 | 270 |
245 def AddEnvSetup(files): | 271 def AddEnvSetup(files): |
246 """We need to generate this file in the same way that the "from pieces" | 272 """We need to generate this file in the same way that the "from pieces" |
247 script does, so pull that in here.""" | 273 script does, so pull that in here.""" |
248 tempdir = tempfile.mkdtemp() | 274 tempdir = tempfile.mkdtemp() |
249 os.makedirs(os.path.join(tempdir, 'win_sdk', 'bin')) | 275 os.makedirs(os.path.join(tempdir, 'win_sdk', 'bin')) |
250 GenerateSetEnvCmd(tempdir) | 276 GenerateSetEnvCmd(tempdir) |
251 files.append((os.path.join(tempdir, 'win_sdk', 'bin', 'SetEnv.cmd'), | 277 files.append((os.path.join(tempdir, 'win_sdk', 'bin', 'SetEnv.cmd'), |
252 'win_sdk\\bin\\SetEnv.cmd')) | 278 'win_sdk\\bin\\SetEnv.cmd')) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 sys.stdout.write('\rWrote to %s.%s\n' % (output, ' '*50)) | 370 sys.stdout.write('\rWrote to %s.%s\n' % (output, ' '*50)) |
345 sys.stdout.flush() | 371 sys.stdout.flush() |
346 | 372 |
347 RenameToSha1(output) | 373 RenameToSha1(output) |
348 | 374 |
349 return 0 | 375 return 0 |
350 | 376 |
351 | 377 |
352 if __name__ == '__main__': | 378 if __name__ == '__main__': |
353 sys.exit(main()) | 379 sys.exit(main()) |
OLD | NEW |