Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. 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 import gyp | |
| 12 | 13 |
| 13 | 14 |
| 14 class VisualStudioVersion(object): | 15 class VisualStudioVersion(object): |
| 15 """Information regarding a version of Visual Studio.""" | 16 """Information regarding a version of Visual Studio.""" |
| 16 | 17 |
| 17 def __init__(self, short_name, description, | 18 def __init__(self, short_name, description, |
| 18 solution_version, project_version, flat_sln, uses_vcxproj, | 19 solution_version, project_version, flat_sln, uses_vcxproj, |
| 19 path, sdk_based, default_toolset=None): | 20 path, sdk_based, default_toolset=None): |
| 20 self.short_name = short_name | 21 self.short_name = short_name |
| 21 self.description = description | 22 self.description = description |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 return True | 187 return True |
| 187 | 188 |
| 188 | 189 |
| 189 def _CreateVersion(name, path, sdk_based=False): | 190 def _CreateVersion(name, path, sdk_based=False): |
| 190 """Sets up MSVS project generation. | 191 """Sets up MSVS project generation. |
| 191 | 192 |
| 192 Setup is based off the GYP_MSVS_VERSION environment variable or whatever is | 193 Setup is based off the GYP_MSVS_VERSION environment variable or whatever is |
| 193 autodetected if GYP_MSVS_VERSION is not explicitly specified. If a version is | 194 autodetected if GYP_MSVS_VERSION is not explicitly specified. If a version is |
| 194 passed in that doesn't match a value in versions python will throw a error. | 195 passed in that doesn't match a value in versions python will throw a error. |
| 195 """ | 196 """ |
| 197 if path: | |
| 198 path = os.path.normpath(path) | |
| 196 versions = { | 199 versions = { |
| 197 '2012': VisualStudioVersion('2012', | 200 '2012': VisualStudioVersion('2012', |
| 198 'Visual Studio 2012', | 201 'Visual Studio 2012', |
| 199 solution_version='12.00', | 202 solution_version='12.00', |
| 200 project_version='4.0', | 203 project_version='4.0', |
| 201 flat_sln=False, | 204 flat_sln=False, |
| 202 uses_vcxproj=True, | 205 uses_vcxproj=True, |
| 203 path=path, | 206 path=path, |
| 204 sdk_based=sdk_based, | 207 sdk_based=sdk_based, |
| 205 default_toolset='v110'), | 208 default_toolset='v110'), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 solution_version='9.00', | 260 solution_version='9.00', |
| 258 project_version='8.00', | 261 project_version='8.00', |
| 259 flat_sln=True, | 262 flat_sln=True, |
| 260 uses_vcxproj=False, | 263 uses_vcxproj=False, |
| 261 path=path, | 264 path=path, |
| 262 sdk_based=sdk_based), | 265 sdk_based=sdk_based), |
| 263 } | 266 } |
| 264 return versions[str(name)] | 267 return versions[str(name)] |
| 265 | 268 |
| 266 | 269 |
| 270 def _ConvertToCygpath(path): | |
| 271 """Convert to cygwin path if we are using cygwin.""" | |
| 272 if sys.platform == 'cygwin': | |
| 273 p = subprocess.Popen(["cygpath", path], stdout=subprocess.PIPE) | |
|
bradn
2012/09/18 00:22:39
Use '' like the rest of the file.
Sam Clegg
2012/09/18 00:47:17
Done.
| |
| 274 path = p.communicate()[0].strip() | |
| 275 return path | |
| 276 | |
| 277 | |
| 267 def _DetectVisualStudioVersions(versions_to_check, force_express): | 278 def _DetectVisualStudioVersions(versions_to_check, force_express): |
| 268 """Collect the list of installed visual studio versions. | 279 """Collect the list of installed visual studio versions. |
| 269 | 280 |
| 270 Returns: | 281 Returns: |
| 271 A list of visual studio versions installed in descending order of | 282 A list of visual studio versions installed in descending order of |
| 272 usage preference. | 283 usage preference. |
| 273 Base this on the registry and a quick check if devenv.exe exists. | 284 Base this on the registry and a quick check if devenv.exe exists. |
| 274 Only versions 8-10 are considered. | 285 Only versions 8-10 are considered. |
| 275 Possibilities are: | 286 Possibilities are: |
| 276 2005(e) - Visual Studio 2005 (8) | 287 2005(e) - Visual Studio 2005 (8) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 287 # We don't use the 2010-encouraged-way because we also want to get the | 298 # We don't use the 2010-encouraged-way because we also want to get the |
| 288 # path to the binaries, which it doesn't offer. | 299 # path to the binaries, which it doesn't offer. |
| 289 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, | 300 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, |
| 290 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version, | 301 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version, |
| 291 r'HKLM\Software\Microsoft\VCExpress\%s' % version, | 302 r'HKLM\Software\Microsoft\VCExpress\%s' % version, |
| 292 r'HKLM\Software\Wow6432Node\Microsoft\VCExpress\%s' % version] | 303 r'HKLM\Software\Wow6432Node\Microsoft\VCExpress\%s' % version] |
| 293 for index in range(len(keys)): | 304 for index in range(len(keys)): |
| 294 path = _RegistryGetValue(keys[index], 'InstallDir') | 305 path = _RegistryGetValue(keys[index], 'InstallDir') |
| 295 if not path: | 306 if not path: |
| 296 continue | 307 continue |
| 308 path = _ConvertToCygpath(path) | |
| 297 # Check for full. | 309 # Check for full. |
| 298 full_path = os.path.join(path, 'devenv.exe') | 310 full_path = os.path.join(path, 'devenv.exe') |
| 299 express_path = os.path.join(path, 'vcexpress.exe') | 311 express_path = os.path.join(path, 'vcexpress.exe') |
| 300 if not force_express and os.path.exists(full_path): | 312 if not force_express and os.path.exists(full_path): |
| 301 # Add this one. | 313 # Add this one. |
| 302 versions.append(_CreateVersion(version_to_year[version], | 314 versions.append(_CreateVersion(version_to_year[version], |
| 303 os.path.join(path, '..', '..'))) | 315 os.path.join(path, '..', '..'))) |
| 304 # Check for express. | 316 # Check for express. |
| 305 elif os.path.exists(express_path): | 317 elif os.path.exists(express_path): |
| 306 # Add this one. | 318 # Add this one. |
| 307 versions.append(_CreateVersion(version_to_year[version] + 'e', | 319 versions.append(_CreateVersion(version_to_year[version] + 'e', |
| 308 os.path.join(path, '..', '..'))) | 320 os.path.join(path, '..', '..'))) |
| 309 | 321 |
| 310 # The old method above does not work when only SDK is installed. | 322 # The old method above does not work when only SDK is installed. |
| 311 keys = [r'HKLM\Software\Microsoft\VisualStudio\SxS\VC7', | 323 keys = [r'HKLM\Software\Microsoft\VisualStudio\SxS\VC7', |
| 312 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VC7'] | 324 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VC7'] |
| 313 for index in range(len(keys)): | 325 for index in range(len(keys)): |
| 314 path = _RegistryGetValue(keys[index], version) | 326 path = _RegistryGetValue(keys[index], version) |
| 315 if not path: | 327 if not path: |
| 316 continue | 328 continue |
| 329 path = _ConvertToCygpath(path) | |
| 317 versions.append(_CreateVersion(version_to_year[version] + 'e', | 330 versions.append(_CreateVersion(version_to_year[version] + 'e', |
| 318 os.path.join(path, '..'), sdk_based=True)) | 331 os.path.join(path, '..'), sdk_based=True)) |
| 319 | 332 |
| 320 return versions | 333 return versions |
| 321 | 334 |
| 322 | 335 |
| 323 def SelectVisualStudioVersion(version='auto'): | 336 def SelectVisualStudioVersion(version='auto'): |
| 324 """Select which version of Visual Studio projects to generate. | 337 """Select which version of Visual Studio projects to generate. |
| 325 | 338 |
| 326 Arguments: | 339 Arguments: |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 344 } | 357 } |
| 345 version = str(version) | 358 version = str(version) |
| 346 versions = _DetectVisualStudioVersions(version_map[version], 'e' in version) | 359 versions = _DetectVisualStudioVersions(version_map[version], 'e' in version) |
| 347 if not versions: | 360 if not versions: |
| 348 if version == 'auto': | 361 if version == 'auto': |
| 349 # Default to 2005 if we couldn't find anything | 362 # Default to 2005 if we couldn't find anything |
| 350 return _CreateVersion('2005', None) | 363 return _CreateVersion('2005', None) |
| 351 else: | 364 else: |
| 352 return _CreateVersion(version, None) | 365 return _CreateVersion(version, None) |
| 353 return versions[0] | 366 return versions[0] |
| OLD | NEW |