• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2008 the V8 project authors. All rights reserved.
2# Redistribution and use in source and binary forms, with or without
3# modification, are permitted provided that the following conditions are
4# met:
5#
6#     * Redistributions of source code must retain the above copyright
7#       notice, this list of conditions and the following disclaimer.
8#     * Redistributions in binary form must reproduce the above
9#       copyright notice, this list of conditions and the following
10#       disclaimer in the documentation and/or other materials provided
11#       with the distribution.
12#     * Neither the name of Google Inc. nor the names of its
13#       contributors may be used to endorse or promote products derived
14#       from this software without specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
29import glob
30import platform
31import re
32import sys
33
34
35# Reads a .list file into an array of strings
36def ReadLinesFrom(name):
37  list = []
38  for line in open(name):
39    if '#' in line:
40      line = line[:line.find('#')]
41    line = line.strip()
42    if len(line) == 0:
43      continue
44    list.append(line)
45  return list
46
47
48def GuessOS():
49  id = platform.system()
50  if id == 'Linux':
51    return 'linux'
52  elif id == 'Darwin':
53    return 'macos'
54  elif id.find('CYGWIN') >= 0:
55    return 'cygwin'
56  elif id == 'Windows' or id == 'Microsoft':
57    # On Windows Vista platform.system() can return 'Microsoft' with some
58    # versions of Python, see http://bugs.python.org/issue1082
59    return 'win32'
60  elif id == 'FreeBSD':
61    return 'freebsd'
62  elif id == 'OpenBSD':
63    return 'openbsd'
64  elif id == 'SunOS':
65    return 'solaris'
66  elif id == 'NetBSD':
67    return 'netbsd'
68  elif id == 'DragonFly':
69    # Doing so on purpose as they are pretty close
70    # minus few features
71    return 'freebsd'
72  elif id == 'AIX':
73    return 'aix'
74  elif id == 'OS400':
75    return 'ibmi'
76  else:
77    return None
78
79
80# This will default to building the 32 bit VM even on machines that are capable
81# of running the 64 bit VM.  Use the scons option --arch=x64 to force it to build
82# the 64 bit VM.
83def GuessArchitecture():
84  id = platform.machine()
85  id = id.lower()  # Windows 7 capitalizes 'AMD64'.
86  if id.startswith('arm') or id == 'aarch64':
87    return 'arm'
88  elif (not id) or (not re.match('(x|i[3-6])86$', id) is None):
89    return 'ia32'
90  elif id == 'i86pc':
91    return 'ia32'
92  elif id == 'x86_64':
93    return 'ia32'
94  elif id == 'amd64':
95    return 'ia32'
96  elif id.startswith('ppc'):
97    return 'ppc'
98  elif id == 's390x':
99    return 's390'
100  elif id == 'riscv64':
101    return 'riscv64'
102  else:
103    id = platform.processor()
104    if id == 'powerpc':
105      return 'ppc'
106    return None
107
108
109def IsWindows():
110  return GuessOS() == 'win32'
111
112
113def SearchFiles(dir, ext):
114  list = glob.glob(dir+ '/**/*.' + ext, recursive=True)
115  if sys.platform == 'win32':
116    list = [ x.replace('\\', '/')for x in list]
117  return sorted(list)
118