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

Side by Side Diff: build/vs_toolchain.py

Issue 1556993002: [gn] Detect location of Visual Studio in the registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 # values there. 57 # values there.
58 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES')) 58 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
59 gyp_defines_dict['windows_sdk_path'] = win_sdk 59 gyp_defines_dict['windows_sdk_path'] = win_sdk
60 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) 60 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v)))
61 for k, v in gyp_defines_dict.iteritems()) 61 for k, v in gyp_defines_dict.iteritems())
62 os.environ['WINDOWSSDKDIR'] = win_sdk 62 os.environ['WINDOWSSDKDIR'] = win_sdk
63 os.environ['WDK_DIR'] = wdk 63 os.environ['WDK_DIR'] = wdk
64 # Include the VS runtime in the PATH in case it's not machine-installed. 64 # Include the VS runtime in the PATH in case it's not machine-installed.
65 runtime_path = ';'.join(vs_runtime_dll_dirs) 65 runtime_path = ';'.join(vs_runtime_dll_dirs)
66 os.environ['PATH'] = runtime_path + ';' + os.environ['PATH'] 66 os.environ['PATH'] = runtime_path + ';' + os.environ['PATH']
67 elif sys.platform in ('win32', 'cygwin') and not depot_tools_win_toolchain:
68 if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ:
69 os.environ['GYP_MSVS_OVERRIDE_PATH'] = _DetectVisualStudioPath()
70
67 return vs_runtime_dll_dirs 71 return vs_runtime_dll_dirs
68 72
69 73
74 def _RegistryGetValueUsingWinReg(key, value):
75 """Use the _winreg module to obtain the value of a registry key.
76
77 Args:
78 key: The registry key.
79 value: The particular registry value to read.
80 Return:
81 contents of the registry key's value, or None on failure. Throws
82 ImportError if _winreg is unavailable.
83 """
84 import _winreg
85 try:
86 root, subkey = key.split('\\', 1)
87 assert root == 'HKLM' # Only need HKLM for now.
88 with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey:
89 return _winreg.QueryValueEx(hkey, value)[0]
90 except WindowsError:
91 return None
92
93
94 def _RegistryGetValue(key, value):
95 try:
96 return _RegistryGetValueUsingWinReg(key, value)
brucedawson 2016/01/04 21:36:06 Also indented two extra spaces.
97 except ImportError:
98 raise Exception('The python library _winreg not found.')
99
100
101 def _DetectVisualStudioPath():
102 """Return path to the GYP_MSVS_VERSION of Visual Studio
103 """
104
105 # Default to 2015 for now.
106 version_as_year = os.environ.get('GYP_MSVS_VERSION', '2015')
107 year_to_version = {
108 '2013': '12.0',
109 '2015': '14.0',
110 }
111 if not version_as_year in year_to_version:
112 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)'
113 ' not supported. Supported versions are: %s') % (
114 version_as_year, ', '.join(year_to_version.keys())))
115 version = year_to_version[version_as_year]
116 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version,
117 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version]
118 for key in keys:
119 path = _RegistryGetValue(key, 'InstallDir')
120 if not path:
121 continue
122 path = os.path.normpath(os.path.join(path, '..', '..'))
123 return path
124
125 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)'
126 ' not found.') % (version_as_year))
127
128
70 def _VersionNumber(): 129 def _VersionNumber():
71 """Gets the standard version number ('120', '140', etc.) based on 130 """Gets the standard version number ('120', '140', etc.) based on
72 GYP_MSVS_VERSION.""" 131 GYP_MSVS_VERSION."""
73 if os.environ['GYP_MSVS_VERSION'] == '2013': 132 if os.environ['GYP_MSVS_VERSION'] == '2013':
74 return '120' 133 return '120'
75 elif os.environ['GYP_MSVS_VERSION'] == '2015': 134 elif os.environ['GYP_MSVS_VERSION'] == '2015':
76 return '140' 135 return '140'
77 else: 136 else:
78 raise ValueError('Unexpected GYP_MSVS_VERSION') 137 raise ValueError('Unexpected GYP_MSVS_VERSION')
79 138
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 'copy_dlls': CopyDlls, 322 'copy_dlls': CopyDlls,
264 } 323 }
265 if len(sys.argv) < 2 or sys.argv[1] not in commands: 324 if len(sys.argv) < 2 or sys.argv[1] not in commands:
266 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) 325 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands)
267 return 1 326 return 1
268 return commands[sys.argv[1]](*sys.argv[2:]) 327 return commands[sys.argv[1]](*sys.argv[2:])
269 328
270 329
271 if __name__ == '__main__': 330 if __name__ == '__main__':
272 sys.exit(main()) 331 sys.exit(main())
OLDNEW
« build/toolchain/win/setup_toolchain.py ('K') | « build/toolchain/win/setup_toolchain.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698