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

Side by Side Diff: tools/utils.py

Issue 12298006: Try to better guess Visual Studio path when building Dart on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Got rid of arithmetic comparison with None. Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « tools/build.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 # for details. All rights reserved. Use of this source code is governed by a 2 # for details. All rights reserved. Use of this source code is governed by a
3 # BSD-style license that can be found in the LICENSE file. 3 # BSD-style license that can be found in the LICENSE file.
4 4
5 # This file contains a set of utilities functions used by other Python-based 5 # This file contains a set of utilities functions used by other Python-based
6 # scripts. 6 # scripts.
7 7
8 import commands 8 import commands
9 import os 9 import os
10 import platform 10 import platform
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 def GuessCpus(): 53 def GuessCpus():
54 if os.path.exists("/proc/cpuinfo"): 54 if os.path.exists("/proc/cpuinfo"):
55 return int(commands.getoutput("grep -E '^processor' /proc/cpuinfo | wc -l")) 55 return int(commands.getoutput("grep -E '^processor' /proc/cpuinfo | wc -l"))
56 if os.path.exists("/usr/bin/hostinfo"): 56 if os.path.exists("/usr/bin/hostinfo"):
57 return int(commands.getoutput('/usr/bin/hostinfo | grep "processors are logi cally available." | awk "{ print \$1 }"')) 57 return int(commands.getoutput('/usr/bin/hostinfo | grep "processors are logi cally available." | awk "{ print \$1 }"'))
58 win_cpu_count = os.getenv("NUMBER_OF_PROCESSORS") 58 win_cpu_count = os.getenv("NUMBER_OF_PROCESSORS")
59 if win_cpu_count: 59 if win_cpu_count:
60 return int(win_cpu_count) 60 return int(win_cpu_count)
61 return int(os.getenv("DART_NUMBER_OF_CORES", 2)) 61 return int(os.getenv("DART_NUMBER_OF_CORES", 2))
62 62
63 def GetWindowsRegistryKeyName(name):
64 import win32process
65 # Check if python process is 64-bit or if it's 32-bit running in 64-bit OS.
66 # We need to know whether host is 64-bit so that we are looking in right
67 # registry for Visual Studio path.
68 if sys.maxsize > 2**32 or win32process.IsWow64Process():
69 wow6432Node = 'Wow6432Node\\'
70 else:
71 wow6432Node = ''
72 return r'SOFTWARE\%s%s' % (wow6432Node, name)
73
74 # Try to guess Visual Studio location when buiding on Windows.
75 def GuessVisualStudioPath():
76 defaultPath = r"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7" \
77 r"\IDE"
78 defaultExecutable = "devenv.com"
79
80 if not IsWindows():
81 return (defaultPath, defaultExecutable)
82
83 keyNamesAndExecutables = [
84 # Pair for non-Express editions.
85 (GetWindowsRegistryKeyName(r'Microsoft\VisualStudio'), 'devenv.com'),
86 # Pair for 2012 Express edition.
87 (GetWindowsRegistryKeyName(r'Microsoft\VSWinExpress'), 'VSWinExpress.exe'),
88 # Pair for pre-2012 Express editions.
89 (GetWindowsRegistryKeyName(r'Microsoft\VCExpress'), 'VCExpress.exe')]
90
91 bestGuess = (0.0, (defaultPath, defaultExecutable))
92
93 import _winreg
94 for (keyName, executable) in keyNamesAndExecutables:
95 try:
96 key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keyName)
97 except WindowsError:
98 # Can't find this key - moving on the next one.
99 continue
100
101 try:
102 subkeyCounter = 0
103 while True:
104 try:
105 subkeyName = _winreg.EnumKey(key, subkeyCounter)
106 subkeyCounter = subkeyCounter + 1
107 except WindowsError:
108 # Reached end of enumeration. Moving on the next key.
109 break
110
111 match = re.match(r'^\d+\.\d+$', subkeyName)
112 if match:
113 with _winreg.OpenKey(key, subkeyName) as subkey:
114 try:
115 (installDir, registrytype) = _winreg.QueryValueEx(subkey,
116 'InstallDir')
117 except WindowsError:
118 # Can't find value under the key - continue to the next key.
119 continue
120 isExpress = executable != 'devenv.com'
121 if not isExpress and subkeyName == '10.0':
122 # Stop search since if we found non-Express VS2010 version
123 # installed, which is preferred version.
124 return (installDir, executable)
125 else:
126 version = float(subkeyName)
127 # We prefer higher version of Visual Studio and given equal
128 # version numbers we prefer non-Express edition.
129 if version > bestGuess[0]:
130 bestGuess = (version, (installDir, executable))
131 finally:
132 _winreg.CloseKey(key)
133 return bestGuess[1]
134
63 135
64 # Returns true if we're running under Windows. 136 # Returns true if we're running under Windows.
65 def IsWindows(): 137 def IsWindows():
66 return GuessOS() == 'win32' 138 return GuessOS() == 'win32'
67 139
68 140
69 # Reads a text file into an array of strings - one for each 141 # Reads a text file into an array of strings - one for each
70 # line. Strips comments in the process. 142 # line. Strips comments in the process.
71 def ReadLinesFrom(name): 143 def ReadLinesFrom(name):
72 result = [] 144 result = []
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 os.unlink(name) 336 os.unlink(name)
265 except OSError, e: 337 except OSError, e:
266 PrintError("os.unlink() " + str(e)) 338 PrintError("os.unlink() " + str(e))
267 339
268 340
269 def Main(argv): 341 def Main(argv):
270 print "GuessOS() -> ", GuessOS() 342 print "GuessOS() -> ", GuessOS()
271 print "GuessArchitecture() -> ", GuessArchitecture() 343 print "GuessArchitecture() -> ", GuessArchitecture()
272 print "GuessCpus() -> ", GuessCpus() 344 print "GuessCpus() -> ", GuessCpus()
273 print "IsWindows() -> ", IsWindows() 345 print "IsWindows() -> ", IsWindows()
346 print "GuessVisualStudioPath() -> ", GuessVisualStudioPath()
274 347
275 348
276 class Error(Exception): 349 class Error(Exception):
277 pass 350 pass
278 351
279 352
280 class ToolError(Exception): 353 class ToolError(Exception):
281 """Deprecated exception, use Error instead.""" 354 """Deprecated exception, use Error instead."""
282 355
283 def __init__(self, value): 356 def __init__(self, value):
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 394
322 def DartSdkBinary(): 395 def DartSdkBinary():
323 tools_dir = os.path.dirname(os.path.realpath(__file__)) 396 tools_dir = os.path.dirname(os.path.realpath(__file__))
324 dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin') 397 dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin')
325 return os.path.join(dart_binary_prefix, 'dart') 398 return os.path.join(dart_binary_prefix, 'dart')
326 399
327 400
328 if __name__ == "__main__": 401 if __name__ == "__main__":
329 import sys 402 import sys
330 Main(sys.argv) 403 Main(sys.argv)
OLDNEW
« no previous file with comments | « tools/build.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698