summaryrefslogtreecommitdiff
path: root/SConstruct
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2009-09-22 15:24:16 -0700
committerNathan Binkert <nate@binkert.org>2009-09-22 15:24:16 -0700
commit9a8cb7db7e86c25a755f2e2817a0385b13e3ac32 (patch)
tree56c7b56824b967ad385b6e8890f345d18c102980 /SConstruct
parent0d58d32ad51eed32e6c7f9135b901006777fbe87 (diff)
downloadgem5-9a8cb7db7e86c25a755f2e2817a0385b13e3ac32.tar.xz
python: Move more code into m5.util allow SCons to use that code.
Get rid of misc.py and just stick misc things in __init__.py Move utility functions out of SCons files and into m5.util Move utility type stuff from m5/__init__.py to m5/util/__init__.py Remove buildEnv from m5 and allow access only from m5.defines Rename AddToPath to addToPath while we're moving it to m5.util Rename read_command to readCommand while we're moving it Rename compare_versions to compareVersions while we're moving it. --HG-- rename : src/python/m5/convert.py => src/python/m5/util/convert.py rename : src/python/m5/smartdict.py => src/python/m5/util/smartdict.py
Diffstat (limited to 'SConstruct')
-rw-r--r--SConstruct70
1 files changed, 15 insertions, 55 deletions
diff --git a/SConstruct b/SConstruct
index 85c5de142..e34d60ec8 100644
--- a/SConstruct
+++ b/SConstruct
@@ -96,6 +96,7 @@ For more details, see:
"""
raise
+# Global Python includes
import os
import re
import subprocess
@@ -106,55 +107,14 @@ from os.path import abspath, basename, dirname, expanduser, normpath
from os.path import exists, isdir, isfile
from os.path import join as joinpath, split as splitpath
+# SCons includes
import SCons
import SCons.Node
-def read_command(cmd, **kwargs):
- """run the command cmd, read the results and return them
- this is sorta like `cmd` in shell"""
- from subprocess import Popen, PIPE, STDOUT
-
- if isinstance(cmd, str):
- cmd = cmd.split()
-
- no_exception = 'exception' in kwargs
- exception = kwargs.pop('exception', None)
-
- kwargs.setdefault('shell', False)
- kwargs.setdefault('stdout', PIPE)
- kwargs.setdefault('stderr', STDOUT)
- kwargs.setdefault('close_fds', True)
- try:
- subp = Popen(cmd, **kwargs)
- except Exception, e:
- if no_exception:
- return exception
- raise
-
- return subp.communicate()[0]
-
-# helper function: compare arrays or strings of version numbers.
-# E.g., compare_version((1,3,25), (1,4,1)')
-# returns -1, 0, 1 if v1 is <, ==, > v2
-def compare_versions(v1, v2):
- def make_version_list(v):
- if isinstance(v, (list,tuple)):
- return v
- elif isinstance(v, str):
- return map(lambda x: int(re.match('\d+', x).group()), v.split('.'))
- else:
- raise TypeError
-
- v1 = make_version_list(v1)
- v2 = make_version_list(v2)
- # Compare corresponding elements of lists
- for n1,n2 in zip(v1, v2):
- if n1 < n2: return -1
- if n1 > n2: return 1
- # all corresponding values are equal... see if one has extra values
- if len(v1) < len(v2): return -1
- if len(v1) > len(v2): return 1
- return 0
+# M5 includes
+sys.path[1:1] = [ Dir('src/python').srcnode().abspath ]
+
+from m5.util import compareVersions, readCommand
########################################################################
#
@@ -217,7 +177,7 @@ if hgdir.exists():
# 1) Grab repository revision if we know it.
cmd = "hg id -n -i -t -b"
try:
- hg_info = read_command(cmd, cwd=main.root.abspath).strip()
+ hg_info = readCommand(cmd, cwd=main.root.abspath).strip()
except OSError:
print mercurial_bin_not_found
@@ -381,8 +341,8 @@ main.Append(CPPPATH=[Dir('ext')])
# M5_PLY is used by isa_parser.py to find the PLY package.
main.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath })
-CXX_version = read_command([main['CXX'],'--version'], exception=False)
-CXX_V = read_command([main['CXX'],'-V'], exception=False)
+CXX_version = readCommand([main['CXX'],'--version'], exception=False)
+CXX_V = readCommand([main['CXX'],'-V'], exception=False)
main['GCC'] = CXX_version and CXX_version.find('g++') >= 0
main['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
@@ -435,7 +395,7 @@ if not main.has_key('SWIG'):
Exit(1)
# Check for appropriate SWIG version
-swig_version = read_command(('swig', '-version'), exception='').split()
+swig_version = readCommand(('swig', '-version'), exception='').split()
# First 3 words should be "SWIG Version x.y.z"
if len(swig_version) < 3 or \
swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
@@ -443,7 +403,7 @@ if len(swig_version) < 3 or \
Exit(1)
min_swig_version = '1.3.28'
-if compare_versions(swig_version[2], min_swig_version) < 0:
+if compareVersions(swig_version[2], min_swig_version) < 0:
print 'Error: SWIG version', min_swig_version, 'or newer required.'
print ' Installed version:', swig_version[2]
Exit(1)
@@ -514,8 +474,8 @@ conf.CheckLeading()
try:
import platform
uname = platform.uname()
- if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
- if int(read_command('sysctl -n hw.cpu64bit_capable')[0]):
+ if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
+ if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
main.Append(CCFLAGS='-arch x86_64')
main.Append(CFLAGS='-arch x86_64')
main.Append(LINKFLAGS='-arch x86_64')
@@ -615,9 +575,9 @@ have_mysql = bool(mysql_config)
# Check MySQL version.
if have_mysql:
- mysql_version = read_command(mysql_config + ' --version')
+ mysql_version = readCommand(mysql_config + ' --version')
min_mysql_version = '4.1'
- if compare_versions(mysql_version, min_mysql_version) < 0:
+ if compareVersions(mysql_version, min_mysql_version) < 0:
print 'Warning: MySQL', min_mysql_version, 'or newer required.'
print ' Version', mysql_version, 'detected.'
have_mysql = False