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

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: Code cleanup. 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
« tools/build.py ('K') | « 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 63
64 # Try to guess Visual Studio location when buiding on Windows.
65 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
66 defaultPath = 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7'
67 '\\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.
68 if not IsWindows():
69 return defaultPath
70
71 import win32process
72 # Check if python process is 64-bit or if it's 32-bit running in 64-bit OS.
73 # We need to know whether host is 64-bit so that we are looking in right
74 # registry for Visual Studio path.
75 if sys.maxsize > 2**32 or win32process.IsWow64Process():
76 wow6432Node = "Wow6432Node\\"
77 else:
78 wow6432Node = ""
79
80 import _winreg
81 try:
82 key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
83 "SOFTWARE\\%sMicrosoft\\VisualStudio" % wow6432Node)
84 except WindowsError:
85 # Can't find traces of Visual Studio. Giving up, then.
86 return defaultPath
87
88 try:
89 subkeyCounter = 0
90 while True:
91 try:
92 subkeyName = _winreg.EnumKey(key, subkeyCounter)
93 except WindowsError:
94 # Reached end of enumeration.
95 return defaultPath
96 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.
97 if match:
98 with _winreg.OpenKey(key, subkeyName) as subkey:
99 try:
100 (path, registrytype) = _winreg.QueryValueEx(subkey, 'InstallDir')
101 return path
102 except WindowsError:
103 # Can't find value under the key - continue to the next key.
104 pass
105 subkeyCounter = subkeyCounter + 1
106 finally:
107 _winreg.CloseKey(key)
108
64 # Returns true if we're running under Windows. 109 # Returns true if we're running under Windows.
65 def IsWindows(): 110 def IsWindows():
66 return GuessOS() == 'win32' 111 return GuessOS() == 'win32'
67 112
68 113
69 # Reads a text file into an array of strings - one for each 114 # Reads a text file into an array of strings - one for each
70 # line. Strips comments in the process. 115 # line. Strips comments in the process.
71 def ReadLinesFrom(name): 116 def ReadLinesFrom(name):
72 result = [] 117 result = []
73 for line in open(name): 118 for line in open(name):
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 os.unlink(name) 309 os.unlink(name)
265 except OSError, e: 310 except OSError, e:
266 PrintError("os.unlink() " + str(e)) 311 PrintError("os.unlink() " + str(e))
267 312
268 313
269 def Main(argv): 314 def Main(argv):
270 print "GuessOS() -> ", GuessOS() 315 print "GuessOS() -> ", GuessOS()
271 print "GuessArchitecture() -> ", GuessArchitecture() 316 print "GuessArchitecture() -> ", GuessArchitecture()
272 print "GuessCpus() -> ", GuessCpus() 317 print "GuessCpus() -> ", GuessCpus()
273 print "IsWindows() -> ", IsWindows() 318 print "IsWindows() -> ", IsWindows()
319 print "GuessVisualStudioPath() -> ", GuessVisualStudioPath()
274 320
275 321
276 class Error(Exception): 322 class Error(Exception):
277 pass 323 pass
278 324
279 325
280 class ToolError(Exception): 326 class ToolError(Exception):
281 """Deprecated exception, use Error instead.""" 327 """Deprecated exception, use Error instead."""
282 328
283 def __init__(self, value): 329 def __init__(self, value):
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 367
322 def DartSdkBinary(): 368 def DartSdkBinary():
323 tools_dir = os.path.dirname(os.path.realpath(__file__)) 369 tools_dir = os.path.dirname(os.path.realpath(__file__))
324 dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin') 370 dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin')
325 return os.path.join(dart_binary_prefix, 'dart') 371 return os.path.join(dart_binary_prefix, 'dart')
326 372
327 373
328 if __name__ == "__main__": 374 if __name__ == "__main__":
329 import sys 375 import sys
330 Main(sys.argv) 376 Main(sys.argv)
OLDNEW
« tools/build.py ('K') | « tools/build.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698