Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: build/vs_toolchain.py

Issue 2745863002: Only import gyp when required in vs_toolchain.py. (Closed)
Patch Set: ordering Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import glob 6 import glob
7 import json 7 import json
8 import os 8 import os
9 import pipes 9 import pipes
10 import platform 10 import platform
11 import shutil 11 import shutil
12 import stat 12 import stat
13 import subprocess 13 import subprocess
14 import sys 14 import sys
15 15
16 16
17 script_dir = os.path.dirname(os.path.realpath(__file__)) 17 script_dir = os.path.dirname(os.path.realpath(__file__))
18 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) 18 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
19 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 19 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
20 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) 20 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
21 json_data_file = os.path.join(script_dir, 'win_toolchain.json') 21 json_data_file = os.path.join(script_dir, 'win_toolchain.json')
22 22
23 23
24 import gyp
25
26
27 # Use MSVS2015 as the default toolchain. 24 # Use MSVS2015 as the default toolchain.
28 CURRENT_DEFAULT_TOOLCHAIN_VERSION = '2015' 25 CURRENT_DEFAULT_TOOLCHAIN_VERSION = '2015'
29 26
30 27
31 def SetEnvironmentAndGetRuntimeDllDirs(): 28 def SetEnvironmentAndGetRuntimeDllDirs():
32 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and 29 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and
33 returns the location of the VS runtime DLLs so they can be copied into 30 returns the location of the VS runtime DLLs so they can be copied into
34 the output directory after gyp generation. 31 the output directory after gyp generation.
35 32
36 Return value is [x64path, x86path] or None 33 Return value is [x64path, x86path] or None
(...skipping 16 matching lines...) Expand all
53 if not win_sdk: 50 if not win_sdk:
54 win_sdk = toolchain_data['win8sdk'] 51 win_sdk = toolchain_data['win8sdk']
55 wdk = toolchain_data['wdk'] 52 wdk = toolchain_data['wdk']
56 # TODO(scottmg): The order unfortunately matters in these. They should be 53 # TODO(scottmg): The order unfortunately matters in these. They should be
57 # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call 54 # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call
58 # below). http://crbug.com/345992 55 # below). http://crbug.com/345992
59 vs_runtime_dll_dirs = toolchain_data['runtime_dirs'] 56 vs_runtime_dll_dirs = toolchain_data['runtime_dirs']
60 57
61 os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain 58 os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
62 os.environ['GYP_MSVS_VERSION'] = version 59 os.environ['GYP_MSVS_VERSION'] = version
60
61 # Limit the scope of the gyp import to only where it is used. This
62 # potentially lets build configs that never execute this block to drop
63 # their GYP checkout.
64 import gyp
65
63 # We need to make sure windows_sdk_path is set to the automated 66 # We need to make sure windows_sdk_path is set to the automated
64 # toolchain values in GYP_DEFINES, but don't want to override any 67 # toolchain values in GYP_DEFINES, but don't want to override any
65 # otheroptions.express 68 # otheroptions.express
66 # values there. 69 # values there.
67 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES')) 70 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
68 gyp_defines_dict['windows_sdk_path'] = win_sdk 71 gyp_defines_dict['windows_sdk_path'] = win_sdk
69 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) 72 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v)))
70 for k, v in gyp_defines_dict.iteritems()) 73 for k, v in gyp_defines_dict.iteritems())
74
71 os.environ['WINDOWSSDKDIR'] = win_sdk 75 os.environ['WINDOWSSDKDIR'] = win_sdk
72 os.environ['WDK_DIR'] = wdk 76 os.environ['WDK_DIR'] = wdk
73 # Include the VS runtime in the PATH in case it's not machine-installed. 77 # Include the VS runtime in the PATH in case it's not machine-installed.
74 runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs) 78 runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs)
75 os.environ['PATH'] = runtime_path + os.path.pathsep + os.environ['PATH'] 79 os.environ['PATH'] = runtime_path + os.path.pathsep + os.environ['PATH']
76 elif sys.platform == 'win32' and not depot_tools_win_toolchain: 80 elif sys.platform == 'win32' and not depot_tools_win_toolchain:
77 if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ: 81 if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ:
78 os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath() 82 os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath()
79 if not 'GYP_MSVS_VERSION' in os.environ: 83 if not 'GYP_MSVS_VERSION' in os.environ:
80 os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion() 84 os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion()
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' 168 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)'
165 ' not found.') % (version_as_year)) 169 ' not found.') % (version_as_year))
166 170
167 171
168 def _VersionNumber(): 172 def _VersionNumber():
169 """Gets the standard version number ('120', '140', etc.) based on 173 """Gets the standard version number ('120', '140', etc.) based on
170 GYP_MSVS_VERSION.""" 174 GYP_MSVS_VERSION."""
171 vs_version = GetVisualStudioVersion() 175 vs_version = GetVisualStudioVersion()
172 if vs_version == '2013': 176 if vs_version == '2013':
173 return '120' 177 return '120'
174 elif vs_version == '2015': 178 if vs_version == '2015':
175 return '140' 179 return '140'
176 elif vs_version == '2017': 180 if vs_version == '2017':
177 return '150' 181 return '150'
178 else: 182 raise ValueError('Unexpected GYP_MSVS_VERSION')
179 raise ValueError('Unexpected GYP_MSVS_VERSION')
180 183
181 184
182 def _CopyRuntimeImpl(target, source, verbose=True): 185 def _CopyRuntimeImpl(target, source, verbose=True):
183 """Copy |source| to |target| if it doesn't already exist or if it needs to be 186 """Copy |source| to |target| if it doesn't already exist or if it needs to be
184 updated (comparing last modified time as an approximate float match as for 187 updated (comparing last modified time as an approximate float match as for
185 some reason the values tend to differ by ~1e-07 despite being copies of the 188 some reason the values tend to differ by ~1e-07 despite being copies of the
186 same file... https://crbug.com/603603). 189 same file... https://crbug.com/603603).
187 """ 190 """
188 if (os.path.isdir(os.path.dirname(target)) and 191 if (os.path.isdir(os.path.dirname(target)) and
189 (not os.path.isfile(target) or 192 (not os.path.isfile(target) or
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 336
334 for debug_file in debugger_files: 337 for debug_file in debugger_files:
335 full_path = os.path.join(win_sdk_dir, 'Debuggers', target_cpu, debug_file) 338 full_path = os.path.join(win_sdk_dir, 'Debuggers', target_cpu, debug_file)
336 target_path = os.path.join(target_dir, debug_file) 339 target_path = os.path.join(target_dir, debug_file)
337 _CopyRuntimeImpl(target_path, full_path) 340 _CopyRuntimeImpl(target_path, full_path)
338 341
339 342
340 def _GetDesiredVsToolchainHashes(): 343 def _GetDesiredVsToolchainHashes():
341 """Load a list of SHA1s corresponding to the toolchains that we want installed 344 """Load a list of SHA1s corresponding to the toolchains that we want installed
342 to build with.""" 345 to build with."""
343 if GetVisualStudioVersion() == '2015': 346 env_version = GetVisualStudioVersion()
347 if env_version == '2013':
348 return ['03a4e939cd325d6bc5216af41b92d02dda1366a6']
349 if env_version == '2015':
344 # Update 3 final with patches with 10.0.14393.0 SDK. 350 # Update 3 final with patches with 10.0.14393.0 SDK.
345 return ['d3cb0e37bdd120ad0ac4650b674b09e81be45616'] 351 return ['d3cb0e37bdd120ad0ac4650b674b09e81be45616']
346 elif GetVisualStudioVersion() == '2013': 352 raise Exception('Unsupported VS version %s' % env_version)
347 return ['03a4e939cd325d6bc5216af41b92d02dda1366a6']
348 else:
349 raise Exception('Unsupported VS version %s' % GetVisualStudioVersion())
350 353
351 354
352 def ShouldUpdateToolchain(): 355 def ShouldUpdateToolchain():
353 """Check if the toolchain should be upgraded.""" 356 """Check if the toolchain should be upgraded."""
354 if not os.path.exists(json_data_file): 357 if not os.path.exists(json_data_file):
355 return True 358 return True
356 with open(json_data_file, 'r') as tempf: 359 with open(json_data_file, 'r') as tempf:
357 toolchain_data = json.load(tempf) 360 toolchain_data = json.load(tempf)
358 version = toolchain_data['version'] 361 version = toolchain_data['version']
359 env_version = GetVisualStudioVersion() 362 env_version = GetVisualStudioVersion()
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 'copy_dlls': CopyDlls, 445 'copy_dlls': CopyDlls,
443 } 446 }
444 if len(sys.argv) < 2 or sys.argv[1] not in commands: 447 if len(sys.argv) < 2 or sys.argv[1] not in commands:
445 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) 448 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands)
446 return 1 449 return 1
447 return commands[sys.argv[1]](*sys.argv[2:]) 450 return commands[sys.argv[1]](*sys.argv[2:])
448 451
449 452
450 if __name__ == '__main__': 453 if __name__ == '__main__':
451 sys.exit(main()) 454 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698