diff options
author | Steven Knight <knight@baldmt.com> | 2001-10-02 20:01:35 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2001-10-02 20:01:35 (GMT) |
commit | c38b764a8c7e91d48c79a4918fd55d5305a3fffc (patch) | |
tree | f9032a75fdaca058cad91c0823a7d6c9e06ce1be /src | |
parent | f987fbf31938ce3009b89f1f62f880cdc2a511f4 (diff) | |
download | SCons-c38b764a8c7e91d48c79a4918fd55d5305a3fffc.zip SCons-c38b764a8c7e91d48c79a4918fd55d5305a3fffc.tar.gz SCons-c38b764a8c7e91d48c79a4918fd55d5305a3fffc.tar.bz2 |
Add the Command() method.
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/SCons/Builder.py | 2 | ||||
-rw-r--r-- | src/engine/SCons/BuilderTests.py | 44 | ||||
-rw-r--r-- | src/engine/SCons/Environment.py | 10 | ||||
-rw-r--r-- | src/engine/SCons/EnvironmentTests.py | 17 | ||||
-rw-r--r-- | src/engine/SCons/Node/__init__.py | 2 |
5 files changed, 65 insertions, 10 deletions
diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index c90bc40..f4dbec4 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -70,7 +70,7 @@ def Action(act): l = string.split(act, "\n") if len(l) > 1: act = l - if type(act) == types.FunctionType: + if callable(act): return FunctionAction(act) elif type(act) == types.StringType: return CommandAction(act) diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 965df6e..d2e5768 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -80,16 +80,16 @@ class BuilderTestCase(unittest.TestCase): one is an internal Python function, one is a list containing one of each. """ + cmd1 = "python %s %s xyzzy" % (act_py, outfile) + builder = SCons.Builder.Builder(action = cmd1) r = builder.execute() assert r == 0 assert test.read(outfile, 'r') == "act.py: xyzzy\n" def function1(kw): - f = open(kw['out'], 'w') - f.write("function1\n") - f.close() + open(kw['out'], 'w').write("function1\n") return 1 builder = SCons.Builder.Builder(action = function1) @@ -97,14 +97,44 @@ class BuilderTestCase(unittest.TestCase): assert r == 1 assert test.read(outfile, 'r') == "function1\n" + class class1a: + def __init__(self, kw): + open(kw['out'], 'w').write("class1a\n") + + builder = SCons.Builder.Builder(action = class1a) + r = builder.execute(out = outfile) + assert r.__class__ == class1a + assert test.read(outfile, 'r') == "class1a\n" + + class class1b: + def __call__(self, kw): + open(kw['out'], 'w').write("class1b\n") + return 2 + + builder = SCons.Builder.Builder(action = class1b()) + r = builder.execute(out = outfile) + assert r == 2 + assert test.read(outfile, 'r') == "class1b\n" + cmd2 = "python %s %s syzygy" % (act_py, outfile) + def function2(kw): open(kw['out'], 'a').write("function2\n") - return 2 - builder = SCons.Builder.Builder(action = [cmd2, function2]) + return 0 + + class class2a: + def __call__(self, kw): + open(kw['out'], 'a').write("class2a\n") + return 0 + + class class2b: + def __init__(self, kw): + open(kw['out'], 'a').write("class2b\n") + + builder = SCons.Builder.Builder(action = [cmd2, function2, class2a(), class2b]) r = builder.execute(out = outfile) - assert r == 2 - assert test.read(outfile, 'r') == "act.py: syzygy\nfunction2\n" + assert r.__class__ == class2b + assert test.read(outfile, 'r') == "act.py: syzygy\nfunction2\nclass2a\nclass2b\n" def test_insuffix(self): """Test Builder creation with a specified input suffix diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index c7c32dd..e47a0a2 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -12,7 +12,7 @@ import copy import re import types import SCons.Util - +import SCons.Builder def Command(): @@ -139,6 +139,14 @@ class Environment: dlist = dlist[0] return dlist + def Command(self, target, source, action): + """Builds the supplied target files from the supplied + source files using the supplied action. Action may + be any type that the Builder constructor will accept + for an action.""" + bld = SCons.Builder.Builder(name="Command", action=action) + return bld(self, target, source) + def subst(self, string): """Recursively interpolates construction variables from the Environment into the specified string, returning the expanded diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index c503fe2..a60e558 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -145,6 +145,23 @@ class EnvironmentTestCase(unittest.TestCase): assert d.__class__.__name__ == 'File' assert d.path == 'Environment.py' + def test_Command(self): + """Test the Command() method.""" + env = Environment() + t = env.Command(target='foo.out', source=['foo1.in', 'foo2.in'], + action='buildfoo %(target)s %(source)s') + assert t.derived + assert t.builder.action.__class__.__name__ == 'CommandAction' + assert t.builder.action.command == 'buildfoo %(target)s %(source)s' + assert 'foo1.in' in map(lambda x: x.path, t.sources) + assert 'foo2.in' in map(lambda x: x.path, t.sources) + + def testFunc(ENV, target, source): + assert target == 'foo.out' + assert source == 'foo1.in foo2.in' or source == 'foo2.in foo1.in' + env.Command(target='foo.out', source=['foo1.in','foo2.in'], + action=testFunc) + def test_subst(self): """Test substituting construction variables within strings diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index 6026900..5b90eb7 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -10,7 +10,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" from SCons.Errors import BuildError import string - +import types class Node: |