Fix Value node expansion in command-line strings. (Kevin Quick)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 21 Nov 2004 16:18:50 +0000 (16:18 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 21 Nov 2004 16:18:50 +0000 (16:18 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1172 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py
test/Value.py

index 2159249a7ad7757319f03e2f0f56879bdd703fb6..326f9cf2ee8873d5bd54f5072ded077415abb7d1 100644 (file)
@@ -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.
index ec809b9ffb0944c343230d6e38cc84934d6f2262..896abaf26176275b916cd3010624ca0af1d3ab93 100644 (file)
@@ -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)
 
index 18fd3c2b888eef397998b6ca051c51402fd47aeb..c5c5297d99ab1053ee85b06bb6eed5c8bf8b64d6 100644 (file)
@@ -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"""
index e3106b80e7b91059553e185941c3c932ec87d739..46f82322d202738ea4e830afbd7d9af38b0cb19a 100644 (file)
@@ -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()