summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/SCons/Util.py28
-rw-r--r--src/engine/SCons/UtilTests.py28
2 files changed, 48 insertions, 8 deletions
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py
index afcaf11..984bb02 100644
--- a/src/engine/SCons/Util.py
+++ b/src/engine/SCons/Util.py
@@ -606,10 +606,16 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, dict=No
r.append(self.conv(self.substitute(l, lvars)))
return string.join(r)
elif callable(s):
- s = s(target=self.target,
- source=self.source,
- env=self.env,
- for_signature=(self.mode != SUBST_CMD))
+ try:
+ s = s(target=self.target,
+ source=self.source,
+ env=self.env,
+ for_signature=(self.mode != SUBST_CMD))
+ except TypeError:
+ # This probably indicates that it's a callable
+ # object that doesn't match our calling arguments
+ # (like an Action).
+ s = str(s)
return self.substitute(s, lvars)
elif s is None:
return ''
@@ -753,10 +759,16 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, di
self.substitute(a, lvars, 1)
self.next_word()
elif callable(s):
- s = s(target=self.target,
- source=self.source,
- env=self.env,
- for_signature=(self.mode != SUBST_CMD))
+ try:
+ s = s(target=self.target,
+ source=self.source,
+ env=self.env,
+ for_signature=(self.mode != SUBST_CMD))
+ except TypeError:
+ # This probably indicates that it's a callable
+ # object that doesn't match our calling arguments
+ # (like an Action).
+ s = str(s)
self.substitute(s, lvars, within_list)
elif s is None:
self.this_word()
diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py
index 054d0b2..5ac6ec0 100644
--- a/src/engine/SCons/UtilTests.py
+++ b/src/engine/SCons/UtilTests.py
@@ -130,6 +130,14 @@ class UtilTestCase(unittest.TestCase):
def is_literal(self):
return 1
+ class TestCallable:
+ def __init__(self, value):
+ self.value = value
+ def __call__(self):
+ pass
+ def __str__(self):
+ return self.value
+
def function_foo(arg):
pass
@@ -194,6 +202,9 @@ class UtilTestCase(unittest.TestCase):
'RECURSE' : 'foo $RECURSE bar',
'RRR' : 'foo $SSS bar',
'SSS' : '$RRR',
+
+ # Test callables that don't match the calling arguments.
+ 'CALLABLE' : TestCallable('callable-1'),
}
env = DummyEnv(loc)
@@ -307,6 +318,9 @@ class UtilTestCase(unittest.TestCase):
# Bug reported by Christoph Wiedemann.
cvt('$xxx/bin'), '/bin',
+
+ # Tests callables that don't match our calling arguments.
+ '$CALLABLE', 'callable-1',
]
kwargs = {'target' : target, 'source' : source}
@@ -474,6 +488,14 @@ class UtilTestCase(unittest.TestCase):
self.attribute.attr1 = 'attr$1-' + os.path.basename(name)
self.attribute.attr2 = 'attr$2-' + os.path.basename(name)
+ class TestCallable:
+ def __init__(self, value):
+ self.value = value
+ def __call__(self):
+ pass
+ def __str__(self):
+ return self.value
+
target = [ MyNode("./foo/bar.exe"),
MyNode("/bar/baz with spaces.obj"),
MyNode("../foo/baz.obj") ]
@@ -529,6 +551,9 @@ class UtilTestCase(unittest.TestCase):
'RECURSE' : 'foo $RECURSE bar',
'RRR' : 'foo $SSS bar',
'SSS' : '$RRR',
+
+ # Test callable objects that don't match our calling arguments.
+ 'CALLABLE' : TestCallable('callable-2'),
}
env = DummyEnv(loc)
@@ -660,6 +685,9 @@ class UtilTestCase(unittest.TestCase):
'<$AAA', [['<', 'a']],
'>$AAA', [['>', 'a']],
'|$AAA', [['|', 'a']],
+
+ # Test callables that don't match our calling arguments.
+ '$CALLABLE', [['callable-2']],
]
kwargs = {'target' : target, 'source' : source}