OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 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 """Handle version information related to Visual Stuio.""" | 5 """Handle version information related to Visual Stuio.""" |
6 | 6 |
7 import errno | 7 import errno |
8 import os | 8 import os |
9 import re | 9 import re |
10 import subprocess | 10 import subprocess |
11 import sys | 11 import sys |
12 | 12 |
13 | 13 |
14 class VisualStudioVersion(object): | 14 class VisualStudioVersion(object): |
15 """Information regarding a version of Visual Studio.""" | 15 """Information regarding a version of Visual Studio.""" |
16 | 16 |
17 def __init__(self, short_name, description, | 17 def __init__(self, short_name, description, |
18 solution_version, project_version, flat_sln, uses_vcxproj): | 18 solution_version, project_version, flat_sln, uses_vcxproj, |
| 19 path): |
19 self.short_name = short_name | 20 self.short_name = short_name |
20 self.description = description | 21 self.description = description |
21 self.solution_version = solution_version | 22 self.solution_version = solution_version |
22 self.project_version = project_version | 23 self.project_version = project_version |
23 self.flat_sln = flat_sln | 24 self.flat_sln = flat_sln |
24 self.uses_vcxproj = uses_vcxproj | 25 self.uses_vcxproj = uses_vcxproj |
| 26 self.path = path |
25 | 27 |
26 def ShortName(self): | 28 def ShortName(self): |
27 return self.short_name | 29 return self.short_name |
28 | 30 |
29 def Description(self): | 31 def Description(self): |
30 """Get the full description of the version.""" | 32 """Get the full description of the version.""" |
31 return self.description | 33 return self.description |
32 | 34 |
33 def SolutionVersion(self): | 35 def SolutionVersion(self): |
34 """Get the version number of the sln files.""" | 36 """Get the version number of the sln files.""" |
35 return self.solution_version | 37 return self.solution_version |
36 | 38 |
37 def ProjectVersion(self): | 39 def ProjectVersion(self): |
38 """Get the version number of the vcproj or vcxproj files.""" | 40 """Get the version number of the vcproj or vcxproj files.""" |
39 return self.project_version | 41 return self.project_version |
40 | 42 |
41 def FlatSolution(self): | 43 def FlatSolution(self): |
42 return self.flat_sln | 44 return self.flat_sln |
43 | 45 |
44 def UsesVcxproj(self): | 46 def UsesVcxproj(self): |
45 """Returns true if this version uses a vcxproj file.""" | 47 """Returns true if this version uses a vcxproj file.""" |
46 return self.uses_vcxproj | 48 return self.uses_vcxproj |
47 | 49 |
48 def ProjectExtension(self): | 50 def ProjectExtension(self): |
49 """Returns the file extension for the project.""" | 51 """Returns the file extension for the project.""" |
50 return self.uses_vcxproj and '.vcxproj' or '.vcproj' | 52 return self.uses_vcxproj and '.vcxproj' or '.vcproj' |
51 | 53 |
| 54 def Path(self): |
| 55 """Returns the path to Visual Studio installation.""" |
| 56 return self.path |
| 57 |
52 def _RegistryQueryBase(sysdir, key, value): | 58 def _RegistryQueryBase(sysdir, key, value): |
53 """Use reg.exe to read a particular key. | 59 """Use reg.exe to read a particular key. |
54 | 60 |
55 While ideally we might use the win32 module, we would like gyp to be | 61 While ideally we might use the win32 module, we would like gyp to be |
56 python neutral, so for instance cygwin python lacks this module. | 62 python neutral, so for instance cygwin python lacks this module. |
57 | 63 |
58 Arguments: | 64 Arguments: |
59 sysdir: The system subdirectory to attempt to launch reg.exe from. | 65 sysdir: The system subdirectory to attempt to launch reg.exe from. |
60 key: The registry key to read from. | 66 key: The registry key to read from. |
61 value: The particular value to read. | 67 value: The particular value to read. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 Args: | 139 Args: |
134 key: The registry key to check. | 140 key: The registry key to check. |
135 Return: | 141 Return: |
136 True if the key exists | 142 True if the key exists |
137 """ | 143 """ |
138 if not _RegistryQuery(key): | 144 if not _RegistryQuery(key): |
139 return False | 145 return False |
140 return True | 146 return True |
141 | 147 |
142 | 148 |
143 def _CreateVersion(name): | 149 def _CreateVersion(name, path): |
144 """Sets up MSVS project generation. | 150 """Sets up MSVS project generation. |
145 | 151 |
146 Setup is based off the GYP_MSVS_VERSION environment variable or whatever is | 152 Setup is based off the GYP_MSVS_VERSION environment variable or whatever is |
147 autodetected if GYP_MSVS_VERSION is not explicitly specified. If a version is | 153 autodetected if GYP_MSVS_VERSION is not explicitly specified. If a version is |
148 passed in that doesn't match a value in versions python will throw a error. | 154 passed in that doesn't match a value in versions python will throw a error. |
149 """ | 155 """ |
150 versions = { | 156 versions = { |
151 '2010': VisualStudioVersion('2010', | 157 '2010': VisualStudioVersion('2010', |
152 'Visual Studio 2010', | 158 'Visual Studio 2010', |
153 solution_version='11.00', | 159 solution_version='11.00', |
154 project_version='4.0', | 160 project_version='4.0', |
155 flat_sln=False, | 161 flat_sln=False, |
156 uses_vcxproj=True), | 162 uses_vcxproj=True, |
| 163 path=path), |
157 '2010e': VisualStudioVersion('2010e', | 164 '2010e': VisualStudioVersion('2010e', |
158 'Visual Studio 2010', | 165 'Visual Studio 2010', |
159 solution_version='11.00', | 166 solution_version='11.00', |
160 project_version='4.0', | 167 project_version='4.0', |
161 flat_sln=True, | 168 flat_sln=True, |
162 uses_vcxproj=True), | 169 uses_vcxproj=True, |
| 170 path=path), |
163 '2008': VisualStudioVersion('2008', | 171 '2008': VisualStudioVersion('2008', |
164 'Visual Studio 2008', | 172 'Visual Studio 2008', |
165 solution_version='10.00', | 173 solution_version='10.00', |
166 project_version='9.00', | 174 project_version='9.00', |
167 flat_sln=False, | 175 flat_sln=False, |
168 uses_vcxproj=False), | 176 uses_vcxproj=False, |
| 177 path=path), |
169 '2008e': VisualStudioVersion('2008e', | 178 '2008e': VisualStudioVersion('2008e', |
170 'Visual Studio 2008', | 179 'Visual Studio 2008', |
171 solution_version='10.00', | 180 solution_version='10.00', |
172 project_version='9.00', | 181 project_version='9.00', |
173 flat_sln=True, | 182 flat_sln=True, |
174 uses_vcxproj=False), | 183 uses_vcxproj=False, |
| 184 path=path), |
175 '2005': VisualStudioVersion('2005', | 185 '2005': VisualStudioVersion('2005', |
176 'Visual Studio 2005', | 186 'Visual Studio 2005', |
177 solution_version='9.00', | 187 solution_version='9.00', |
178 project_version='8.00', | 188 project_version='8.00', |
179 flat_sln=False, | 189 flat_sln=False, |
180 uses_vcxproj=False), | 190 uses_vcxproj=False, |
| 191 path=path), |
181 '2005e': VisualStudioVersion('2005e', | 192 '2005e': VisualStudioVersion('2005e', |
182 'Visual Studio 2005', | 193 'Visual Studio 2005', |
183 solution_version='9.00', | 194 solution_version='9.00', |
184 project_version='8.00', | 195 project_version='8.00', |
185 flat_sln=True, | 196 flat_sln=True, |
186 uses_vcxproj=False), | 197 uses_vcxproj=False, |
| 198 path=path), |
187 } | 199 } |
188 return versions[str(name)] | 200 return versions[str(name)] |
189 | 201 |
190 | 202 |
191 def _DetectVisualStudioVersions(): | 203 def _DetectVisualStudioVersions(): |
192 """Collect the list of installed visual studio versions. | 204 """Collect the list of installed visual studio versions. |
193 | 205 |
194 Returns: | 206 Returns: |
195 A list of visual studio versions installed in descending order of | 207 A list of visual studio versions installed in descending order of |
196 usage preference. | 208 usage preference. |
197 Base this on the registry and a quick check if devenv.exe exists. | 209 Base this on the registry and a quick check if devenv.exe exists. |
198 Only versions 8-10 are considered. | 210 Only versions 8-10 are considered. |
199 Possibilities are: | 211 Possibilities are: |
200 2005(e) - Visual Studio 2005 (8) | 212 2005(e) - Visual Studio 2005 (8) |
201 2008(e) - Visual Studio 2008 (9) | 213 2008(e) - Visual Studio 2008 (9) |
202 2010(e) - Visual Studio 2010 (10) | 214 2010(e) - Visual Studio 2010 (10) |
203 Where (e) is e for express editions of MSVS and blank otherwise. | 215 Where (e) is e for express editions of MSVS and blank otherwise. |
204 """ | 216 """ |
205 version_to_year = {'8.0': '2005', '9.0': '2008', '10.0': '2010'} | 217 version_to_year = {'8.0': '2005', '9.0': '2008', '10.0': '2010'} |
206 versions = [] | 218 versions = [] |
207 # For now, prefer versions before VS2010 | 219 # For now, prefer versions before VS2010 |
208 for version in ('9.0', '8.0', '10.0'): | 220 for version in ('9.0', '8.0', '10.0'): |
| 221 |
| 222 ''' |
209 # Check if VS2010 and later is installed as specified by | 223 # Check if VS2010 and later is installed as specified by |
210 # http://msdn.microsoft.com/en-us/library/bb164659.aspx | 224 # http://msdn.microsoft.com/en-us/library/bb164659.aspx |
211 keys = [r'HKLM\SOFTWARE\Microsoft\DevDiv\VS\Servicing\%s' % version, | 225 keys = [r'HKLM\SOFTWARE\Microsoft\DevDiv\VS\Servicing\%s' % version, |
212 r'HKLM\SOFTWARE\Wow6432Node\Microsoft\DevDiv\VS\Servicing\%s' % ( | 226 r'HKLM\SOFTWARE\Wow6432Node\Microsoft\DevDiv\VS\Servicing\%s' % ( |
213 version)] | 227 version)] |
214 for index in range(len(keys)): | 228 for index in range(len(keys)): |
215 if not _RegistryKeyExists(keys[index]): | 229 if not _RegistryKeyExists(keys[index]): |
216 continue | 230 continue |
217 # Check for express | 231 # Check for express |
218 if _RegistryKeyExists(keys[index] + '\\expbsln'): | 232 if _RegistryKeyExists(keys[index] + '\\expbsln'): |
219 # Add this one | 233 # Add this one |
220 versions.append(_CreateVersion(version_to_year[version] + 'e')) | 234 versions.append(_CreateVersion(version_to_year[version] + 'e', "TODO!")) |
221 else: | 235 else: |
222 # Add this one | 236 # Add this one |
223 versions.append(_CreateVersion(version_to_year[version])) | 237 versions.append(_CreateVersion(version_to_year[version], "TODO!")) |
| 238 ''' |
224 | 239 |
225 # Old (pre-VS2010) method of searching for which VS version is installed | 240 # Old (pre-VS2010) method of searching for which VS version is installed |
226 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, | 241 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, |
227 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version, | 242 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version, |
228 r'HKLM\Software\Microsoft\VCExpress\%s' % version, | 243 r'HKLM\Software\Microsoft\VCExpress\%s' % version, |
229 r'HKLM\Software\Wow6432Node\Microsoft\VCExpress\%s' % version] | 244 r'HKLM\Software\Wow6432Node\Microsoft\VCExpress\%s' % version] |
230 for index in range(len(keys)): | 245 for index in range(len(keys)): |
231 path = _RegistryGetValue(keys[index], 'InstallDir') | 246 path = _RegistryGetValue(keys[index], 'InstallDir') |
232 if not path: | 247 if not path: |
233 continue | 248 continue |
234 # Check for full. | 249 # Check for full. |
235 if os.path.exists(os.path.join(path, 'devenv.exe')): | 250 full_path = os.path.join(path, 'devenv.exe') |
| 251 express_path = os.path.join(path, 'vcexpress.exe') |
| 252 if os.path.exists(full_path): |
236 # Add this one. | 253 # Add this one. |
237 versions.append(_CreateVersion(version_to_year[version])) | 254 versions.append(_CreateVersion(version_to_year[version], |
| 255 os.path.join(path, '../..'))) |
238 # Check for express. | 256 # Check for express. |
239 elif os.path.exists(os.path.join(path, 'vcexpress.exe')): | 257 elif os.path.exists(express_path): |
240 # Add this one. | 258 # Add this one. |
241 versions.append(_CreateVersion(version_to_year[version] + 'e')) | 259 versions.append(_CreateVersion(version_to_year[version] + 'e', |
| 260 os.path.join(path, '../..'))) |
242 return versions | 261 return versions |
243 | 262 |
244 | 263 |
245 def SelectVisualStudioVersion(version='auto'): | 264 def SelectVisualStudioVersion(version='auto'): |
246 """Select which version of Visual Studio projects to generate. | 265 """Select which version of Visual Studio projects to generate. |
247 | 266 |
248 Arguments: | 267 Arguments: |
249 version: Hook to allow caller to force a particular version (vs auto). | 268 version: Hook to allow caller to force a particular version (vs auto). |
250 Returns: | 269 Returns: |
251 An object representing a visual studio project format version. | 270 An object representing a visual studio project format version. |
252 """ | 271 """ |
253 # In auto mode, check environment variable for override. | 272 # In auto mode, check environment variable for override. |
254 if version == 'auto': | 273 if version == 'auto': |
255 version = os.environ.get('GYP_MSVS_VERSION', 'auto') | 274 version = os.environ.get('GYP_MSVS_VERSION', 'auto') |
256 # In auto mode, pick the most preferred version present. | 275 # In auto mode, pick the most preferred version present. |
257 if version == 'auto': | 276 if version == 'auto': |
258 versions = _DetectVisualStudioVersions() | 277 versions = _DetectVisualStudioVersions() |
259 if not versions: | 278 if not versions: |
260 # Default to 2005. | 279 # Default to 2005. |
261 return _CreateVersion('2005') | 280 return _CreateVersion('2005') |
262 return versions[0] | 281 return versions[0] |
263 # Convert version string into a version object. | 282 # Convert version string into a version object. |
264 return _CreateVersion(version) | 283 return _CreateVersion(version) |
OLD | NEW |