Use a Node's environment in preference to the builder's environment.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 10 Nov 2004 00:39:51 +0000 (00:39 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 10 Nov 2004 00:39:51 +0000 (00:39 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1151 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Node/NodeTests.py
src/engine/SCons/Node/__init__.py
test/pre-post-actions.py

index 508b70eaa62efd064f44cf08dbc70b409a1c7104..e7d3061cb8d948277e16ebde9f60db1ec01a4b62 100644 (file)
@@ -288,6 +288,47 @@ class NodeTestCase(unittest.TestCase):
             assert str(act.built_target[0]) == "xxx", str(act.built_target[0])
             assert act.built_source == ["yyy", "zzz"], act.built_source
 
+    def test_get_executor(self):
+        """Test the reset_executor() method"""
+        n = SCons.Node.Node()
+
+        try:
+            n.get_executor(0)
+        except AttributeError:
+            pass
+        else:
+            self.fail("did not catch expected AttributeError")
+
+        class Builder:
+            action = 'act'
+            env = 'env1'
+            overrides = {}
+
+        n = SCons.Node.Node()
+        n.builder_set(Builder())
+        x = n.get_executor()
+        assert x.env == 'env1', x.env
+
+        n = SCons.Node.Node()
+        n.builder_set(Builder())
+        n.env_set('env2')
+        x = n.get_executor()
+        assert x.env == 'env2', x.env
+
+    def test_set_executor(self):
+        """Test the reset_executor() method"""
+        n = SCons.Node.Node()
+        n.set_executor(1)
+        assert n.executor == 1, n.executor
+
+    def test_reset_executor(self):
+        """Test the reset_executor() method"""
+        n = SCons.Node.Node()
+        n.set_executor(1)
+        assert n.executor == 1, n.executor
+        n.reset_executor()
+        assert not hasattr(n, 'executor'), "unexpected executor attribute"
+
     def test_built(self):
         """Test the built() method"""
         class SubNode(SCons.Node.Node):
index 31f8b5839936f2d1be9b9094583846f1ccc05abe..ef0a096651024dc17e33323efb1f217b05fda12d 100644 (file)
@@ -173,7 +173,7 @@ class Node:
             if self.post_actions:
                 act = act + self.post_actions
             executor = SCons.Executor.Executor(act,
-                                               self.builder.env,
+                                               self.env or self.builder.env,
                                                [self.builder.overrides],
                                                [self],
                                                self.sources)
index 1e69a21c44acd3bbff145f3a4fb0c6aba55939f6..db5d5befcaa7c4386a7e724ba59b3cdb573b3aa6 100644 (file)
@@ -36,36 +36,44 @@ _exe = TestSCons._exe
 
 test = TestSCons.TestSCons()
 
-test.write('SConstruct', """
+test.subdir('work1', 'work2')
+
+
+
+test.write(['work1', 'SConstruct'], """
 import os.path
+import stat
 
-env = Environment(XXX='bar%s')
+env = Environment(XXX='bar%(_exe)s')
 
 def before(env, target, source):
     f=open(str(target[0]), "wb")
     f.write("Foo\\n")
     f.close()
     f=open("before.txt", "ab")
-    f.write(str(target[0]) + "\\n")
+    f.write(os.path.splitext(str(target[0]))[0] + "\\n")
     f.close()
 
 def after(env, target, source):
-    fin = open(str(target[0]), "rb")
-    fout = open("after_" + str(target[0]), "wb")
+    t = str(target[0])
+    a = "after_" + os.path.splitext(t)[0]
+    fin = open(t, "rb")
+    fout = open(a, "wb")
     fout.write(fin.read())
     fout.close()
     fin.close()
+    os.chmod(a, os.stat(a)[stat.ST_MODE] | stat.S_IXUSR)
 
 foo = env.Program(source='foo.c', target='foo')
 AddPreAction(foo, before)
-AddPostAction('foo%s', after)
+AddPostAction('foo%(_exe)s', after)
 
 bar = env.Program(source='bar.c', target='bar')
 env.AddPreAction('$XXX', before)
 env.AddPostAction('$XXX', after)
-""" % (_exe, _exe))
+""" % locals())
 
-test.write('foo.c', r"""
+test.write(['work1', 'foo.c'], r"""
 #include <stdio.h>
 
 int main(void)
@@ -75,7 +83,7 @@ int main(void)
 }
 """)
 
-test.write('bar.c', r"""
+test.write(['work1', 'bar.c'], r"""
 #include <stdio.h>
 
 int main(void)
@@ -85,20 +93,57 @@ int main(void)
 }
 """)
 
+test.run(chdir='work1', arguments='.')
+
+test.run(program=test.workpath('work1', 'foo'+ _exe), stdout="foo.c\n")
+test.run(program=test.workpath('work1', 'bar'+ _exe), stdout="bar.c\n")
+
+test.must_match(['work1', 'before.txt'], "bar\nfoo\n")
+
+after_foo_exe = test.workpath('work1', 'after_foo' + _exe)
+test.run(program=after_foo_exe, stdout="foo.c\n")
+
+after_bar_exe = test.workpath('work1', 'after_bar' + _exe)
+test.run(program=after_bar_exe, stdout="bar.c\n")
+
+
+
+
+test.write(['work2', 'SConstruct'], """\
+def b(target, source, env):
+    open(str(target[0]), 'w').write(env['X'] + '\\n')
+env1 = Environment(X='111')
+env2 = Environment(X='222')
+B = Builder(action = b, env = env1, multi=1)
+print "B =", B
+print "B.env =", B.env
+env1.Append(BUILDERS = {'B' : B})
+env2.Append(BUILDERS = {'B' : B})
+env3 = env1.Copy(X='333')
+print "env1 =", env1
+print "env2 =", env2
+print "env3 =", env3
+f1 = env1.B(File('file1.out'), [])
+f2 = env2.B('file2.out', [])
+f3 = env3.B('file3.out', [])
+def do_nothing(env, target, source):
+    pass
+AddPreAction(f2[0], do_nothing)
+AddPostAction(f3[0], do_nothing)
+print "f1[0].builder =", f1[0].builder
+print "f2[0].builder =", f2[0].builder
+print "f3[0].builder =", f3[0].builder
+print "f1[0].env =", f1[0].env
+print "f2[0].env =", f2[0].env
+print "f3[0].env =", f3[0].env
+""")
 
-test.run(arguments='.')
-
-test.run(program=test.workpath('foo'+ _exe), stdout="foo.c\n")
-test.run(program=test.workpath('bar'+ _exe), stdout="bar.c\n")
+test.run(chdir='work2', arguments = '.')
 
-test.fail_test(test.read('before.txt', 'rb') != "bar%s\nfoo%s\n" % (_exe, _exe))
+test.must_match(['work2', 'file1.out'], "111\n")
+test.must_match(['work2', 'file2.out'], "222\n")
+test.must_match(['work2', 'file3.out'], "333\n")
 
-after_foo_exe = test.workpath('after_foo' + _exe)
-os.chmod(after_foo_exe, os.stat(after_foo_exe)[stat.ST_MODE] | stat.S_IXUSR)
-test.run(program=test.workpath(after_foo_exe), stdout="foo.c\n")
 
-after_bar_exe = test.workpath('after_bar' + _exe)
-os.chmod(after_bar_exe, os.stat(after_bar_exe)[stat.ST_MODE] | stat.S_IXUSR)
-test.run(program=test.workpath(after_bar_exe), stdout="bar.c\n")
 
 test.pass_test()