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

Side by Side Diff: tools/utils.py

Issue 190793014: - Last level of defense when guessing host architecture. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 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 | « no previous file | 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 return 'arm' 52 return 'arm'
53 elif id.startswith('mips'): 53 elif id.startswith('mips'):
54 return 'mips' 54 return 'mips'
55 elif (not id) or (not re.match('(x|i[3-6])86', id) is None): 55 elif (not id) or (not re.match('(x|i[3-6])86', id) is None):
56 return 'ia32' 56 return 'ia32'
57 elif id == 'i86pc': 57 elif id == 'i86pc':
58 return 'ia32' 58 return 'ia32'
59 elif '64' in id: 59 elif '64' in id:
60 return 'x64' 60 return 'x64'
61 else: 61 else:
62 guess_os = GuessOS()
63 print "Warning: Guessing architecture %s based on os %s\n" % (id, guess_os)
64 if guess_os == 'win32':
65 return 'ia32'
62 return None 66 return None
63 67
64 68
65 # Try to guess the number of cpus on this machine. 69 # Try to guess the number of cpus on this machine.
66 def GuessCpus(): 70 def GuessCpus():
67 if os.path.exists("/proc/cpuinfo"): 71 if os.path.exists("/proc/cpuinfo"):
68 return int(commands.getoutput("grep -E '^processor' /proc/cpuinfo | wc -l")) 72 return int(commands.getoutput("grep -E '^processor' /proc/cpuinfo | wc -l"))
69 if os.path.exists("/usr/bin/hostinfo"): 73 if os.path.exists("/usr/bin/hostinfo"):
70 return int(commands.getoutput('/usr/bin/hostinfo | grep "processors are logi cally available." | awk "{ print \$1 }"')) 74 return int(commands.getoutput('/usr/bin/hostinfo | grep "processors are logi cally available." | awk "{ print \$1 }"'))
71 win_cpu_count = os.getenv("NUMBER_OF_PROCESSORS") 75 win_cpu_count = os.getenv("NUMBER_OF_PROCESSORS")
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 206
203 207
204 # Mapping table between OS and build output location. 208 # Mapping table between OS and build output location.
205 BUILD_ROOT = { 209 BUILD_ROOT = {
206 'win32': os.path.join('build'), 210 'win32': os.path.join('build'),
207 'linux': os.path.join('out'), 211 'linux': os.path.join('out'),
208 'freebsd': os.path.join('out'), 212 'freebsd': os.path.join('out'),
209 'macos': os.path.join('xcodebuild'), 213 'macos': os.path.join('xcodebuild'),
210 } 214 }
211 215
216 ARCH_GUESS = GuessArchitecture()
217 BASE_DIR = os.path.abspath(os.path.join(os.curdir, '..'))
218 DART_DIR = os.path.abspath(os.path.join(__file__, '..', '..'))
219
212 def GetBuildbotGSUtilPath(): 220 def GetBuildbotGSUtilPath():
213 gsutil = '/b/build/scripts/slave/gsutil' 221 gsutil = '/b/build/scripts/slave/gsutil'
214 if platform.system() == 'Windows': 222 if platform.system() == 'Windows':
215 gsutil = 'e:\\\\b\\build\\scripts\\slave\\gsutil' 223 gsutil = 'e:\\\\b\\build\\scripts\\slave\\gsutil'
216 return gsutil 224 return gsutil
217 225
218 def GetBuildMode(mode): 226 def GetBuildMode(mode):
219 return BUILD_MODES[mode] 227 return BUILD_MODES[mode]
220 228
221 def GetBuildConf(mode, arch, conf_os=None): 229 def GetBuildConf(mode, arch, conf_os=None):
222 if conf_os == 'android': 230 if conf_os == 'android':
223 return '%s%s%s' % (GetBuildMode(mode), conf_os.title(), arch.upper()) 231 return '%s%s%s' % (GetBuildMode(mode), conf_os.title(), arch.upper())
224 else: 232 else:
225 # Ask for a cross build if the host and target architectures don't match. 233 # Ask for a cross build if the host and target architectures don't match.
226 host_arch = ARCH_GUESS 234 host_arch = ARCH_GUESS
227 target_arch = arch 235 target_arch = arch
228 if target_arch == 'x64': 236 if target_arch == 'x64':
229 target_arch = 'ia32' 237 target_arch = 'ia32'
238 print "GetBuildConf: Rewritten %s to %s\n" % (arch, target_arch)
230 cross_build = '' 239 cross_build = ''
231 if host_arch != target_arch: 240 if host_arch != target_arch:
241 print "GetBuildConf: Cross-build of % on %s\n" % (arch, host_arch)
232 cross_build = 'X' 242 cross_build = 'X'
233 return '%s%s%s' % (GetBuildMode(mode), cross_build, arch.upper()) 243 return '%s%s%s' % (GetBuildMode(mode), cross_build, arch.upper())
234 244
235 ARCH_GUESS = GuessArchitecture()
236 BASE_DIR = os.path.abspath(os.path.join(os.curdir, '..'))
237 DART_DIR = os.path.abspath(os.path.join(__file__, '..', '..'))
238
239
240 def GetBuildDir(host_os, target_os): 245 def GetBuildDir(host_os, target_os):
241 return BUILD_ROOT[host_os] 246 return BUILD_ROOT[host_os]
242 247
243 def GetBuildRoot(host_os, mode=None, arch=None, target_os=None): 248 def GetBuildRoot(host_os, mode=None, arch=None, target_os=None):
244 build_root = GetBuildDir(host_os, target_os) 249 build_root = GetBuildDir(host_os, target_os)
245 if mode: 250 if mode:
246 build_root = os.path.join(build_root, GetBuildConf(mode, arch)) 251 build_root = os.path.join(build_root, GetBuildConf(mode, arch))
247 return build_root 252 return build_root
248 253
249 def GetBaseDir(): 254 def GetBaseDir():
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 os.chdir(self._working_directory) 551 os.chdir(self._working_directory)
547 552
548 def __exit__(self, *_): 553 def __exit__(self, *_):
549 print "Enter directory = ", self._old_cwd 554 print "Enter directory = ", self._old_cwd
550 os.chdir(self._old_cwd) 555 os.chdir(self._old_cwd)
551 556
552 557
553 if __name__ == "__main__": 558 if __name__ == "__main__":
554 import sys 559 import sys
555 Main(sys.argv) 560 Main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698