98a99
> # Global Python includes
108a110
> # SCons includes
112,115c114,115
< 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
---
> # M5 includes
> sys.path[1:1] = [ Dir('src/python').srcnode().abspath ]
117,118c117
< if isinstance(cmd, str):
< cmd = cmd.split()
---
> from m5.util import compareVersions, readCommand
120,158d118
< 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
<
220c180
< hg_info = read_command(cmd, cwd=main.root.abspath).strip()
---
> hg_info = readCommand(cmd, cwd=main.root.abspath).strip()
384,385c344,345
< 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)
438c398
< swig_version = read_command(('swig', '-version'), exception='').split()
---
> swig_version = readCommand(('swig', '-version'), exception='').split()
446c406
< if compare_versions(swig_version[2], min_swig_version) < 0:
---
> if compareVersions(swig_version[2], min_swig_version) < 0:
517,518c477,478
< 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]):
618c578
< mysql_version = read_command(mysql_config + ' --version')
---
> mysql_version = readCommand(mysql_config + ' --version')
620c580
< if compare_versions(mysql_version, min_mysql_version) < 0:
---
> if compareVersions(mysql_version, min_mysql_version) < 0: