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

Side by Side Diff: build/vs_toolchain.py

Issue 1580703002: Ensure GYP_MSVS_VERSION is set for GN build. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new helper GetVisualStudioVersion() Created 4 years, 11 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 json 6 import json
7 import os 7 import os
8 import pipes 8 import pipes
9 import shutil 9 import shutil
10 import subprocess 10 import subprocess
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 return None 91 return None
92 92
93 93
94 def _RegistryGetValue(key, value): 94 def _RegistryGetValue(key, value):
95 try: 95 try:
96 return _RegistryGetValueUsingWinReg(key, value) 96 return _RegistryGetValueUsingWinReg(key, value)
97 except ImportError: 97 except ImportError:
98 raise Exception('The python library _winreg not found.') 98 raise Exception('The python library _winreg not found.')
99 99
100 100
101 def GetVisualStudioVersion():
102 """Return GYP_MSVS_VERSION of Visual Studio, default to 2013 for now.
103 """
104
scottmg 2016/01/12 20:56:44 Remove blank line.
105 return os.environ.get('GYP_MSVS_VERSION', '2013')
106
107
101 def DetectVisualStudioPath(): 108 def DetectVisualStudioPath():
102 """Return path to the GYP_MSVS_VERSION of Visual Studio. 109 """Return path to the GYP_MSVS_VERSION of Visual Studio.
103 """ 110 """
104 111
105 # Note that this code is used from 112 # Note that this code is used from
106 # build/toolchain/win/setup_toolchain.py as well. 113 # build/toolchain/win/setup_toolchain.py as well.
107 114
108 # Default to Visual Studio 2013 for now. 115 # Default to Visual Studio 2013 for now.
scottmg 2016/01/12 20:56:44 Remove this comment, it's in the function body now
109 version_as_year = os.environ.get('GYP_MSVS_VERSION', '2013') 116 version_as_year = GetVisualStudioVersion()
110 year_to_version = { 117 year_to_version = {
111 '2013': '12.0', 118 '2013': '12.0',
112 '2015': '14.0', 119 '2015': '14.0',
113 } 120 }
114 if version_as_year not in year_to_version: 121 if version_as_year not in year_to_version:
115 raise Exception(('Visual Studio version %s (from GYP_MSVS_VERSION)' 122 raise Exception(('Visual Studio version %s (from GYP_MSVS_VERSION)'
116 ' not supported. Supported versions are: %s') % ( 123 ' not supported. Supported versions are: %s') % (
117 version_as_year, ', '.join(year_to_version.keys()))) 124 version_as_year, ', '.join(year_to_version.keys())))
118 version = year_to_version[version_as_year] 125 version = year_to_version[version_as_year]
119 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, 126 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version,
120 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version] 127 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version]
121 for key in keys: 128 for key in keys:
122 path = _RegistryGetValue(key, 'InstallDir') 129 path = _RegistryGetValue(key, 'InstallDir')
123 if not path: 130 if not path:
124 continue 131 continue
125 path = os.path.normpath(os.path.join(path, '..', '..')) 132 path = os.path.normpath(os.path.join(path, '..', '..'))
126 return path 133 return path
127 134
128 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' 135 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)'
129 ' not found.') % (version_as_year)) 136 ' not found.') % (version_as_year))
130 137
131 138
132 def _VersionNumber(): 139 def _VersionNumber():
133 """Gets the standard version number ('120', '140', etc.) based on 140 """Gets the standard version number ('120', '140', etc.) based on
134 GYP_MSVS_VERSION.""" 141 GYP_MSVS_VERSION."""
135 if os.environ['GYP_MSVS_VERSION'] == '2013': 142 vs_version = GetVisualStudioVersion()
143 if vs_version == '2013':
136 return '120' 144 return '120'
137 elif os.environ['GYP_MSVS_VERSION'] == '2015': 145 elif vs_version == '2015':
138 return '140' 146 return '140'
139 else: 147 else:
140 raise ValueError('Unexpected GYP_MSVS_VERSION') 148 raise ValueError('Unexpected GYP_MSVS_VERSION')
141 149
142 150
143 def _CopyRuntimeImpl(target, source): 151 def _CopyRuntimeImpl(target, source):
144 """Copy |source| to |target| if it doesn't already exist or if it 152 """Copy |source| to |target| if it doesn't already exist or if it
145 needs to be updated. 153 needs to be updated.
146 """ 154 """
147 if (os.path.isdir(os.path.dirname(target)) and 155 if (os.path.isdir(os.path.dirname(target)) and
(...skipping 22 matching lines...) Expand all
170 dll = dll_pattern % file_part 178 dll = dll_pattern % file_part
171 target = os.path.join(target_dir, dll) 179 target = os.path.join(target_dir, dll)
172 source = os.path.join(source_dir, dll) 180 source = os.path.join(source_dir, dll)
173 _CopyRuntimeImpl(target, source) 181 _CopyRuntimeImpl(target, source)
174 182
175 183
176 def _CopyRuntime(target_dir, source_dir, target_cpu, debug): 184 def _CopyRuntime(target_dir, source_dir, target_cpu, debug):
177 """Copy the VS runtime DLLs, only if the target doesn't exist, but the target 185 """Copy the VS runtime DLLs, only if the target doesn't exist, but the target
178 directory does exist. Handles VS 2013 and VS 2015.""" 186 directory does exist. Handles VS 2013 and VS 2015."""
179 suffix = "d.dll" if debug else ".dll" 187 suffix = "d.dll" if debug else ".dll"
180 if os.environ.get('GYP_MSVS_VERSION') == '2015': 188 if GetVisualStudioVersion() == '2015':
181 _CopyRuntime2015(target_dir, source_dir, '%s140' + suffix) 189 _CopyRuntime2015(target_dir, source_dir, '%s140' + suffix)
182 else: 190 else:
183 _CopyRuntime2013(target_dir, source_dir, 'msvc%s120' + suffix) 191 _CopyRuntime2013(target_dir, source_dir, 'msvc%s120' + suffix)
184 192
185 # Copy the PGO runtime library to the release directories. 193 # Copy the PGO runtime library to the release directories.
186 if not debug and os.environ.get('GYP_MSVS_OVERRIDE_PATH'): 194 if not debug and os.environ.get('GYP_MSVS_OVERRIDE_PATH'):
187 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), 195 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'),
188 'VC', 'bin') 196 'VC', 'bin')
189 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') 197 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64')
190 pgo_runtime_dll = 'pgort' + _VersionNumber() + '.dll' 198 pgo_runtime_dll = 'pgort' + _VersionNumber() + '.dll'
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 x64_runtime, x86_runtime = vs_runtime_dll_dirs 257 x64_runtime, x86_runtime = vs_runtime_dll_dirs
250 runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime 258 runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime
251 _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=False) 259 _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=False)
252 if configuration == 'Debug': 260 if configuration == 'Debug':
253 _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=True) 261 _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=True)
254 262
255 263
256 def _GetDesiredVsToolchainHashes(): 264 def _GetDesiredVsToolchainHashes():
257 """Load a list of SHA1s corresponding to the toolchains that we want installed 265 """Load a list of SHA1s corresponding to the toolchains that we want installed
258 to build with.""" 266 to build with."""
259 if os.environ.get('GYP_MSVS_VERSION') == '2015': 267 if GetVisualStudioVersion() == '2015':
260 return ['17c7ddb3595be5c6b9c98b6f930adad7e4456671'] # Update 1 268 return ['17c7ddb3595be5c6b9c98b6f930adad7e4456671'] # Update 1
261 else: 269 else:
262 # Default to VS2013. 270 # Default to VS2013.
263 return ['9ff97c632ae1fee0c98bcd53e71770eb3a0d8deb'] 271 return ['9ff97c632ae1fee0c98bcd53e71770eb3a0d8deb']
264 272
265 273
266 def Update(force=False): 274 def Update(force=False):
267 """Requests an update of the toolchain to the specific hashes we have at 275 """Requests an update of the toolchain to the specific hashes we have at
268 this revision. The update outputs a .json of the various configuration 276 this revision. The update outputs a .json of the various configuration
269 information required to pass to gyp which we use in |GetToolchainDir()|. 277 information required to pass to gyp which we use in |GetToolchainDir()|.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 os.environ['WINDOWSSDKDIR'] = default_sdk_path 314 os.environ['WINDOWSSDKDIR'] = default_sdk_path
307 315
308 print '''vs_path = "%s" 316 print '''vs_path = "%s"
309 sdk_path = "%s" 317 sdk_path = "%s"
310 vs_version = "%s" 318 vs_version = "%s"
311 wdk_dir = "%s" 319 wdk_dir = "%s"
312 runtime_dirs = "%s" 320 runtime_dirs = "%s"
313 ''' % ( 321 ''' % (
314 os.environ['GYP_MSVS_OVERRIDE_PATH'], 322 os.environ['GYP_MSVS_OVERRIDE_PATH'],
315 os.environ['WINDOWSSDKDIR'], 323 os.environ['WINDOWSSDKDIR'],
316 os.environ['GYP_MSVS_VERSION'], 324 GetVisualStudioVersion(),
317 os.environ.get('WDK_DIR', ''), 325 os.environ.get('WDK_DIR', ''),
318 ';'.join(runtime_dll_dirs or ['None'])) 326 ';'.join(runtime_dll_dirs or ['None']))
319 327
320 328
321 def main(): 329 def main():
322 commands = { 330 commands = {
323 'update': Update, 331 'update': Update,
324 'get_toolchain_dir': GetToolchainDir, 332 'get_toolchain_dir': GetToolchainDir,
325 'copy_dlls': CopyDlls, 333 'copy_dlls': CopyDlls,
326 } 334 }
327 if len(sys.argv) < 2 or sys.argv[1] not in commands: 335 if len(sys.argv) < 2 or sys.argv[1] not in commands:
328 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) 336 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands)
329 return 1 337 return 1
330 return commands[sys.argv[1]](*sys.argv[2:]) 338 return commands[sys.argv[1]](*sys.argv[2:])
331 339
332 340
333 if __name__ == '__main__': 341 if __name__ == '__main__':
334 sys.exit(main()) 342 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