133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# Copyright 2012 the V8 project authors. All rights reserved. 233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# Redistribution and use in source and binary forms, with or without 333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# modification, are permitted provided that the following conditions are 433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# met: 533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# 633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# * Redistributions of source code must retain the above copyright 733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# notice, this list of conditions and the following disclaimer. 833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# * Redistributions in binary form must reproduce the above 933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# copyright notice, this list of conditions and the following 1033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# disclaimer in the documentation and/or other materials provided 1133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# with the distribution. 1233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# * Neither the name of Google Inc. nor the names of its 1333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# contributors may be used to endorse or promote products derived 1433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# from this software without specific prior written permission. 1533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# 1633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 2833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 2933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgimport os 3033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgfrom os.path import exists 3133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgfrom os.path import isdir 3233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgfrom os.path import join 3333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgimport platform 3433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgimport re 3533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 3633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 3733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgdef GetSuitePaths(test_root): 3833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org def IsSuite(path): 3933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return isdir(path) and exists(join(path, 'testcfg.py')) 4033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return [ f for f in os.listdir(test_root) if IsSuite(join(test_root, f)) ] 4133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 4233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 4333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# Reads a file into an array of strings 4433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgdef ReadLinesFrom(name): 4533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org lines = [] 4633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org with open(name) as f: 4733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org for line in f: 4833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org if line.startswith('#'): continue 4933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org if '#' in line: 5033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org line = line[:line.find('#')] 5133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org line = line.strip() 5233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org if not line: continue 5333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org lines.append(line) 5433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return lines 5533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 5633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 5733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgdef GuessOS(): 5833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org system = platform.system() 5933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org if system == 'Linux': 6033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'linux' 6133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org elif system == 'Darwin': 6233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'macos' 6333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org elif system.find('CYGWIN') >= 0: 6433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'cygwin' 6533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org elif system == 'Windows' or system == 'Microsoft': 6633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org # On Windows Vista platform.system() can return 'Microsoft' with some 6733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org # versions of Python, see http://bugs.python.org/issue1082 688e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org return 'windows' 6933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org elif system == 'FreeBSD': 7033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'freebsd' 7133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org elif system == 'OpenBSD': 7233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'openbsd' 7333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org elif system == 'SunOS': 7433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'solaris' 7533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org elif system == 'NetBSD': 7633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'netbsd' 7733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org else: 7833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return None 7933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 8033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 8133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# This will default to building the 32 bit VM even on machines that are 8233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org# capable of running the 64 bit VM. 8333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgdef DefaultArch(): 8433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org machine = platform.machine() 8533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org machine = machine.lower() # Windows 7 capitalizes 'AMD64'. 8633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org if machine.startswith('arm'): 8733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'arm' 8833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org elif (not machine) or (not re.match('(x|i[3-6])86$', machine) is None): 8933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'ia32' 9033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org elif machine == 'i86pc': 9133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'ia32' 9233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org elif machine == 'x86_64': 9333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'ia32' 9433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org elif machine == 'amd64': 9533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return 'ia32' 9633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org else: 9733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return None 9833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 9933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 10033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgdef GuessWordsize(): 10133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org if '64' in platform.machine(): 10233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return '64' 10333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org else: 10433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org return '32' 10533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 10633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 10733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgdef IsWindows(): 1088e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org return GuessOS() == 'windows' 109