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

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