Index: tools/utils.py |
diff --git a/tools/utils.py b/tools/utils.py |
index c1305b598d076f38c15ca5170d266ab0f906f86a..d0985e22b4c984cdbbe0b4c533b70716a26716ee 100644 |
--- a/tools/utils.py |
+++ b/tools/utils.py |
@@ -61,6 +61,51 @@ def GuessCpus(): |
return int(os.getenv("DART_NUMBER_OF_CORES", 2)) |
+# Try to guess Visual Studio location when buiding on Windows. |
+def GuessVisualStudioPath(): |
kustermann
2013/02/18 21:17:52
I have one major concern with this function:
- In
aam-me
2013/02/19 04:06:31
Done.
This script can also retrieve Visual Studio
|
+ defaultPath = 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7' |
+ '\\IDE' |
kustermann
2013/02/18 21:17:52
In general I usually prefer raw strings for window
aam-me
2013/02/19 04:06:31
Done.
|
+ if not IsWindows(): |
+ return defaultPath |
+ |
+ import win32process |
+ # Check if python process is 64-bit or if it's 32-bit running in 64-bit OS. |
+ # We need to know whether host is 64-bit so that we are looking in right |
+ # registry for Visual Studio path. |
+ if sys.maxsize > 2**32 or win32process.IsWow64Process(): |
+ wow6432Node = "Wow6432Node\\" |
+ else: |
+ wow6432Node = "" |
+ |
+ import _winreg |
+ try: |
+ key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, |
+ "SOFTWARE\\%sMicrosoft\\VisualStudio" % wow6432Node) |
+ except WindowsError: |
+ # Can't find traces of Visual Studio. Giving up, then. |
+ return defaultPath |
+ |
+ try: |
+ subkeyCounter = 0 |
+ while True: |
+ try: |
+ subkeyName = _winreg.EnumKey(key, subkeyCounter) |
+ except WindowsError: |
+ # Reached end of enumeration. |
+ return defaultPath |
+ match = re.match('^(\\d+\\.\\d+)$', subkeyName) |
kustermann
2013/02/18 21:17:52
Consider using a raw string.
aam-me
2013/02/19 04:06:31
Done.
|
+ if match: |
+ with _winreg.OpenKey(key, subkeyName) as subkey: |
+ try: |
+ (path, registrytype) = _winreg.QueryValueEx(subkey, 'InstallDir') |
+ return path |
+ except WindowsError: |
+ # Can't find value under the key - continue to the next key. |
+ pass |
+ subkeyCounter = subkeyCounter + 1 |
+ finally: |
+ _winreg.CloseKey(key) |
+ |
# Returns true if we're running under Windows. |
def IsWindows(): |
return GuessOS() == 'win32' |
@@ -271,6 +316,7 @@ def Main(argv): |
print "GuessArchitecture() -> ", GuessArchitecture() |
print "GuessCpus() -> ", GuessCpus() |
print "IsWindows() -> ", IsWindows() |
+ print "GuessVisualStudioPath() -> ", GuessVisualStudioPath() |
class Error(Exception): |