summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2002-10-07 23:50:06 (GMT)
committerSteven Knight <knight@baldmt.com>2002-10-07 23:50:06 (GMT)
commitbbdf3e20a90dabfe9944bfc58e6756cf799df7e9 (patch)
tree6bfa44d8dd2407ce2973a3b688860629accc0e50
parentbdf39335f8eff310c749fa5a9d08697aa81a003b (diff)
downloadSCons-bbdf3e20a90dabfe9944bfc58e6756cf799df7e9.zip
SCons-bbdf3e20a90dabfe9944bfc58e6756cf799df7e9.tar.gz
SCons-bbdf3e20a90dabfe9944bfc58e6756cf799df7e9.tar.bz2
Get rid of the magicness of the magic _ variables. (Anthony Roach)
-rw-r--r--doc/man/scons.143
-rw-r--r--src/CHANGES.txt6
-rw-r--r--src/engine/SCons/Defaults.py51
-rw-r--r--src/engine/SCons/Environment.py130
-rw-r--r--src/engine/SCons/EnvironmentTests.py204
-rw-r--r--src/engine/SCons/Node/FS.py76
-rw-r--r--src/engine/SCons/Node/FSTests.py35
-rw-r--r--src/engine/SCons/Node/NodeTests.py2
-rw-r--r--src/engine/SCons/Node/__init__.py10
-rw-r--r--src/engine/SCons/Tool/mslink.py4
-rw-r--r--src/engine/SCons/Tool/msvc.py10
-rw-r--r--test/Environment.py53
-rw-r--r--test/LIBS.py7
-rw-r--r--test/msvc.py31
14 files changed, 361 insertions, 301 deletions
diff --git a/doc/man/scons.1 b/doc/man/scons.1
index 34cbcd4..7a9790a 100644
--- a/doc/man/scons.1
+++ b/doc/man/scons.1
@@ -1,5 +1,3 @@
-.\" 1. Builder's __call__ method can now take arbitrary keyword arguments.
-.\" These args are saved with the target node of the build, then passed along
.\" Copyright (c) 2001, 2002 Steven Knight
.\"
.\" Permission is hereby granted, free of charge, to any person obtaining
@@ -1407,6 +1405,19 @@ SCons also treats
(upper case) files
as C files.
+.IP _concat
+A function used to produce variables like $_CPPINCFLAGS. It takes six
+arguments: a prefix to concatenate onto each element, a list of elements, a
+suffix to concatenate onto each element, a dictionary of global variables
+for variable interpolation, a list of local variables for variable
+interpolation, and an optional function that will be called to transform the list
+before concatenation.
+
+.ES
+env['_CPPINCFLAGS'] = '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, locals(), globals(), RDirs)} $)',
+.EE
+
+
.IP CPPFLAGS
C preprocessor options.
These will be included in any command that uses the C preprocessor,
@@ -1501,6 +1512,10 @@ are included on this command line.
.IP CXXFLAGS
General options that are passed to the C++ compiler.
+.IP Dir
+A function that converts a file name into a Dir instance relative to the
+target being built.
+
.IP DVIPDF
The TeX DVI file to PDF file converter.
@@ -1627,6 +1642,10 @@ after first running the file through the C preprocessor.
Any options specified in the $F77FLAGS and $CPPFLAGS construction variables
are included on this command line.
+.IP File
+A function that converts a file name into a File instance relative to the
+target being built.
+
.IP INCPREFIX
The prefix used to specify an include directory on the C compiler command
line.
@@ -1806,11 +1825,10 @@ object files. This variable is ignored by tools other than Microsoft Visual C++.
When this variable is
defined SCons will add options to the compiler command line to
cause it to use the precompiled header, and will also set up the
-dependencies for the PCH file. This variable must reference a File instance created either
-with File() or returned by the PCH builder:
+dependencies for the PCH file. Example:
.ES
-env['PCH'] = env.PCH('StdAfx.cpp')[0]
+env['PCH'] = 'StdAfx.pch'
.EE
.IP PCHSTOP
@@ -1822,7 +1840,7 @@ is included at the end of the precompiled portion of the source files, or
the empty string if the "#pragma hrdstop" construct is being used:
.ES
-env['PCHSTOP'] = File('StdAfx.h')
+env['PCHSTOP'] = 'StdAfx.h'
.EE
@@ -1834,11 +1852,10 @@ tools other than Microsoft Visual C++.
When this variable is
defined SCons will add options to the compiler and linker command line to
cause them to generate external debugging information, and will also set up the
-dependencies for the PDB file. This variable must reference
-a File instance created with File():
+dependencies for the PDB file. Example:
.ES
-env['PDB'] = File('hello.pdb')
+env['PDB'] = 'hello.pdb'
.EE
.IP PDFCOM
@@ -1871,6 +1888,10 @@ The archive indexer.
.IP RANLIBFLAGS
General options passed to the archive indexer.
+.IP RDirs
+A function that converts a file name into a list of Dir instances by
+searching the repositories.
+
.IP SCANNERS
A list of the available implicit dependency scanners. [CScan] by default.
@@ -3296,7 +3317,7 @@ Bar.cpp:
SConstruct:
.ES
env=Environment()
-env['PCHSTOP'] = File('StdAfx.h')
+env['PCHSTOP'] = StdAfx.h
env['PCH'] = env.PCH('StdAfx.cpp')[0]
env.Program('MyApp', ['Foo.cpp', 'Bar.cpp'])
.EE
@@ -3316,7 +3337,7 @@ variable.
SConstruct:
.ES
env=Environment()
-env['PDB'] = File('MyApp.pdb')
+env['PDB'] = 'MyApp.pdb'
env.Program('MyApp', ['Foo.cpp', 'Bar.cpp'])
.EE
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 838e178..bda8903 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -82,6 +82,12 @@ RELEASE 0.09 -
- Add support for Microsoft VC++ precompiled header (.pch)
and debugger (.pdb) files.
+ - Don't compute the $_CPPINCFLAGS, $_F77INCFLAGS, $_LIBFLAGS and
+ $_LIBDIRFLAGS variables each time a command is executed, define
+ them so they're computed only as needed. Add a new _concat
+ function to the Environment that allows people to define their
+ own similar variables.
+
From sam th:
- Dynamically check for the existence of utilities with which to
diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py
index 4e8cf4e..e50be98 100644
--- a/src/engine/SCons/Defaults.py
+++ b/src/engine/SCons/Defaults.py
@@ -185,6 +185,52 @@ Program = SCons.Builder.Builder(action=[ StaticCheck, '$LINKCOM' ],
src_builder='Object',
scanner = ProgScan)
+def _concat(prefix, list, suffix, locals, globals, f=lambda x: x):
+ """Creates a new list from 'list' by first interpolating each element
+ in the list using 'locals' and 'globals' and then calling f on the list, and
+ finally concatinating 'prefix' and 'suffix' onto each element of the
+ list. A trailing space on 'prefix' or leading space on 'suffix' will
+ cause them to be put into seperate list elements rather than being
+ concatinated."""
+
+ if not list:
+ return list
+
+ if not SCons.Util.is_List(list):
+ list = [list]
+
+ def subst(x, locals=locals, globals=globals):
+ if SCons.Util.is_String(x):
+ return SCons.Util.scons_subst(x, locals, globals)
+ else:
+ return x
+
+ list = map(subst, list)
+
+ list = f(list)
+
+ ret = []
+
+ # ensure that prefix and suffix are strings
+ prefix = str(prefix)
+ suffix = str(suffix)
+
+ for x in list:
+ x = str(x)
+
+ if prefix and prefix[-1] == ' ':
+ ret.append(prefix[:-1])
+ ret.append(x)
+ else:
+ ret.append(prefix+x)
+
+ if suffix and suffix[0] == ' ':
+ ret.append(suffix[1:])
+ else:
+ ret[-1] = ret[-1]+suffix
+
+ return ret
+
ConstructionEnvironment = {
'BUILDERS' : { 'SharedLibrary' : SharedLibrary,
'Library' : StaticLibrary,
@@ -197,4 +243,9 @@ ConstructionEnvironment = {
'PSPREFIX' : '',
'PSSUFFIX' : '.ps',
'ENV' : {},
+ '_concat' : _concat,
+ '_LIBFLAGS' : '${_concat(LIBLINKPREFIX, LIBS, LIBLINKSUFFIX, locals(), globals())}',
+ '_LIBDIRFLAGS' : '$( ${_concat(LIBDIRPREFIX, LIBPATH, LIBDIRSUFFIX, locals(), globals(), RDirs)} $)',
+ '_CPPINCFLAGS' : '$( ${_concat(INCPREFIX, CPPPATH, INCSUFFIX, locals(), globals(), RDirs)} $)',
+ '_F77INCFLAGS' : '$( ${_concat(INCPREFIX, F77PATH, INCSUFFIX, locals(), globals(), RDirs)} $)'
}
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index 1a1dd49..c0b3255 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -159,38 +159,6 @@ class Environment:
if options:
options.Update(self)
- #
- # self.autogen_vars is a tuple of tuples. Each inner tuple
- # has four elements, each strings referring to an environment
- # variable, and describing how to autogenerate a particular
- # variable. The elements are:
- #
- # 0 - The variable to generate
- # 1 - The "source" variable, usually a list
- # 2 - The "prefix" variable
- # 3 - The "suffix" variable
- #
- # The autogenerated variable is a list, consisting of every
- # element of the source list, or a single element if the source
- # is a string, with the prefix and suffix concatenated.
- #
- self.autogen_vars = ( VarInterpolator('_LIBFLAGS',
- 'LIBS',
- 'LIBLINKPREFIX',
- 'LIBLINKSUFFIX'),
- DirVarInterp('_LIBDIRFLAGS',
- 'LIBPATH',
- 'LIBDIRPREFIX',
- 'LIBDIRSUFFIX' ),
- DirVarInterp('_CPPINCFLAGS',
- 'CPPPATH',
- 'INCPREFIX',
- 'INCSUFFIX'),
- DirVarInterp('_F77INCFLAGS',
- 'F77PATH',
- 'INCPREFIX',
- 'INCSUFFIX') )
-
def __cmp__(self, other):
return cmp(self._dict, other._dict)
@@ -454,15 +422,6 @@ class Environment:
return scanner
return None
- def autogenerate(self, fs = SCons.Node.FS.default_fs, dir = None):
- """Return a dictionary of autogenerated "interpolated"
- construction variables.
- """
- dict = {}
- for interp in self.autogen_vars:
- interp.instance(dir, fs).generate(dict, self._dict)
- return dict
-
def get_builder(self, name):
"""Fetch the builder with the specified name from the environment.
"""
@@ -518,92 +477,3 @@ class Environment:
"Emulates the items() method of dictionaries."""
return self._dict.items()
-class VarInterpolator:
- def __init__(self, dest, src, prefix, suffix):
- self.dest = dest
- if not SCons.Util.is_List(src):
- src = [ src ]
- self.src = src
- self.prefix = prefix
- self.suffix = suffix
-
- def prepareSrc(self, dict):
- src = []
- for s in self.src:
- if dict.has_key(s):
- cv = dict[s]
- if SCons.Util.is_String(cv):
- src.extend(string.split(cv))
- elif SCons.Util.is_List(cv):
- src.extend(cv)
- else:
- src.append(cv)
-
- def prepare(x, dict=dict):
- if isinstance(x, SCons.Node.Node):
- return x
- else:
- return SCons.Util.scons_subst(x, {}, dict)
-
- return map(prepare, src)
-
- def generate(self, ddict, sdict):
- src = filter(lambda x: not x is None, self.prepareSrc(sdict))
-
- if not src:
- ddict[self.dest] = ''
- return
-
- prefix = sdict.get(self.prefix, '')
- suffix = sdict.get(self.suffix, '')
-
- def autogenFunc(x, suff=suffix, pref=prefix):
- """Generate the interpolated variable. If the prefix
- ends in a space, or the suffix begins in a space,
- leave it as a separate element of the list."""
- ret = [ str(x) ]
- if pref and pref[-1] == ' ':
- ret.insert(0, pref[:-1])
- else:
- ret[0] = pref + ret[0]
- if suff and suff[0] == ' ':
- ret.append(suff[1:])
- else:
- ret[-1] = ret[-1] + suff
- return ret
-
- ddict[self.dest] = reduce(lambda x, y: x+y,
- map(autogenFunc, src))
-
- def instance(self, dir, fs):
- return self
-
-class DirVarInterp(VarInterpolator):
- def __init__(self, dest, src, prefix, suffix):
- VarInterpolator.__init__(self, dest, src, prefix, suffix)
- self.fs = None
- self.Dir = None
- self.dictInstCache = {}
-
- def prepareSrc(self, dict):
- src = VarInterpolator.prepareSrc(self, dict)
- def path_dirs(rep, path, fs=self.fs, dir=self.dir):
- if rep:
- path = os.path.join(rep, path)
- return fs.Dir(path, directory = dir)
- return self.fs.Rsearchall(src, path_dirs)
-
- def instance(self, dir, fs):
- try:
- ret = self.dictInstCache[(dir, fs)]
- except KeyError:
- ret = copy.copy(self)
- ret.fs = fs
- ret.dir = dir
- self.dictInstCache[(dir, fs)] = ret
- return ret
-
- def generate(self, ddict, sdict):
- VarInterpolator.generate(self, ddict, sdict)
- if ddict[self.dest]:
- ddict[self.dest] = ['$('] + ddict[self.dest] + ['$)']
diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py
index 40c4f93..45b6901 100644
--- a/src/engine/SCons/EnvironmentTests.py
+++ b/src/engine/SCons/EnvironmentTests.py
@@ -484,116 +484,136 @@ class EnvironmentTestCase(unittest.TestCase):
def test_autogenerate(dict):
"""Test autogenerating variables in a dictionary."""
+
+ def Dir(name):
+ dir = SCons.Node.FS.default_fs.Dir('/xx')
+ return SCons.Node.FS.default_fs.Dir(name, dir)
+
+ def File(name):
+ dir = SCons.Node.FS.default_fs.Dir('/xx')
+ return SCons.Node.FS.default_fs.File(name, dir)
+
+ def RDirs(pathlist, Dir=Dir):
+ def path_dirs(rep, path, Dir=Dir):
+ if rep:
+ path = os.path.join(rep, path)
+ return Dir(path)
+
+ return SCons.Node.FS.default_fs.Rsearchall(pathlist, path_dirs)
+
env = Environment(LIBS = [ 'foo', 'bar', 'baz' ],
LIBLINKPREFIX = 'foo',
- LIBLINKSUFFIX = 'bar')
- dict = env.autogenerate(dir = SCons.Node.FS.default_fs.Dir('/xx'))
- assert len(dict['_LIBFLAGS']) == 3, dict['_LIBFLAGS']
- assert dict['_LIBFLAGS'][0] == 'foofoobar', \
- dict['_LIBFLAGS'][0]
- assert dict['_LIBFLAGS'][1] == 'foobarbar', \
- dict['_LIBFLAGS'][1]
- assert dict['_LIBFLAGS'][2] == 'foobazbar', \
- dict['_LIBFLAGS'][2]
+ LIBLINKSUFFIX = 'bar',
+ Dir=Dir, File=File, RDirs=RDirs)
+ flags = env.subst_list('$_LIBFLAGS', 1)[0]
+ assert len(flags) == 3, flags
+ assert flags[0] == 'foofoobar', \
+ flags[0]
+ assert flags[1] == 'foobarbar', \
+ flags[1]
+ assert flags[2] == 'foobazbar', \
+ flags[2]
blat = SCons.Node.FS.default_fs.Dir('blat')
env = Environment(CPPPATH = [ 'foo', '$FOO/bar', blat ],
INCPREFIX = 'foo ',
INCSUFFIX = 'bar',
- FOO = 'baz')
- dict = env.autogenerate(dir = SCons.Node.FS.default_fs.Dir('/xx'))
- assert len(dict['_CPPINCFLAGS']) == 8, dict['_CPPINCFLAGS']
- assert dict['_CPPINCFLAGS'][0] == '$(', \
- dict['_CPPINCFLAGS'][0]
- assert dict['_CPPINCFLAGS'][1] == os.path.normpath('foo'), \
- dict['_CPPINCFLAGS'][1]
- assert dict['_CPPINCFLAGS'][2] == os.path.normpath('/xx/foobar'), \
- dict['_CPPINCFLAGS'][2]
- assert dict['_CPPINCFLAGS'][3] == os.path.normpath('foo'), \
- dict['_CPPINCFLAGS'][3]
- assert dict['_CPPINCFLAGS'][4] == os.path.normpath('/xx/baz/barbar'), \
- dict['_CPPINCFLAGS'][4]
- assert dict['_CPPINCFLAGS'][5] == os.path.normpath('foo'), \
- dict['_CPPINCFLAGS'][5]
- assert dict['_CPPINCFLAGS'][6] == os.path.normpath('blatbar'), \
- dict['_CPPINCFLAGS'][6]
- assert dict['_CPPINCFLAGS'][7] == '$)', \
- dict['_CPPINCFLAGS'][7]
+ FOO = 'baz',
+ Dir=Dir, File=File, RDirs=RDirs)
+ flags = env.subst_list('$_CPPINCFLAGS', 1)[0]
+ assert len(flags) == 8, flags
+ assert flags[0] == '$(', \
+ flags[0]
+ assert flags[1] == os.path.normpath('foo'), \
+ flags[1]
+ assert flags[2] == os.path.normpath('/xx/foobar'), \
+ flags[2]
+ assert flags[3] == os.path.normpath('foo'), \
+ flags[3]
+ assert flags[4] == os.path.normpath('/xx/baz/barbar'), \
+ flags[4]
+ assert flags[5] == os.path.normpath('foo'), \
+ flags[5]
+ assert flags[6] == os.path.normpath('blatbar'), \
+ flags[6]
+ assert flags[7] == '$)', \
+ flags[7]
env = Environment(F77PATH = [ 'foo', '$FOO/bar', blat ],
INCPREFIX = 'foo ',
INCSUFFIX = 'bar',
- FOO = 'baz')
- dict = env.autogenerate(dir = SCons.Node.FS.default_fs.Dir('/xx'))
- assert len(dict['_F77INCFLAGS']) == 8, dict['_F77INCFLAGS']
- assert dict['_F77INCFLAGS'][0] == '$(', \
- dict['_F77INCFLAGS'][0]
- assert dict['_F77INCFLAGS'][1] == os.path.normpath('foo'), \
- dict['_F77INCFLAGS'][1]
- assert dict['_F77INCFLAGS'][2] == os.path.normpath('/xx/foobar'), \
- dict['_F77INCFLAGS'][2]
- assert dict['_F77INCFLAGS'][3] == os.path.normpath('foo'), \
- dict['_F77INCFLAGS'][3]
- assert dict['_F77INCFLAGS'][4] == os.path.normpath('/xx/baz/barbar'), \
- dict['_F77INCFLAGS'][4]
- assert dict['_F77INCFLAGS'][5] == os.path.normpath('foo'), \
- dict['_F77INCFLAGS'][5]
- assert dict['_F77INCFLAGS'][6] == os.path.normpath('blatbar'), \
- dict['_F77INCFLAGS'][6]
- assert dict['_F77INCFLAGS'][7] == '$)', \
- dict['_F77INCFLAGS'][7]
-
- env = Environment(CPPPATH = '', F77PATH = '', LIBPATH = '')
- dict = env.autogenerate(dir = SCons.Node.FS.default_fs.Dir('/yy'))
- assert len(dict['_CPPINCFLAGS']) == 0, dict['_CPPINCFLAGS']
- assert len(dict['_F77INCFLAGS']) == 0, dict['_F77INCFLAGS']
- assert len(dict['_LIBDIRFLAGS']) == 0, dict['_LIBDIRFLAGS']
+ FOO = 'baz',
+ Dir=Dir, File=File, RDirs=RDirs)
+ flags = env.subst_list('$_F77INCFLAGS', 1)[0]
+ assert len(flags) == 8, flags
+ assert flags[0] == '$(', \
+ flags[0]
+ assert flags[1] == os.path.normpath('foo'), \
+ flags[1]
+ assert flags[2] == os.path.normpath('/xx/foobar'), \
+ flags[2]
+ assert flags[3] == os.path.normpath('foo'), \
+ flags[3]
+ assert flags[4] == os.path.normpath('/xx/baz/barbar'), \
+ flags[4]
+ assert flags[5] == os.path.normpath('foo'), \
+ flags[5]
+ assert flags[6] == os.path.normpath('blatbar'), \
+ flags[6]
+ assert flags[7] == '$)', \
+ flags[7]
+
+ env = Environment(CPPPATH = '', F77PATH = '', LIBPATH = '',
+ Dir=Dir, File=File, RDirs=RDirs)
+ assert len(env.subst_list('$_CPPINCFLAGS')[0]) == 0
+ assert len(env.subst_list('$_F77INCFLAGS')[0]) == 0
+ assert len(env.subst_list('$_LIBDIRFLAGS')[0]) == 0
SCons.Node.FS.default_fs.Repository('/rep1')
SCons.Node.FS.default_fs.Repository('/rep2')
env = Environment(CPPPATH = [ 'foo', '/a/b', '$FOO/bar', blat],
INCPREFIX = '-I ',
INCSUFFIX = 'XXX',
- FOO = 'baz')
- dict = env.autogenerate(dir = SCons.Node.FS.default_fs.Dir('/xx'))
- assert len(dict['_CPPINCFLAGS']) == 18, dict['_CPPINCFLAGS']
- assert dict['_CPPINCFLAGS'][0] == '$(', \
- dict['_CPPINCFLAGS'][0]
- assert dict['_CPPINCFLAGS'][1] == '-I', \
- dict['_CPPINCFLAGS'][1]
- assert dict['_CPPINCFLAGS'][2] == os.path.normpath('/xx/fooXXX'), \
- dict['_CPPINCFLAGS'][2]
- assert dict['_CPPINCFLAGS'][3] == '-I', \
- dict['_CPPINCFLAGS'][3]
- assert dict['_CPPINCFLAGS'][4] == os.path.normpath('/rep1/fooXXX'), \
- dict['_CPPINCFLAGS'][4]
- assert dict['_CPPINCFLAGS'][5] == '-I', \
- dict['_CPPINCFLAGS'][5]
- assert dict['_CPPINCFLAGS'][6] == os.path.normpath('/rep2/fooXXX'), \
- dict['_CPPINCFLAGS'][6]
- assert dict['_CPPINCFLAGS'][7] == '-I', \
- dict['_CPPINCFLAGS'][7]
- assert dict['_CPPINCFLAGS'][8] == os.path.normpath('/a/bXXX'), \
- dict['_CPPINCFLAGS'][8]
- assert dict['_CPPINCFLAGS'][9] == '-I', \
- dict['_CPPINCFLAGS'][9]
- assert dict['_CPPINCFLAGS'][10] == os.path.normpath('/xx/baz/barXXX'), \
- dict['_CPPINCFLAGS'][10]
- assert dict['_CPPINCFLAGS'][11] == '-I', \
- dict['_CPPINCFLAGS'][11]
- assert dict['_CPPINCFLAGS'][12] == os.path.normpath('/rep1/baz/barXXX'), \
- dict['_CPPINCFLAGS'][12]
- assert dict['_CPPINCFLAGS'][13] == '-I', \
- dict['_CPPINCFLAGS'][13]
- assert dict['_CPPINCFLAGS'][14] == os.path.normpath('/rep2/baz/barXXX'), \
- dict['_CPPINCFLAGS'][14]
- assert dict['_CPPINCFLAGS'][15] == '-I', \
- dict['_CPPINCFLAGS'][15]
- assert dict['_CPPINCFLAGS'][16] == os.path.normpath('blatXXX'), \
- dict['_CPPINCFLAGS'][16]
- assert dict['_CPPINCFLAGS'][17] == '$)', \
- dict['_CPPINCFLAGS'][17]
+ FOO = 'baz',
+ Dir=Dir, File=File, RDirs=RDirs)
+ flags = env.subst_list('$_CPPINCFLAGS', 1)[0]
+ assert flags[0] == '$(', \
+ flags[0]
+ assert flags[1] == '-I', \
+ flags[1]
+ assert flags[2] == os.path.normpath('/xx/fooXXX'), \
+ flags[2]
+ assert flags[3] == '-I', \
+ flags[3]
+ assert flags[4] == os.path.normpath('/rep1/fooXXX'), \
+ flags[4]
+ assert flags[5] == '-I', \
+ flags[5]
+ assert flags[6] == os.path.normpath('/rep2/fooXXX'), \
+ flags[6]
+ assert flags[7] == '-I', \
+ flags[7]
+ assert flags[8] == os.path.normpath('/a/bXXX'), \
+ flags[8]
+ assert flags[9] == '-I', \
+ flags[9]
+ assert flags[10] == os.path.normpath('/xx/baz/barXXX'), \
+ flags[10]
+ assert flags[11] == '-I', \
+ flags[11]
+ assert flags[12] == os.path.normpath('/rep1/baz/barXXX'), \
+ flags[12]
+ assert flags[13] == '-I', \
+ flags[13]
+ assert flags[14] == os.path.normpath('/rep2/baz/barXXX'), \
+ flags[14]
+ assert flags[15] == '-I', \
+ flags[15]
+ assert flags[16] == os.path.normpath('blatXXX'), \
+ flags[16]
+ assert flags[17] == '$)', \
+ flags[17]
def test_Detect(self):
"""Test Detect()ing tools"""
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index bdabdf2..1ac7566 100644
--- a/src/engine/SCons/Node/FS.py
+++ b/src/engine/SCons/Node/FS.py
@@ -170,7 +170,7 @@ class FS:
except KeyError:
if not create:
raise UserError
- dir = Dir(drive, ParentOfRoot())
+ dir = Dir(drive, ParentOfRoot(), self)
dir.path = dir.path + os.sep
dir.abspath = dir.abspath + os.sep
dir.srcpath = dir.srcpath + os.sep
@@ -197,7 +197,7 @@ class FS:
raise TypeError, \
"File %s found where directory expected." % path
- dir_temp = Dir(path_name, directory)
+ dir_temp = Dir(path_name, directory, self)
directory.entries[path_norm] = dir_temp
directory.add_wkid(dir_temp)
directory = dir_temp
@@ -220,8 +220,7 @@ class FS:
raise TypeError, \
"File %s found where directory expected." % path
- ret = fsclass(path_comp[-1], directory)
- ret.fs = self
+ ret = fsclass(path_comp[-1], directory, self)
directory.entries[file_name] = ret
directory.add_wkid(ret)
return ret
@@ -256,15 +255,22 @@ class FS:
if not dir is None:
self._cwd = dir
- def Entry(self, name, directory = None, create = 1):
+ def Entry(self, name, directory = None, create = 1, klass=None):
"""Lookup or create a generic Entry node with the specified name.
If the name is a relative path (begins with ./, ../, or a file
name), then it is looked up relative to the supplied directory
node, or to the top level directory of the FS (supplied at
construction time) if no directory is supplied.
"""
- name, directory = self.__transformPath(name, directory)
- return self.__doLookup(Entry, name, directory, create)
+
+ if not klass:
+ klass = Entry
+
+ if isinstance(name, Entry):
+ return self.__checkClass(name, klass)
+ else:
+ name, directory = self.__transformPath(name, directory)
+ return self.__doLookup(klass, name, directory, create)
def File(self, name, directory = None, create = 1):
"""Lookup or create a File node with the specified name. If
@@ -276,9 +282,9 @@ class FS:
This method will raise TypeError if a directory is found at the
specified path.
"""
- name, directory = self.__transformPath(name, directory)
- return self.__doLookup(File, name, directory, create)
+ return self.Entry(name, directory, create, File)
+
def Dir(self, name, directory = None, create = 1):
"""Lookup or create a Dir node with the specified name. If
the name is a relative path (begins with ./, ../, or a file name),
@@ -289,9 +295,9 @@ class FS:
This method will raise TypeError if a normal file is found at the
specified path.
"""
- name, directory = self.__transformPath(name, directory)
- return self.__doLookup(Dir, name, directory, create)
+ return self.Entry(name, directory, create, Dir)
+
def BuildDir(self, build_dir, src_dir, duplicate=1):
"""Link the supplied build directory to the source directory
for purposes of building files."""
@@ -363,7 +369,7 @@ class Entry(SCons.Node.Node):
Python's built-in object identity comparison.
"""
- def __init__(self, name, directory):
+ def __init__(self, name, directory, fs):
"""Initialize a generic file system Entry.
Call the superclass initialization, take care of setting up
@@ -390,7 +396,8 @@ class Entry(SCons.Node.Node):
self.srcpath_ = self.srcpath
self.cwd = None # will hold the SConscript directory for target nodes
self._local = None
-
+ self.fs = fs # The filesystem that this entry is part of
+
def get_dir(self):
return self.dir
@@ -474,8 +481,8 @@ class Dir(Entry):
"""A class for directories in a file system.
"""
- def __init__(self, name, directory):
- Entry.__init__(self, name, directory)
+ def __init__(self, name, directory, fs):
+ Entry.__init__(self, name, directory, fs)
self._morph()
def _morph(self):
@@ -499,6 +506,14 @@ class Dir(Entry):
self.builder = 1
self._sconsign = None
+ def Dir(self, name):
+ """Create a directory node named 'name' relative to this directory."""
+ return self.fs.Dir(name, self)
+
+ def File(self, name):
+ """Create file node named 'name' relatove to this directory."""
+ return self.fs.File(name, self)
+
def __doReparent(self, duplicate):
for ent in self.entries.values():
if not ent is self and not ent is self.dir:
@@ -616,9 +631,36 @@ class Dir(Entry):
class File(Entry):
"""A class for files in a file system.
"""
- def __init__(self, name, directory = None):
- Entry.__init__(self, name, directory)
+ def __init__(self, name, directory, fs):
+ Entry.__init__(self, name, directory, fs)
self._morph()
+
+
+ def Dir(self, name):
+ """Create a directory node named 'name' relative to
+ the SConscript directory of this file."""
+ return self.fs.Dir(name, self.cwd)
+
+ def File(self, name):
+ """Create a file node named 'name' relative to
+ the SConscript directory of this file."""
+ return self.fs.File(name, self.cwd)
+
+ def RDirs(self, pathlist):
+ """Search for a list of directories in the Repository list."""
+ def path_dirs(rep, path, Dir=self.Dir):
+ if rep:
+ path = os.path.join(rep, path)
+ return Dir(path)
+
+ return self.fs.Rsearchall(pathlist, path_dirs)
+
+ def generate_build_env(self):
+ env = SCons.Node.Node.generate_build_env(self)
+
+ return env.Override({'Dir' : self.Dir,
+ 'File' : self.File,
+ 'RDirs' : self.RDirs})
def _morph(self):
"""Turn a file system node into a File object."""
diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py
index 1d8b0eb..51d4a6f 100644
--- a/src/engine/SCons/Node/FSTests.py
+++ b/src/engine/SCons/Node/FSTests.py
@@ -214,6 +214,41 @@ class FSTestCase(unittest.TestCase):
assert f1.path == d1_f1, "f1.path %s != %s" % (f1.path, d1_f1)
assert str(f1) == d1_f1, "str(f1) %s != %s" % (str(f1), d1_f1)
+ x1 = d1.File('x1')
+ assert str(x1) == os.path.join('d1', 'x1')
+
+ x2 = d1.Dir('x2')
+ assert str(x2) == os.path.join('d1', 'x2')
+
+ assert d1.File(x1) == x1
+ assert d1.Dir(x2) == x2
+
+ x1.cwd = d1
+
+ x3 = x1.File('x3')
+ assert str(x3) == os.path.join('d1', 'x3')
+
+ x4 = x1.Dir('x4')
+ assert str(x4) == os.path.join('d1', 'x4')
+
+ assert x1.File(x3) == x3
+ assert x1.Dir(x4) == x4
+
+ try:
+ x1.File(x4)
+ except TypeError:
+ pass
+ else:
+ assert 0
+
+ try:
+ x1.Dir(x3)
+ except TypeError:
+ pass
+ else:
+ assert 0
+
+
seps = [os.sep]
if os.sep != '/':
seps = seps + ['/']
diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py
index 8897b00..8ae7165 100644
--- a/src/engine/SCons/Node/NodeTests.py
+++ b/src/engine/SCons/Node/NodeTests.py
@@ -80,8 +80,6 @@ class ExceptBuilder2:
class Environment:
def Dictionary(self, *args):
return {}
- def autogenerate(self, **kw):
- return {}
def Override(selv, overrides):
return overrides
diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py
index b2bd8ed..c67ed92 100644
--- a/src/engine/SCons/Node/__init__.py
+++ b/src/engine/SCons/Node/__init__.py
@@ -93,15 +93,7 @@ class Node:
self.side_effects = [] # the side effects of building this target
def generate_build_env(self):
- if hasattr(self, 'cwd'):
- auto = self.env.autogenerate(dir = self.cwd)
- else:
- auto = self.env.autogenerate()
-
- dict = {}
- dict.update(auto)
- dict.update(self.overrides)
- return self.env.Override(dict)
+ return self.env.Override(self.overrides)
def build(self):
"""Actually build the node. Return the status from the build."""
diff --git a/src/engine/SCons/Tool/mslink.py b/src/engine/SCons/Tool/mslink.py
index 3fdd4d8..391cbfe 100644
--- a/src/engine/SCons/Tool/mslink.py
+++ b/src/engine/SCons/Tool/mslink.py
@@ -71,7 +71,7 @@ def win32LinkGenerator(env, target, source, for_signature):
'$(', '$_LIBDIRFLAGS', '$)', '$_LIBFLAGS' ]
if env.has_key('PDB') and env['PDB']:
- args.extend(['/PDB:%s'%env['PDB'], '/DEBUG'])
+ args.extend(['/PDB:%s'%target[0].File(env['PDB']), '/DEBUG'])
args.extend(map(SCons.Util.to_String, source))
return win32TempFileMunge(env, args, for_signature)
@@ -81,7 +81,7 @@ def win32LibGenerator(target, source, env, for_signature):
no_import_lib = env.get('no_import_lib', 0)
if env.has_key('PDB') and env['PDB']:
- listCmd.extend(['/PDB:%s'%env['PDB'], '/DEBUG'])
+ listCmd.extend(['/PDB:%s'%target[0].File(env['PDB']), '/DEBUG'])
for tgt in target:
ext = os.path.splitext(str(tgt))[1]
diff --git a/src/engine/SCons/Tool/msvc.py b/src/engine/SCons/Tool/msvc.py
index 1ba9ede..f71c074 100644
--- a/src/engine/SCons/Tool/msvc.py
+++ b/src/engine/SCons/Tool/msvc.py
@@ -191,13 +191,7 @@ def get_msdev_paths(version=None):
def validate_vars(env):
"""Validate the PDB, PCH, and PCHSTOP construction variables."""
- if env.has_key('PDB') and env['PDB']:
- if not isinstance(env['PDB'], SCons.Node.FS.File):
- raise SCons.Errors.UserError, "The PDB construction variable must be a File instance: %s"%env['PDB']
-
if env.has_key('PCH') and env['PCH']:
- if not isinstance(env['PCH'], SCons.Node.FS.File):
- raise SCons.Errors.UserError, "The PCH construction variable must be a File instance: %s"%env['PCH']
if not env.has_key('PCHSTOP'):
raise SCons.Errors.UserError, "The PCHSTOP construction must be defined if PCH is defined."
if not SCons.Util.is_String(env['PCHSTOP']):
@@ -257,8 +251,8 @@ def generate(env, platform):
static_obj.add_action(suffix, SCons.Defaults.CXXAction)
shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
- env['CCPDBFLAGS'] = '${(PDB and "/Zi /Fd%s"%PDB) or ""}'
- env['CCPCHFLAGS'] = '${(PCH and "/Yu%s /Fp%s"%(PCHSTOP or "",PCH)) or ""}'
+ env['CCPDBFLAGS'] = '${(PDB and "/Zi /Fd%s"%File(PDB)) or ""}'
+ env['CCPCHFLAGS'] = '${(PCH and "/Yu%s /Fp%s"%(PCHSTOP or "",File(PCH))) or ""}'
env['CCCOMFLAGS'] = '$CPPFLAGS $_CPPINCFLAGS /c $SOURCES /Fo$TARGET $CCPCHFLAGS $CCPDBFLAGS'
env['CC'] = 'cl'
env['CCFLAGS'] = '/nologo'
diff --git a/test/Environment.py b/test/Environment.py
new file mode 100644
index 0000000..ea42e5d
--- /dev/null
+++ b/test/Environment.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2001, 2002 Steven Knight
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import TestSCons
+import sys
+
+python = sys.executable
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+env=Environment(BAR='#bar.in', BLAT='subdir/../blat blat')
+target = env.Command('foo.out', 'foo.in', r'%s build.py $SOURCE $TARGET ${File(BAR)} ${Dir(BLAT)}')
+
+assert target == Dir('.').File('foo.out')
+assert Dir('.') == Dir('.').Dir('.')
+assert target == target.File('foo.out')
+"""%python)
+
+test.write('build.py', """
+import sys
+assert sys.argv[1] == 'foo.in', sys.argv[1]
+assert sys.argv[2] == 'foo.out', sys.argv[2]
+assert sys.argv[3] == 'bar.in', sys.argv[3]
+assert sys.argv[4] == 'blat blat', sys.argv[4]
+""")
+
+test.run(arguments='foo.out')
+
+test.pass_test()
diff --git a/test/LIBS.py b/test/LIBS.py
index 0933d6f..b9fb275 100644
--- a/test/LIBS.py
+++ b/test/LIBS.py
@@ -102,8 +102,8 @@ test.run(program=foo_exe, stdout='sub1/bar.c\nsub1/baz.c\n')
#
test.write('SConstruct', """
-env = Environment(LIBS='baz bar', LIBPATH = '.')
-env.Program(target='foo', source='foo.c')
+env = Environment()
+env.Program(target='foo', source='foo.c', LIBS=['baz', 'bar'], LIBPATH = '.')
SConscript('sub1/SConscript', 'env')
SConscript('sub2/SConscript', 'env')
""")
@@ -125,3 +125,6 @@ test.run(arguments = '.')
test.run(program=foo_exe, stdout='sub1/bar.c\nsub1/baz.c\n')
test.pass_test()
+
+
+
diff --git a/test/msvc.py b/test/msvc.py
index 0e3c3c2..ed43421 100644
--- a/test/msvc.py
+++ b/test/msvc.py
@@ -126,8 +126,9 @@ SConscript('build/SConscript')
test.write('src/SConscript',"""
env=Environment()
-env['PCH'] = env.PCH('StdAfx.cpp')[0]
-env['PDB'] = File('#out/test.pdb')
+env.PCH('StdAfx.cpp')
+env['PCH'] = 'StdAfx.pch'
+env['PDB'] = '#out/test.pdb'
env['PCHSTOP'] = 'StdAfx.h'
env.Program('#out/test.exe', 'test.cpp')
""")
@@ -166,32 +167,6 @@ test.fail_test(os.path.exists(test.workpath('build/StdAfx.obj')))
test.write('SConstruct',"""
env=Environment()
-env['PCH'] = env.PCH('StdAfx.cpp')
-env['PDB'] = File('test.pdb')
-env['PCHSTOP'] = 'StdAfx.h'
-env.Program('test', 'test.cpp')
-""")
-
-test.run(status=2, stderr=r'''
-SCons error: The PCH construction variable must be a File instance: .+
-File "SConstruct", line 6, in \?
-''')
-
-test.write('SConstruct',"""
-env=Environment()
-env['PCH'] = env.PCH('StdAfx.cpp')[0]
-env['PDB'] = 'test.pdb'
-env['PCHSTOP'] = 'StdAfx.h'
-env.Program('test', 'test.cpp')
-""")
-
-test.run(status=2, stderr='''
-SCons error: The PDB construction variable must be a File instance: test.pdb
-File "SConstruct", line 6, in \?
-''')
-
-test.write('SConstruct',"""
-env=Environment()
env['PCH'] = env.PCH('StdAfx.cpp')[0]
env['PDB'] = File('test.pdb')
env.Program('test', 'test.cpp')