Index: tools/utils.py |
diff --git a/tools/utils.py b/tools/utils.py |
index c1305b598d076f38c15ca5170d266ab0f906f86a..e2094694240f8acaa8a05c6025e279cb9f46f0ce 100644 |
--- a/tools/utils.py |
+++ b/tools/utils.py |
@@ -60,12 +60,53 @@ def GuessCpus(): |
return int(win_cpu_count) |
return int(os.getenv("DART_NUMBER_OF_CORES", 2)) |
+# Try to guess Visual Studio location when buiding on Windows. |
+def GuessVisualStudioPath(): |
+ defaultPath = 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7' |
+ '\\IDE' |
+ if IsWindows(): |
ahe
2013/02/18 15:47:20
if not IsWindows():
return defaultPath
Then the
aam-me
2013/02/18 16:20:06
Done.
|
+ 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\\" + wow6432Node + "Microsoft\\VisualStudio") |
ahe
2013/02/18 15:47:20
Long line. Also, I think our Python style guide pr
aam-me
2013/02/18 16:20:06
Done.
|
+ except WindowsError: |
ahe
2013/02/18 15:47:20
Please document why it is OK to ignore this error.
aam-me
2013/02/18 16:20:06
Done.
|
+ return defaultPath |
+ |
+ iSubkey = 0 |
ahe
2013/02/18 15:47:20
What does this variable mean? The word "iSubkey" i
aam-me
2013/02/18 16:20:06
This is subkey counter. Changed name.
|
+ while(True): |
ahe
2013/02/18 15:47:20
I don't think you need parentheses here in Python.
aam-me
2013/02/18 16:20:06
Done.
|
+ try: |
+ subkeyName = _winreg.EnumKey(key, iSubkey) |
+ except WindowsError: |
+ # Reached end of enumeration |
ahe
2013/02/18 15:47:20
Is there a way to check, or must you catch an exce
aam-me
2013/02/18 16:20:06
According to http://docs.python.org/2/library/_win
|
+ return defaultPath |
+ match = re.match('^(\\d+\\.\\d+)$', subkeyName) |
+ if not match is None: |
ahe
2013/02/18 15:47:20
if match:
aam-me
2013/02/18 16:20:06
Done.
|
+ 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 |
+ iSubkey = iSubkey + 1 |
+ |
+ _winreg.CloseKey(key) |
ahe
2013/02/18 15:47:20
This is dead code as it comes after an "infinite"
aam-me
2013/02/18 16:20:06
Thanks. Wrapped it into try: finally: to close the
|
+ else: |
+ return defaultPath |
# Returns true if we're running under Windows. |
def IsWindows(): |
return GuessOS() == 'win32' |
- |
# Reads a text file into an array of strings - one for each |
# line. Strips comments in the process. |
def ReadLinesFrom(name): |
@@ -271,6 +312,7 @@ def Main(argv): |
print "GuessArchitecture() -> ", GuessArchitecture() |
print "GuessCpus() -> ", GuessCpus() |
print "IsWindows() -> ", IsWindows() |
+ print "GuessVisualStudioPath() -> ", GuessVisualStudioPath() |
class Error(Exception): |