2a3
> # Copyright (c) 2009 The Hewlett-Packard Development Company
108a110
> import SCons.Node
110c112
< def read_command(cmd):
---
> def read_command(cmd, **kwargs):
114c116,130
< subp = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT, close_fds=True)
---
>
> 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
>
140,141c156,161
< # The absolute path to the current directory (where this file lives).
< ROOT = Dir('.').abspath
---
> ########################################################################
> #
> # Set up the base build environment.
> #
> ########################################################################
> use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'PATH', 'RANLIB' ])
143,144c163,166
< # Path to the M5 source tree.
< SRCDIR = joinpath(ROOT, 'src')
---
> use_env = {}
> for key,val in os.environ.iteritems():
> if key in use_vars or key.startswith("M5"):
> use_env[key] = val
146,147c168,170
< # tell python where to find m5 python code
< sys.path.append(joinpath(ROOT, 'src/python'))
---
> env = Environment(ENV=use_env)
> env.root = Dir(".") # The current directory (where this file lives).
> env.srcdir = Dir("src") # The source directory
149c172,173
< ###################################################
---
> ########################################################################
> #
151,153c175,179
< # 1) Grab repository revision if we know it.
< # 2) Ensure that the style hook is in place.
< ###################################################
---
> #
> # If the M5 directory is a mercurial repository, we should do some
> # extra things.
> #
> ########################################################################
155,166c181
< hg_info = "Unknown"
< try:
< if not exists(ROOT) or not isdir(ROOT) or \
< not exists(joinpath(ROOT, ".hg")):
< raise ValueError(".hg directory not found")
< hg_info = read_command("cd %s; hg id -n -i -t -b" % ROOT).strip()
< except ImportError, e:
< print "Mercurial not found"
< except ValueError, e:
< print e
< except Exception, e:
< print "Other mercurial exception: %s" % e
---
> hgdir = env.root.Dir(".hg")
168,173c183
< def check_style_hook(ui):
< ui.readconfig(joinpath(ROOT, '.hg', 'hgrc'))
< style_hook = ui.config('hooks', 'pretxncommit.style', None)
<
< if not style_hook:
< print """\
---
> mercurial_style_message = """
186,187c196
< """ % (ROOT)
< sys.exit(1)
---
> """ % (env.root)
189c198,213
< if ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')):
---
> mercurial_bin_not_found = """
> Mercurial binary cannot be found, unfortunately this means that we
> cannot easily determine the version of M5 that you are running and
> this makes error messages more difficult to collect. Please consider
> installing mercurial if you choose to post an error message
> """
>
> mercurial_lib_not_found = """
> Mercurial libraries cannot be found, ignoring style hook
> If you are actually a M5 developer, please fix this and
> run the style hook. It is important.
> """
>
> if hgdir.exists():
> # 1) Grab repository revision if we know it.
> cmd = "hg id -n -i -t -b"
191,192c215,227
< from mercurial import ui
< check_style_hook(ui.ui())
---
> hg_info = read_command(cmd, cwd=env.root.abspath).strip()
> except OSError:
> hg_info = "Unknown"
> print mercurial_bin_not_found
>
> env['HG_INFO'] = hg_info
>
> # 2) Ensure that the style hook is in place.
> try:
> ui = None
> if ARGUMENTS.get('IGNORE_STYLE') != 'True':
> from mercurial import ui
> ui = ui.ui()
194c229
< pass
---
> print mercurial_lib_not_found
195a231,233
> if ui is not None:
> ui.readconfig(hgdir.File('hgrc').abspath)
> style_hook = ui.config('hooks', 'pretxncommit.style', None)
196a235,240
> if not style_hook:
> print mercurial_style_message
> sys.exit(1)
> else:
> print ".hg directory not found"
>
260,271d303
< ###################################################
< #
< # Set up the default build environment. This environment is copied
< # and modified according to each selected configuration.
< #
< ###################################################
<
< env = Environment(ENV = environ, # inherit user's environment vars
< ROOT = ROOT,
< SRCDIR = SRCDIR,
< HG_INFO = hg_info)
<
332c364
< base_dir = joinpath(ROOT, 'src')
---
> base_dir = env.srcdir.abspath
343,345c375,381
< env['GCC'] = read_command(env['CXX'] + ' --version').find('g++') >= 0
< env['SUNCC'] = read_command(env['CXX'] + ' -V').find('Sun C++') >= 0
< env['ICC'] = read_command(env['CXX'] + ' -V').find('Intel') >= 0
---
>
> CXX_version = read_command([env['CXX'],'--version'], exception=False)
> CXX_V = read_command([env['CXX'],'-V'], exception=False)
>
> env['GCC'] = CXX_version and CXX_version.find('g++') >= 0
> env['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
> env['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
364c400
< # env.Append(CCFLAGS='-instances=semiexplicit')
---
> #env.Append(CCFLAGS='-instances=semiexplicit')
391c427
< swig_version = read_command('swig -version').split()
---
> swig_version = read_command(('swig', '-version'), exception='').split()
599a636,637
> Export('env')
>
711,712c749
< variant_dir = joinpath(build_root, 'libelf'),
< exports = 'env')
---
> variant_dir = joinpath(build_root, 'libelf'))
716,717c753
< variant_dir = joinpath(build_root, 'gzstream'),
< exports = 'env')
---
> variant_dir = joinpath(build_root, 'gzstream'))
862,870d897
<
<
< ###################################################
< #
< # Let SCons do its thing. At this point SCons will use the defined
< # build environments to build the requested targets.
< #
< ###################################################
<