self.node_factory)
for t in tlist:
+ t.cwd = SCons.Node.FS.default_fs.cwd # XXX
t.builder_set(self)
t.env_set(env)
t.add_source(slist)
dict.update(kw['env'])
del kw['env']
+ try:
+ cwd = kw['dir']
+ except:
+ cwd = None
+ else:
+ del kw['dir']
+
if kw.has_key('target'):
t = kw['target']
del kw['target']
- if not type(t) is types.ListType:
+ if not type(t) is types.ListType and not isinstance(t, UserList):
t = [t]
+ try:
+ cwd = t[0].cwd
+ except AttributeError:
+ pass
dict['TARGETS'] = PathList(map(os.path.normpath, map(str, t)))
- if dict['TARGETS']:
+ if dict['TARGETS']:
dict['TARGET'] = dict['TARGETS'][0]
+
if kw.has_key('source'):
s = kw['source']
del kw['source']
dict.update(kw)
# Autogenerate necessary construction variables.
- autogenerate(dict)
+ autogenerate(dict, dir = cwd)
return dict
assert contents == "foo\177\036\000\177\037\000d\000\000Sbar", repr(contents)
b4 = SCons.Builder.Builder(action = "$_LIBFLAGS $_LIBDIRFLAGS $_INCFLAGS")
- contents = b4.get_contents(LIBS = ['foo', 'bar'],
- LIBLINKPREFIX = '-l',
- LIBLINKSUFFIX = '',
- LIBPATH = ['lib'],
- LIBDIRPREFIX = '-L',
- LIBDIRSUFFIX = '/',
- CPPPATH = ['c', 'p'],
- INCPREFIX = '-I',
- INCSUFFIX = '')
- assert contents == "-lfoo -lbar -Llib/ -Ic -Ip", contents
+ kw = {'LIBS' : ['l1', 'l2'],
+ 'LIBLINKPREFIX' : '-l',
+ 'LIBLINKSUFFIX' : '',
+ 'LIBPATH' : ['lib'],
+ 'LIBDIRPREFIX' : '-L',
+ 'LIBDIRSUFFIX' : '/',
+ 'CPPPATH' : ['c', 'p'],
+ 'INCPREFIX' : '-I',
+ 'INCSUFFIX' : ''}
+
+ contents = apply(b4.get_contents, (), kw)
+ assert contents == "-ll1 -ll2 -Llib/ -Ic -Ip", contents
+
+ # SCons.Node.FS has been imported by our import of
+ # SCons.Node.Builder. It's kind of bogus that we don't
+ # import this ourselves before using it this way, but it's
+ # maybe a little cleaner than tying these tests directly
+ # to the other module via a direct import.
+ kw['dir'] = SCons.Node.FS.default_fs.Dir('d')
+ contents = apply(b4.get_contents, (), kw)
+ assert contents == "-ld/l1 -ld/l2 -Ld/lib/ -Id/c -Id/p", contents
def test_name(self):
"""Test Builder creation with a specified name
built_target = kw['target']
built_source = kw['source']
return 0
- def get_contents(self, env):
+ def get_contents(self, env, dir):
return 7
class FailBuilder:
self.node = node
def get_contents(self):
env = self.node.env.Dictionary()
- return self.node.builder.get_contents(env = env)
+ try:
+ dir = self.node.cwd
+ except AttributeError:
+ dir = None
+ return self.node.builder.get_contents(env = env, dir = dir)
return Adapter(self)
def scanner_set(self, scanner):
-# See the documentation for the __autogenerate() method
-# for an explanation of this variable...
AUTO_GEN_VARS = ( ( '_LIBFLAGS',
'LIBS',
'LIBLINKPREFIX',
'INCPREFIX',
'INCSUFFIX' ) )
-def autogenerate(dict):
+def autogenerate(dict, fs = SCons.Node.FS.default_fs, dir = None):
"""Autogenerate the "interpolated" environment variables.
We read a static structure that tells us how. AUTO_GEN_VARS
is a tuple of tuples. Each inner tuple has four elements,
concatenated."""
for strVarAuto, strSrc, strPref, strSuff, in AUTO_GEN_VARS:
- if dict.has_key(strSrc):
- src_var = dict[strSrc]
- if type(src_var) is types.ListType or \
- isinstance(src_var, UserList):
- src_var = map(str, src_var)
- else:
- src_var = [ str(src_var), ]
- else:
- src_var = []
+ if not dict.has_key(strSrc):
+ dict[strVarAuto] = ''
+ continue
+
+ src = dict[strSrc]
+ if not type(src) is types.ListType and not isinstance(src, UserList):
+ src = [ src ]
+ src = map(lambda x, fs=fs, d=dir: \
+ fs.Dir(str(x), directory = d).path,
+ src)
try:
prefix = str(dict[strPref])
dict[strVarAuto] = map(lambda x, suff=suffix, pref=prefix: \
pref + os.path.normpath(str(x)) + suff,
- src_var)
+ src)
dict = {'CPPPATH' : [ 'foo', 'bar', 'baz' ],
'INCPREFIX' : 'foo',
'INCSUFFIX' : 'bar'}
- autogenerate(dict)
+ autogenerate(dict, dir = SCons.Node.FS.default_fs.Dir('/xx'))
assert len(dict['_INCFLAGS']) == 3, dict('_INCFLAGS')
- assert dict['_INCFLAGS'][0] == 'foofoobar', \
+ assert dict['_INCFLAGS'][0] == 'foo/xx/foobar', \
dict['_INCFLAGS'][0]
- assert dict['_INCFLAGS'][1] == 'foobarbar', \
+ assert dict['_INCFLAGS'][1] == 'foo/xx/barbar', \
dict['_INCFLAGS'][1]
- assert dict['_INCFLAGS'][2] == 'foobazbar', \
+ assert dict['_INCFLAGS'][2] == 'foo/xx/bazbar', \
dict['_INCFLAGS'][2]
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import os
import sys
import TestSCons
_exe = ''
prog = 'prog' + _exe
+subdir_prog = os.path.join('subdir', 'prog' + _exe)
+
+args = prog + ' ' + subdir_prog
test = TestSCons.TestSCons()
-test.write('foo.c',
-"""#include "foo.h"
+test.subdir('include', 'subdir', ['subdir', 'include'])
+
+test.write('SConstruct', """
+env = Environment(CPPPATH = ['include'])
+obj = env.Object(target='prog', source='subdir/prog.c')
+env.Program(target='prog', source=obj)
+SConscript('subdir/SConscript')
+""")
+
+test.write(['subdir', 'SConscript'], """
+env.Program(target='prog', source='prog.c')
+""")
+
+test.write('include/foo.h',
+r"""
+#define FOO_STRING "include/foo.h 1\n"
+#include <bar.h>
+""")
+
+test.write('include/bar.h',
+r"""
+#define BAR_STRING "include/bar.h 1\n"
+""")
+
+test.write('subdir/prog.c',
+r"""#include <foo.h>
#include <stdio.h>
-int main(void)
+int
+main(int argc, char *argv[])
{
+ argv[argc++] = "--";
+ printf("subdir/prog.c\n");
printf(FOO_STRING);
printf(BAR_STRING);
return 0;
}
""")
-test.subdir('include')
-
-test.write('include/foo.h',
+test.write('subdir/include/foo.h',
r"""
-#define FOO_STRING "foo.h 1\n"
+#define FOO_STRING "subdir/include/foo.h 1\n"
#include "bar.h"
""")
-test.write('include/bar.h',
+test.write('subdir/include/bar.h',
r"""
-#define BAR_STRING "bar.h 1\n"
+#define BAR_STRING "subdir/include/bar.h 1\n"
""")
-test.write('SConstruct', """
-env = Environment(CPPPATH = ['include'])
-env.Program(target='prog', source='foo.c')
-""")
-test.run(arguments = prog)
+
+test.run(arguments = args, stderr = None)
test.run(program = test.workpath(prog),
- stdout = "foo.h 1\nbar.h 1\n")
+ stdout = "subdir/prog.c\ninclude/foo.h 1\ninclude/bar.h 1\n")
+
+test.run(program = test.workpath(subdir_prog),
+ stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
+
+test.up_to_date(arguments = args)
+
-test.up_to_date(arguments = prog)
test.unlink('include/foo.h')
test.write('include/foo.h',
r"""
-#define FOO_STRING "foo.h 2\n"
+#define FOO_STRING "include/foo.h 2\n"
#include "bar.h"
""")
-test.run(arguments = prog)
+test.run(arguments = args)
test.run(program = test.workpath(prog),
- stdout = "foo.h 2\nbar.h 1\n")
+ stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
+
+test.run(program = test.workpath(subdir_prog),
+ stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
+
+test.up_to_date(arguments = args)
+
-test.up_to_date(arguments = prog)
test.unlink('include/bar.h')
test.write('include/bar.h',
r"""
-#define BAR_STRING "bar.h 2\n"
+#define BAR_STRING "include/bar.h 2\n"
""")
test.run(arguments = prog)
test.run(program = test.workpath(prog),
- stdout = "foo.h 2\nbar.h 2\n")
+ stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 2\n")
+
+test.run(program = test.workpath(subdir_prog),
+ stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
test.up_to_date(arguments = prog)