f = f + suf
ret.append(f)
return ret
-
tlist = scons_str2nodes(adjustixes(target, self.prefix, self.suffix),
self.node_factory)
s = [s]
loc['sources'] = PathList(map(os.path.normpath, s))
- try:
- glob = self.env.Dictionary()
- except:
- glob = {}
+ glob = {}
+ if kw.has_key('env'):
+ glob = kw['env']
cmd = scons_subst(self.command, loc, glob)
if print_actions:
# Child process.
args = string.split(cmd)
try:
- ENV = kw['ENV']
+ ENV = kw['env']['ENV']
except:
import SCons.Defaults
- ENV = SCons.Defaults.ENV
+ ENV = SCons.Defaults.ConstructionEnvironment['ENV']
os.execvpe(args[0], args, ENV)
else:
# Parent process.
test.write('act.py', """import os, string, sys
f = open(sys.argv[1], 'w')
f.write("act.py: " + string.join(sys.argv[2:]) + "\\n")
+try:
+ if sys.argv[3]:
+ f.write("act.py: " + os.environ[sys.argv[3]] + "\\n")
+except:
+ pass
f.close()
sys.exit(0)
""")
c = test.read(outfile, 'r')
assert c == "act.py: three four\n", c
+ cmd5 = "python %s %s $target XYZZY" % (act_py, outfile)
+
+ builder = SCons.Builder.Builder(action = cmd5)
+ r = builder.execute(target = 'out5', env = {'ENV' : {'XYZZY' : 'xyzzy'}})
+ assert r == 0
+ c = test.read(outfile, 'r')
+ assert c == "act.py: out5 XYZZY\nact.py: xyzzy\n", c
+
def function1(kw):
open(kw['out'], 'w').write("function1\n")
return 1
Object = SCons.Builder.Builder(name = 'Object',
- action = 'cc -c -o $target $sources',
+ action = '$CC $CCFLAGS -c -o $target $sources',
src_suffix='.c',
suffix='.o')
Program = SCons.Builder.Builder(name = 'Program',
- action = 'cc -o $target $sources',
+ action = '$CC -o $target $sources',
builders = [ Object ])
Library = SCons.Builder.Builder(name = 'Library',
suffix = '.a',
builders = [ Object ])
-Builders = [Object, Program, Library]
-
-ENV = { 'PATH' : '/usr/local/bin:/bin:/usr/bin' }
+ConstructionEnvironment = {
+ 'CC' : 'cc',
+ 'CCFLAGS' : '',
+ 'BUILDERS' : [Object, Program, Library],
+ 'ENV' : { 'PATH' : '/usr/local/bin:/bin:/usr/bin' },
+}
"""
def __init__(self, **kw):
- self._dict = {}
- if kw.has_key('BUILDERS'):
- builders = kw['BUILDERS']
- if not type(builders) is types.ListType:
- kw['BUILDERS'] = [builders]
- else:
- import SCons.Defaults
- kw['BUILDERS'] = SCons.Defaults.Builders[:]
- if not kw.has_key('ENV'):
- import SCons.Defaults
- kw['ENV'] = SCons.Defaults.ENV.copy()
+ import SCons.Defaults
+ self._dict = copy.deepcopy(SCons.Defaults.ConstructionEnvironment)
+ if kw.has_key('BUILDERS') and type(kw['BUILDERS']) != type([]):
+ kw['BUILDERS'] = [kw['BUILDERS']]
self._dict.update(copy.deepcopy(kw))
class BuilderWrapper:
kw['env'] = self
apply(self.builder.execute, (), kw)
- for b in kw['BUILDERS']:
+ for b in self._dict['BUILDERS']:
setattr(self, b.name, BuilderWrapper(self, b))
assert xxx == 'x'
assert zzz == 'z'
assert env.Dictionary().has_key('BUILDERS')
+ assert env.Dictionary().has_key('CC')
+ assert env.Dictionary().has_key('CCFLAGS')
assert env.Dictionary().has_key('ENV')
def test_ENV(self):
assert node.depends == ['one']
node.add_dependency(['two', 'three'])
assert node.depends == ['one', 'two', 'three']
+ node.add_dependency(['three', 'four', 'one'])
+ assert node.depends == ['one', 'two', 'three', 'four']
def test_add_source(self):
"""Test adding sources to a Node's list.
assert node.sources == ['one']
node.add_source(['two', 'three'])
assert node.sources == ['one', 'two', 'three']
+ node.add_source(['three', 'four', 'one'])
+ assert node.sources == ['one', 'two', 'three', 'four']
def test_children(self):
"""Test fetching the "children" of a Node.
if not hasattr(self, "builder"):
return None
sources_str = string.join(map(lambda x: str(x), self.sources))
- stat = self.builder.execute(ENV = self.env.Dictionary('ENV'),
+ stat = self.builder.execute(env = self.env.Dictionary(),
target = str(self), source = sources_str)
if stat != 0:
raise BuildError(node = self, stat = stat)
"""Adds dependencies. The depends argument must be a list."""
if type(depend) is not type([]):
raise TypeError("depend must be a list")
- self.depends.extend(depend)
+ depend = filter(lambda x, d=self.depends: x not in d, depend)
+ if len(depend):
+ self.depends.extend(depend)
def add_source(self, source):
"""Adds sources. The source argument must be a list."""
if type(source) is not type([]):
raise TypeError("source must be a list")
- self.sources.extend(source)
+ source = filter(lambda x, s=self.sources: x not in s, source)
+ if len(source):
+ self.sources.extend(source)
def children(self):
return self.sources + self.depends
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import os
import TestSCons
test = TestSCons.TestSCons()
-test.pass_test() #XXX Short-circuit until this is implemented.
+test.write("ccwrapper.py",
+"""import os
+import string
+import sys
+open('%s', 'w').write("ccwrapper.py\\n")
+os.system(string.join(["cc"] + sys.argv[1:], " "))
+""" % test.workpath('ccwrapper.out'))
test.write('SConstruct', """
+foo = Environment()
+bar = Environment(CC = 'python ccwrapper.py')
+foo.Program(target = 'foo', source = 'foo.c')
+bar.Program(target = 'bar', source = 'bar.c')
""")
-test.run(arguments = '.')
+test.write('foo.c', """
+int
+main(int argc, char *argv[])
+{
+ argv[argc++] = "--";
+ printf("foo.c\n");
+ exit (0);
+}
+""")
+
+test.write('bar.c', """
+int
+main(int argc, char *argv[])
+{
+ argv[argc++] = "--";
+ printf("foo.c\n");
+ exit (0);
+}
+""")
+
+
+test.run(arguments = 'foo')
+
+test.fail_test(os.path.exists(test.workpath('ccwrapper.out')))
+
+test.run(arguments = 'bar')
+
+test.fail_test(test.read('ccwrapper.out') != "ccwrapper.py\n")
test.pass_test()
test = TestSCons.TestSCons()
-test.pass_test() #XXX Short-circuit until this is implemented.
-
test.write('SConstruct', """
foo = Environment(CCFLAGS = '-DFOO')
bar = Environment(CCFLAGS = '-DBAR')
-foo.Program(target = 'progfoo', source = 'prog.c')
-bar.Program(target = 'progbar', source = 'prog.c')
+foo.Object(target = 'foo.o', source = 'prog.c')
+bar.Object(target = 'bar.o', source = 'prog.c')
+foo.Program(target = 'foo', source = 'foo.o')
+bar.Program(target = 'bar', source = 'bar.o')
""")
test.write('prog.c', """
""")
-test.run(arguments = 'progfoo progbar')
+test.run(arguments = 'foo bar')
-test.run(program = test.workpath('progfoo'), stdout = "prog.c: FOO\n")
-test.run(program = test.workpath('progbar'), stdout = "prog.c: BAR\n")
+test.run(program = test.workpath('foo'), stdout = "prog.c: FOO\n")
+test.run(program = test.workpath('bar'), stdout = "prog.c: BAR\n")
test.pass_test()