scons: Rename the basic environment from env -> main.

env is used as a local variable all over the place and sometimes it is
easy to get confused as to whether the global env or local env is being
used.  This will become especially important when I change the way we
support our variants.
This commit is contained in:
Nathan Binkert 2009-04-21 17:17:16 -07:00
parent 56e5509bfd
commit 05d8c9acb8
3 changed files with 82 additions and 86 deletions

View file

@ -158,7 +158,7 @@ def compare_versions(v1, v2):
######################################################################## ########################################################################
# #
# Set up the base build environment. # Set up the main build environment.
# #
######################################################################## ########################################################################
use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
@ -169,9 +169,9 @@ for key,val in os.environ.iteritems():
if key in use_vars or key.startswith("M5"): if key in use_vars or key.startswith("M5"):
use_env[key] = val use_env[key] = val
env = Environment(ENV=use_env) main = Environment(ENV=use_env)
env.root = Dir(".") # The current directory (where this file lives). main.root = Dir(".") # The current directory (where this file lives).
env.srcdir = Dir("src") # The source directory main.srcdir = Dir("src") # The source directory
######################################################################## ########################################################################
# #
@ -182,7 +182,7 @@ env.srcdir = Dir("src") # The source directory
# #
######################################################################## ########################################################################
hgdir = env.root.Dir(".hg") hgdir = main.root.Dir(".hg")
mercurial_style_message = """ mercurial_style_message = """
You're missing the M5 style hook. You're missing the M5 style hook.
@ -197,7 +197,7 @@ style = %s/util/style.py
[hooks] [hooks]
pretxncommit.style = python:style.check_whitespace pretxncommit.style = python:style.check_whitespace
""" % (env.root) """ % (main.root)
mercurial_bin_not_found = """ mercurial_bin_not_found = """
Mercurial binary cannot be found, unfortunately this means that we Mercurial binary cannot be found, unfortunately this means that we
@ -217,7 +217,7 @@ if hgdir.exists():
# 1) Grab repository revision if we know it. # 1) Grab repository revision if we know it.
cmd = "hg id -n -i -t -b" cmd = "hg id -n -i -t -b"
try: try:
hg_info = read_command(cmd, cwd=env.root.abspath).strip() hg_info = read_command(cmd, cwd=main.root.abspath).strip()
except OSError: except OSError:
print mercurial_bin_not_found print mercurial_bin_not_found
@ -239,7 +239,8 @@ if hgdir.exists():
sys.exit(1) sys.exit(1)
else: else:
print ".hg directory not found" print ".hg directory not found"
env['HG_INFO'] = hg_info
main['HG_INFO'] = hg_info
################################################### ###################################################
# #
@ -273,7 +274,7 @@ if COMMAND_LINE_TARGETS:
COMMAND_LINE_TARGETS] COMMAND_LINE_TARGETS]
else: else:
# Default targets are relative to root of tree # Default targets are relative to root of tree
abs_targets = [ normpath(joinpath(env.root.abspath, str(x))) for x in \ abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \
DEFAULT_TARGETS] DEFAULT_TARGETS]
@ -304,15 +305,15 @@ for t in abs_targets:
if not isdir(build_root): if not isdir(build_root):
mkdir(build_root) mkdir(build_root)
Export('env') Export('main')
env.SConsignFile(joinpath(build_root, "sconsign")) main.SConsignFile(joinpath(build_root, "sconsign"))
# Default duplicate option is to use hard links, but this messes up # Default duplicate option is to use hard links, but this messes up
# when you use emacs to edit a file in the target dir, as emacs moves # when you use emacs to edit a file in the target dir, as emacs moves
# file to file~ then copies to file, breaking the link. Symbolic # file to file~ then copies to file, breaking the link. Symbolic
# (soft) links work better. # (soft) links work better.
env.SetOption('duplicate', 'soft-copy') main.SetOption('duplicate', 'soft-copy')
# #
# Set up global sticky variables... these are common to an entire build # Set up global sticky variables... these are common to an entire build
@ -339,8 +340,8 @@ global_sticky_vars_file = joinpath(build_root, 'variables.global')
global_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) global_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS)
global_sticky_vars.AddVariables( global_sticky_vars.AddVariables(
('CC', 'C compiler', environ.get('CC', env['CC'])), ('CC', 'C compiler', environ.get('CC', main['CC'])),
('CXX', 'C++ compiler', environ.get('CXX', env['CXX'])), ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
('BATCH', 'Use batch pool for build and tests', False), ('BATCH', 'Use batch pool for build and tests', False),
('BATCH_CMD', 'Batch pool submission command name', 'qdo'), ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
('EXTRAS', 'Add Extra directories to the compilation', '', ('EXTRAS', 'Add Extra directories to the compilation', '',
@ -354,19 +355,19 @@ Usage: scons [scons options] [build options] [target(s)]
Global sticky options: Global sticky options:
''' '''
help_text += global_sticky_vars.GenerateHelpText(env) help_text += global_sticky_vars.GenerateHelpText(main)
# Update env with values from ARGUMENTS & file global_sticky_vars_file # Update main environment with values from ARGUMENTS & global_sticky_vars_file
global_sticky_vars.Update(env) global_sticky_vars.Update(main)
# Save sticky variable settings back to current variables file # Save sticky variable settings back to current variables file
global_sticky_vars.Save(global_sticky_vars_file, env) global_sticky_vars.Save(global_sticky_vars_file, main)
# Parse EXTRAS variable to build list of all directories where we're # Parse EXTRAS variable to build list of all directories where we're
# look for sources etc. This list is exported as base_dir_list. # look for sources etc. This list is exported as base_dir_list.
base_dir = env.srcdir.abspath base_dir = main.srcdir.abspath
if env['EXTRAS']: if main['EXTRAS']:
extras_dir_list = env['EXTRAS'].split(':') extras_dir_list = main['EXTRAS'].split(':')
else: else:
extras_dir_list = [] extras_dir_list = []
@ -374,36 +375,36 @@ Export('base_dir')
Export('extras_dir_list') Export('extras_dir_list')
# the ext directory should be on the #includes path # the ext directory should be on the #includes path
env.Append(CPPPATH=[Dir('ext')]) main.Append(CPPPATH=[Dir('ext')])
# M5_PLY is used by isa_parser.py to find the PLY package. # M5_PLY is used by isa_parser.py to find the PLY package.
env.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath }) main.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath })
CXX_version = read_command([env['CXX'],'--version'], exception=False) CXX_version = read_command([main['CXX'],'--version'], exception=False)
CXX_V = read_command([env['CXX'],'-V'], exception=False) CXX_V = read_command([main['CXX'],'-V'], exception=False)
env['GCC'] = CXX_version and CXX_version.find('g++') >= 0 main['GCC'] = CXX_version and CXX_version.find('g++') >= 0
env['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 main['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
env['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 main['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
if env['GCC'] + env['SUNCC'] + env['ICC'] > 1: if main['GCC'] + main['SUNCC'] + main['ICC'] > 1:
print 'Error: How can we have two at the same time?' print 'Error: How can we have two at the same time?'
Exit(1) Exit(1)
# Set up default C++ compiler flags # Set up default C++ compiler flags
if env['GCC']: if main['GCC']:
env.Append(CCFLAGS='-pipe') main.Append(CCFLAGS='-pipe')
env.Append(CCFLAGS='-fno-strict-aliasing') main.Append(CCFLAGS='-fno-strict-aliasing')
env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) main.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
env.Append(CXXFLAGS='-Wno-deprecated') main.Append(CXXFLAGS='-Wno-deprecated')
elif env['ICC']: elif main['ICC']:
pass #Fix me... add warning flags once we clean up icc warnings pass #Fix me... add warning flags once we clean up icc warnings
elif env['SUNCC']: elif main['SUNCC']:
env.Append(CCFLAGS='-Qoption ccfe') main.Append(CCFLAGS='-Qoption ccfe')
env.Append(CCFLAGS='-features=gcc') main.Append(CCFLAGS='-features=gcc')
env.Append(CCFLAGS='-features=extensions') main.Append(CCFLAGS='-features=extensions')
env.Append(CCFLAGS='-library=stlport4') main.Append(CCFLAGS='-library=stlport4')
env.Append(CCFLAGS='-xar') main.Append(CCFLAGS='-xar')
#env.Append(CCFLAGS='-instances=semiexplicit') #main.Append(CCFLAGS='-instances=semiexplicit')
else: else:
print 'Error: Don\'t know what compiler options to use for your compiler.' print 'Error: Don\'t know what compiler options to use for your compiler.'
print ' Please fix SConstruct and src/SConscript and try again.' print ' Please fix SConstruct and src/SConscript and try again.'
@ -411,19 +412,19 @@ else:
# Do this after we save setting back, or else we'll tack on an # Do this after we save setting back, or else we'll tack on an
# extra 'qdo' every time we run scons. # extra 'qdo' every time we run scons.
if env['BATCH']: if main['BATCH']:
env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] main['CC'] = main['BATCH_CMD'] + ' ' + main['CC']
env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX']
env['AS'] = env['BATCH_CMD'] + ' ' + env['AS'] main['AS'] = main['BATCH_CMD'] + ' ' + main['AS']
env['AR'] = env['BATCH_CMD'] + ' ' + env['AR'] main['AR'] = main['BATCH_CMD'] + ' ' + main['AR']
env['RANLIB'] = env['BATCH_CMD'] + ' ' + env['RANLIB'] main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
if sys.platform == 'cygwin': if sys.platform == 'cygwin':
# cygwin has some header file issues... # cygwin has some header file issues...
env.Append(CCFLAGS=Split("-Wno-uninitialized")) main.Append(CCFLAGS=Split("-Wno-uninitialized"))
# Check for SWIG # Check for SWIG
if not env.has_key('SWIG'): if not main.has_key('SWIG'):
print 'Error: SWIG utility not found.' print 'Error: SWIG utility not found.'
print ' Please install (see http://www.swig.org) and retry.' print ' Please install (see http://www.swig.org) and retry.'
Exit(1) Exit(1)
@ -444,12 +445,12 @@ if compare_versions(swig_version[2], min_swig_version) < 0:
# Set up SWIG flags & scanner # Set up SWIG flags & scanner
swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
env.Append(SWIGFLAGS=swig_flags) main.Append(SWIGFLAGS=swig_flags)
# filter out all existing swig scanners, they mess up the dependency # filter out all existing swig scanners, they mess up the dependency
# stuff for some reason # stuff for some reason
scanners = [] scanners = []
for scanner in env['SCANNERS']: for scanner in main['SCANNERS']:
skeys = scanner.skeys skeys = scanner.skeys
if skeys == '.i': if skeys == '.i':
continue continue
@ -465,7 +466,7 @@ swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
# replace the scanners list that has what we want # replace the scanners list that has what we want
env['SCANNERS'] = scanners main['SCANNERS'] = scanners
# Add a custom Check function to the Configure context so that we can # Add a custom Check function to the Configure context so that we can
# figure out if the compiler adds leading underscores to global # figure out if the compiler adds leading underscores to global
@ -495,7 +496,7 @@ def CheckLeading(context):
# Platform-specific configuration. Note again that we assume that all # Platform-specific configuration. Note again that we assume that all
# builds under a given build root run on the same host platform. # builds under a given build root run on the same host platform.
conf = Configure(env, conf = Configure(main,
conf_dir = joinpath(build_root, '.scons_config'), conf_dir = joinpath(build_root, '.scons_config'),
log_file = joinpath(build_root, 'scons_config.log'), log_file = joinpath(build_root, 'scons_config.log'),
custom_tests = { 'CheckLeading' : CheckLeading }) custom_tests = { 'CheckLeading' : CheckLeading })
@ -510,10 +511,10 @@ try:
uname = platform.uname() uname = platform.uname()
if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
if int(read_command('sysctl -n hw.cpu64bit_capable')[0]): if int(read_command('sysctl -n hw.cpu64bit_capable')[0]):
env.Append(CCFLAGS='-arch x86_64') main.Append(CCFLAGS='-arch x86_64')
env.Append(CFLAGS='-arch x86_64') main.Append(CFLAGS='-arch x86_64')
env.Append(LINKFLAGS='-arch x86_64') main.Append(LINKFLAGS='-arch x86_64')
env.Append(ASFLAGS='-arch x86_64') main.Append(ASFLAGS='-arch x86_64')
except: except:
pass pass
@ -534,7 +535,7 @@ if not conf:
def __getattr__(self, mname): def __getattr__(self, mname):
return NullCheck return NullCheck
conf = NullConf(env) conf = NullConf(main)
# Find Python include and library directories for embedding the # Find Python include and library directories for embedding the
# interpreter. For consistency, we will use the same Python # interpreter. For consistency, we will use the same Python
@ -567,8 +568,8 @@ for lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
py_libs.append(lib) py_libs.append(lib)
py_libs.append(py_version) py_libs.append(py_version)
env.Append(CPPPATH=py_includes) main.Append(CPPPATH=py_includes)
env.Append(LIBPATH=py_lib_path) main.Append(LIBPATH=py_lib_path)
# verify that this stuff works # verify that this stuff works
if not conf.CheckHeader('Python.h', '<>'): if not conf.CheckHeader('Python.h', '<>'):
@ -630,15 +631,13 @@ if have_mysql:
# #
# Finish the configuration # Finish the configuration
# #
env = conf.Finish() main = conf.Finish()
###################################################################### ######################################################################
# #
# Collect all non-global variables # Collect all non-global variables
# #
Export('env')
# Define the universe of supported ISAs # Define the universe of supported ISAs
all_isa_list = [ ] all_isa_list = [ ]
Export('all_isa_list') Export('all_isa_list')
@ -750,14 +749,14 @@ def config_emitter(target, source, env):
config_builder = Builder(emitter = config_emitter, action = config_action) config_builder = Builder(emitter = config_emitter, action = config_action)
env.Append(BUILDERS = { 'ConfigFile' : config_builder }) main.Append(BUILDERS = { 'ConfigFile' : config_builder })
# libelf build is shared across all configs in the build root. # libelf build is shared across all configs in the build root.
env.SConscript('ext/libelf/SConscript', main.SConscript('ext/libelf/SConscript',
variant_dir = joinpath(build_root, 'libelf')) variant_dir = joinpath(build_root, 'libelf'))
# gzstream build is shared across all configs in the build root. # gzstream build is shared across all configs in the build root.
env.SConscript('ext/gzstream/SConscript', main.SConscript('ext/gzstream/SConscript',
variant_dir = joinpath(build_root, 'gzstream')) variant_dir = joinpath(build_root, 'gzstream'))
################################################### ###################################################
@ -766,7 +765,7 @@ env.SConscript('ext/gzstream/SConscript',
# #
################################################### ###################################################
env['ALL_ISA_LIST'] = all_isa_list main['ALL_ISA_LIST'] = all_isa_list
def make_switching_dir(dname, switch_headers, env): def make_switching_dir(dname, switch_headers, env):
# Generate the header. target[0] is the full path of the output # Generate the header. target[0] is the full path of the output
# header to generate. 'source' is a dummy variable, since we get the # header to generate. 'source' is a dummy variable, since we get the
@ -806,14 +805,11 @@ Export('make_switching_dir')
# #
################################################### ###################################################
# rename base env
base_env = env
for variant_path in variant_paths: for variant_path in variant_paths:
print "Building in", variant_path print "Building in", variant_path
# Make a copy of the build-root environment to use for this config. # Make a copy of the build-root environment to use for this config.
env = base_env.Clone() env = main.Clone()
env['BUILDDIR'] = variant_path env['BUILDDIR'] = variant_path
# variant_dir is the tail component of build path, and is used to # variant_dir is the tail component of build path, and is used to

View file

@ -28,11 +28,11 @@
# #
# Authors: Nathan Binkert # Authors: Nathan Binkert
Import('env') Import('main')
env.Library('gzstream', [File('gzstream.cc')]) main.Library('gzstream', [File('gzstream.cc')])
env.Prepend(CPPPATH=Dir('.')) main.Prepend(CPPPATH=Dir('.'))
env.Append(LIBS=['gzstream']) main.Append(LIBS=['gzstream'])
env.Prepend(LIBPATH=[Dir('.')]) main.Prepend(LIBPATH=[Dir('.')])

View file

@ -30,7 +30,7 @@
import os, subprocess import os, subprocess
Import('env') Import('main')
elf_files = [] elf_files = []
def ElfFile(filename): def ElfFile(filename):
@ -87,9 +87,9 @@ ElfFile('libelf_convert.c')
ElfFile('libelf_fsize.c') ElfFile('libelf_fsize.c')
ElfFile('libelf_msize.c') ElfFile('libelf_msize.c')
m4env = env.Clone() m4env = main.Clone()
if env['GCC']: if m4env['GCC']:
major,minor,dot = [ int(x) for x in env['CXXVERSION'].split('.')] major,minor,dot = [ int(x) for x in m4env['CXXVERSION'].split('.')]
if major >= 4: if major >= 4:
m4env.Append(CCFLAGS=['-Wno-pointer-sign']) m4env.Append(CCFLAGS=['-Wno-pointer-sign'])
m4env.Append(CCFLAGS=['-Wno-implicit']) m4env.Append(CCFLAGS=['-Wno-implicit'])
@ -119,7 +119,7 @@ m4env.M4(target=File('libelf_msize.c'),
# into either m5 or the library # into either m5 or the library
m4env.Library('elf', [m4env.SharedObject(f) for f in elf_files]) m4env.Library('elf', [m4env.SharedObject(f) for f in elf_files])
env.Prepend(CPPPATH=Dir('.')) main.Prepend(CPPPATH=Dir('.'))
env.Append(LIBS=['elf']) main.Append(LIBS=['elf'])
env.Prepend(LIBPATH=[Dir('.')]) main.Prepend(LIBPATH=[Dir('.')])