From 8781e4655cea19b34cd062768d9f09b359fe9a09 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Sun, 21 Nov 2004 16:18:50 +0000 Subject: Fix Value node expansion in command-line strings. (Kevin Quick) --- src/CHANGES.txt | 2 ++ src/engine/SCons/Util.py | 10 +++++++++- src/engine/SCons/UtilTests.py | 19 ++++++++++++------- test/Value.py | 17 +++++++++++++++-- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 2159249..326f9cf 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -304,6 +304,8 @@ RELEASE 0.97 - XXX - Add --debug=objects logging of creation of OverrideWarner, EnvironmentCopy and EnvironmentOverride objects. + - Fix command-line expansion of Python Value Nodes. + From Levi Stephen: - Allow $JARCHDIR to be expanded to other construction variables. diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index ec809b9..896abaf 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -493,7 +493,15 @@ def subst_dict(target, source): dict['TARGET'] = Target_or_Source(tnl) if source: - snl = NLWrapper(source, lambda x: x.rfile().get_subst_proxy()) + def get_src_subst_proxy(node): + try: + rfile = node.rfile + except AttributeError: + pass + else: + node = rfile() + return node.get_subst_proxy() + snl = NLWrapper(source, get_src_subst_proxy) dict['SOURCES'] = Targets_or_Sources(snl) dict['SOURCE'] = Target_or_Source(snl) diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index 18fd3c2..c5c5297 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -1364,27 +1364,32 @@ class UtilTestCase(unittest.TestCase): assert SOURCES == ['s1', 's2'], d['SOURCES'] assert str(d['SOURCE']) == 's1', d['SOURCE'] - class N: + class V: + # Fake Value node with no rfile() method. def __init__(self, name): self.name = name def __str__(self): - return self.name - def rfile(self): - return self.__class__('rstr-' + self.name) + return 'v-'+self.name def get_subst_proxy(self): return self + class N(V): + def rfile(self): + return self.__class__('rstr-' + self.name) + t3 = N('t3') t4 = DummyNode('t4') + t5 = V('t5') s3 = DummyNode('s3') s4 = N('s4') - d = subst_dict(target=[t3, t4], source=[s3, s4]) + s5 = V('s5') + d = subst_dict(target=[t3, t4, t5], source=[s3, s4, s5]) TARGETS = map(lambda x: str(x), d['TARGETS']) TARGETS.sort() - assert TARGETS == ['t3', 't4'], d['TARGETS'] + assert TARGETS == ['t4', 'v-t3', 'v-t5'], TARGETS SOURCES = map(lambda x: str(x), d['SOURCES']) SOURCES.sort() - assert SOURCES == ['rstr-s4', 's3'], d['SOURCES'] + assert SOURCES == ['s3', 'v-rstr-s4', 'v-s5'], SOURCES def test_PrependPath(self): """Test prepending to a path""" diff --git a/test/Value.py b/test/Value.py index e3106b8..46f8232 100644 --- a/test/Value.py +++ b/test/Value.py @@ -40,7 +40,7 @@ for source_signature in ['MD5', 'timestamp']: print "Testing Value node with source signatures:", source_signature test.write('SConstruct', """ -SourceSignatures(r'%s') +SourceSignatures(r'%(source_signature)s') class Custom: def __init__(self, value): self.value = value @@ -55,10 +55,20 @@ def create(target, source, env): env = Environment() env['BUILDERS']['B'] = Builder(action = create) +env['BUILDERS']['S'] = Builder(action = "%(python)s put $SOURCES into $TARGET") env.B('f1.out', Value(P)) env.B('f2.out', env.Value(L)) env.B('f3.out', Value(C)) -""" % source_signature) +env.S('f4.out', Value(L)) +""" % {'source_signature':source_signature, + 'python':TestSCons.python}) + + test.write('put', """ +import os +import string +import sys +open(sys.argv[-1],'wb').write(string.join(sys.argv[1:-2])) +""") test.run(arguments='-c') test.run() @@ -74,6 +84,7 @@ env.B('f3.out', Value(C)) test.must_match('f1.out', "/usr/local") test.must_match('f2.out', "10") test.must_match('f3.out', "C=/usr/local") + test.must_match('f4.out', '10') test.up_to_date(arguments='.') @@ -89,6 +100,7 @@ env.B('f3.out', Value(C)) test.must_match('f1.out', "/usr") test.must_match('f2.out', "4") test.must_match('f3.out', "C=/usr") + test.must_match('f4.out', '4') test.up_to_date('prefix=/usr', '.') @@ -106,5 +118,6 @@ env.B('f3.out', Value(C)) test.must_match('f1.out', "/var") test.must_match('f2.out', "4") test.must_match('f3.out', "C=/var") + test.must_match('f4.out', "4") test.pass_test() -- cgit v0.12