From c758e5b84c91197de129134c2ab67f45f96dff52 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Tue, 7 Oct 2003 14:02:21 +0000 Subject: Allow Dirs to be sources of Depends, Ignores, Precious and SideEffect. (Gary Oberbrunner) --- src/CHANGES.txt | 7 ++- src/engine/SCons/Environment.py | 14 ++--- src/engine/SCons/EnvironmentTests.py | 108 ++++++++++++++++++++++++----------- test/Depends.py | 53 ++++++++++++++--- 4 files changed, 133 insertions(+), 49 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index fd9fca6..d228c81 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -123,6 +123,11 @@ RELEASE X.XX - XXX - Split the non-SCons-specific functionality from SConf.py to a new, re-usable Conftest.py module. + From Gary Oberbrunner: + + - Allow a directory to be the target or source or dependency of a + Depends(), Ignore(), Precious() or SideEffect() call. + From Marko Rauhamaa: - Have the closing message say "...terminated because of errors" if @@ -134,7 +139,7 @@ RELEASE X.XX - XXX used. ("rm" doesn't understand Win32-format path names.) From Christoph Wiedemann: - + - Fix test/SWIG.py to find the Python include directory in all cases. diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 40e039d..36be2e4 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -774,8 +774,8 @@ class Base: def Depends(self, target, dependency): """Explicity specify that 'target's depend on 'dependency'.""" - tlist = self.arg2nodes(target, self.fs.File) - dlist = self.arg2nodes(dependency, self.fs.File) + tlist = self.arg2nodes(target, self.fs.Entry) + dlist = self.arg2nodes(dependency, self.fs.Entry) for t in tlist: t.add_dependency(dlist) @@ -809,8 +809,8 @@ class Base: def Ignore(self, target, dependency): """Ignore a dependency.""" - tlist = self.arg2nodes(target, self.fs.File) - dlist = self.arg2nodes(dependency, self.fs.File) + tlist = self.arg2nodes(target, self.fs.Entry) + dlist = self.arg2nodes(dependency, self.fs.Entry) for t in tlist: t.add_ignore(dlist) @@ -869,7 +869,7 @@ class Base: def Precious(self, *targets): tlist = [] for t in targets: - tlist.extend(self.arg2nodes(t, self.fs.File)) + tlist.extend(self.arg2nodes(t, self.fs.Entry)) for t in tlist: t.set_precious() @@ -891,8 +891,8 @@ class Base: def SideEffect(self, side_effect, target): """Tell scons that side_effects are built as side effects of building targets.""" - side_effects = self.arg2nodes(side_effect, self.fs.File) - targets = self.arg2nodes(target, self.fs.File) + side_effects = self.arg2nodes(side_effect, self.fs.Entry) + targets = self.arg2nodes(target, self.fs.Entry) for side_effect in side_effects: # A builder of 1 means the node is supposed to appear diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index f46df73..360eb4c 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -1343,23 +1343,35 @@ class EnvironmentTestCase(unittest.TestCase): assert d == ['bbb', 'another_file'], d def test_Depends(self): - """Test the explicit Depends method.""" - env = Environment(FOO = 'xxx', BAR='yyy') - t = env.Depends(target='EnvironmentTest.py', dependency='Environment.py') - assert t.__class__.__name__ == 'File' - assert t.path == 'EnvironmentTest.py' - assert len(t.depends) == 1 - d = t.depends[0] - assert d.__class__.__name__ == 'File' - assert d.path == 'Environment.py' - - t = env.Depends(target='${FOO}.py', dependency='${BAR}.py') - assert t.__class__.__name__ == 'File' - assert t.path == 'xxx.py' - assert len(t.depends) == 1 - d = t.depends[0] - assert d.__class__.__name__ == 'File' - assert d.path == 'yyy.py' + """Test the explicit Depends method.""" + env = Environment(FOO = 'xxx', BAR='yyy') + env.Dir('dir1') + env.Dir('dir2') + env.File('xxx.py') + env.File('yyy.py') + t = env.Depends(target='EnvironmentTest.py', dependency='Environment.py') + assert t.__class__.__name__ == 'Entry', t.__class__.__name__ + assert t.path == 'EnvironmentTest.py' + assert len(t.depends) == 1 + d = t.depends[0] + assert d.__class__.__name__ == 'Entry', d.__class__.__name__ + assert d.path == 'Environment.py' + + t = env.Depends(target='${FOO}.py', dependency='${BAR}.py') + assert t.__class__.__name__ == 'File', t.__class__.__name__ + assert t.path == 'xxx.py' + assert len(t.depends) == 1 + d = t.depends[0] + assert d.__class__.__name__ == 'File', d.__class__.__name__ + assert d.path == 'yyy.py' + + t = env.Depends(target='dir1', dependency='dir2') + assert t.__class__.__name__ == 'Dir', t.__class__.__name__ + assert t.path == 'dir1' + assert len(t.depends) == 1 + d = t.depends[0] + assert d.__class__.__name__ == 'Dir', d.__class__.__name__ + assert d.path == 'dir2' def test_Dir(self): """Test the Dir() method""" @@ -1427,21 +1439,35 @@ class EnvironmentTestCase(unittest.TestCase): def test_Ignore(self): """Test the explicit Ignore method.""" env = Environment(FOO='yyy', BAR='zzz') + env.Dir('dir1') + env.Dir('dir2') + env.File('yyyzzz') + env.File('zzzyyy') + t = env.Ignore(target='targ.py', dependency='dep.py') - assert t.__class__.__name__ == 'File' + assert t.__class__.__name__ == 'Entry', t.__class__.__name__ assert t.path == 'targ.py' assert len(t.ignore) == 1 i = t.ignore[0] - assert i.__class__.__name__ == 'File' + assert i.__class__.__name__ == 'Entry', i.__class__.__name__ assert i.path == 'dep.py' + t = env.Ignore(target='$FOO$BAR', dependency='$BAR$FOO') - assert t.__class__.__name__ == 'File' + assert t.__class__.__name__ == 'File', t.__class__.__name__ assert t.path == 'yyyzzz' assert len(t.ignore) == 1 i = t.ignore[0] - assert i.__class__.__name__ == 'File' + assert i.__class__.__name__ == 'File', i.__class__.__name__ assert i.path == 'zzzyyy' + t = env.Ignore(target='dir1', dependency='dir2') + assert t.__class__.__name__ == 'Dir', t.__class__.__name__ + assert t.path == 'dir1' + assert len(t.ignore) == 1 + i = t.ignore[0] + assert i.__class__.__name__ == 'Dir', i.__class__.__name__ + assert i.path == 'dir2' + def test_Install(self): """Test the Install method""" env = Environment(FOO='iii', BAR='jjj') @@ -1530,21 +1556,24 @@ class EnvironmentTestCase(unittest.TestCase): def test_Precious(self): """Test the Precious() method""" env = Environment(FOO='ggg', BAR='hhh') - t = env.Precious('a', '${BAR}b', ['c', 'd'], '$FOO') - assert t[0].__class__.__name__ == 'File' - assert t[0].path == 'a' + env.Dir('p_hhhb') + env.File('p_d') + t = env.Precious('p_a', 'p_${BAR}b', ['p_c', 'p_d'], 'p_$FOO') + + assert t[0].__class__.__name__ == 'Entry', t[0].__class__.__name__ + assert t[0].path == 'p_a' assert t[0].precious - assert t[1].__class__.__name__ == 'File' - assert t[1].path == 'hhhb' + assert t[1].__class__.__name__ == 'Dir', t[1].__class__.__name__ + assert t[1].path == 'p_hhhb' assert t[1].precious - assert t[2].__class__.__name__ == 'File' - assert t[2].path == 'c' + assert t[2].__class__.__name__ == 'Entry', t[2].__class__.__name__ + assert t[2].path == 'p_c' assert t[2].precious - assert t[3].__class__.__name__ == 'File' - assert t[3].path == 'd' + assert t[3].__class__.__name__ == 'File', t[3].__class__.__name__ + assert t[3].path == 'p_d' assert t[3].precious - assert t[4].__class__.__name__ == 'File' - assert t[4].path == 'ggg' + assert t[4].__class__.__name__ == 'Entry', t[4].__class__.__name__ + assert t[4].path == 'p_ggg' assert t[4].precious def test_Repository(self): @@ -1602,10 +1631,13 @@ class EnvironmentTestCase(unittest.TestCase): def test_SideEffect(self): """Test the SideEffect() method""" env = Environment(LIB='lll', FOO='fff', BAR='bbb') + env.File('mylll.pdb') + env.Dir('mymmm.pdb') foo = env.Object('foo.obj', 'foo.cpp') bar = env.Object('bar.obj', 'bar.cpp') s = env.SideEffect('mylib.pdb', ['foo.obj', 'bar.obj']) + assert s.__class__.__name__ == 'Entry', s.__class__.__name__ assert s.path == 'mylib.pdb' assert s.side_effect assert foo.side_effects == [s] @@ -1616,6 +1648,7 @@ class EnvironmentTestCase(unittest.TestCase): fff = env.Object('fff.obj', 'fff.cpp') bbb = env.Object('bbb.obj', 'bbb.cpp') s = env.SideEffect('my${LIB}.pdb', ['${FOO}.obj', '${BAR}.obj']) + assert s.__class__.__name__ == 'File', s.__class__.__name__ assert s.path == 'mylll.pdb' assert s.side_effect assert fff.side_effects == [s], fff.side_effects @@ -1623,6 +1656,17 @@ class EnvironmentTestCase(unittest.TestCase): assert s.depends_on([bbb]) assert s.depends_on([fff]) + ggg = env.Object('ggg.obj', 'ggg.cpp') + ccc = env.Object('ccc.obj', 'ccc.cpp') + s = env.SideEffect('mymmm.pdb', ['ggg.obj', 'ccc.obj']) + assert s.__class__.__name__ == 'Dir', s.__class__.__name__ + assert s.path == 'mymmm.pdb' + assert s.side_effect + assert ggg.side_effects == [s], ggg.side_effects + assert ccc.side_effects == [s], ccc.side_effects + assert s.depends_on([ccc]) + assert s.depends_on([ggg]) + def test_SourceCode(self): """Test the SourceCode() method.""" env = Environment(FOO='mmm', BAR='nnn') diff --git a/test/Depends.py b/test/Depends.py index 4dfc55a..530c3c9 100644 --- a/test/Depends.py +++ b/test/Depends.py @@ -32,7 +32,7 @@ python = TestSCons.python test = TestSCons.TestSCons() -test.subdir('subdir') +test.subdir('subdir', 'sub2') test.write('build.py', r""" import sys @@ -52,6 +52,9 @@ env.Foo(target = 'f1.out', source = 'f1.in') env.Foo(target = 'f2.out', source = 'f2.in') env.Bar(target = 'subdir/f3.out', source = 'f3.in') SConscript('subdir/SConscript', "env") +env.Foo(target = 'f5.out', source = 'f5.in') +env.Bar(target = 'sub2/f6.out', source = 'f6.in') +env.Depends(target = 'f5.out', dependency = 'sub2') """ % (python, python, os.path.join('$SUBDIR', 'foo.dep'), @@ -64,28 +67,29 @@ env.Bar(target = 'f4.out', source = 'f4.in') """) test.write('f1.in', "f1.in\n") - test.write('f2.in', "f2.in\n") - test.write('f3.in', "f3.in\n") - test.write(['subdir', 'f4.in'], "subdir/f4.in\n") +test.write('f5.in', "f5.in\n") +test.write('f6.in', "f6.in\n") test.write(['subdir', 'foo.dep'], "subdir/foo.dep 1\n") - test.write(['subdir', 'bar.dep'], "subdir/bar.dep 1\n") -test.run(arguments = '--debug=dtree .') +test.run(arguments = '.') test.fail_test(test.read('f1.out') != "f1.in\nsubdir/foo.dep 1\n") test.fail_test(test.read('f2.out') != "f2.in\nsubdir/foo.dep 1\n") test.fail_test(test.read(['subdir', 'f3.out']) != "f3.in\nsubdir/bar.dep 1\n") test.fail_test(test.read(['subdir', 'f4.out']) != "subdir/f4.in\nsubdir/bar.dep 1\n") +test.fail_test(test.read('f5.out') != "f5.in\nsubdir/foo.dep 1\n") +test.fail_test(test.read(['sub2', 'f6.out']) != "f6.in\nsubdir/bar.dep 1\n") +# test.write(['subdir', 'foo.dep'], "subdir/foo.dep 2\n") - test.write(['subdir', 'bar.dep'], "subdir/bar.dep 2\n") +test.write('f6.in', "f6.in 2\n") test.run(arguments = '.') @@ -94,15 +98,46 @@ test.fail_test(test.read('f2.out') != "f2.in\nsubdir/foo.dep 2\n") test.fail_test(test.read(['subdir', 'f3.out']) != "f3.in\nsubdir/bar.dep 2\n") test.fail_test(test.read(['subdir', 'f4.out']) != "subdir/f4.in\nsubdir/bar.dep 2\n") +test.fail_test(test.read('f5.out') != "f5.in\nsubdir/foo.dep 2\n") +test.fail_test(test.read(['sub2', 'f6.out']) != "f6.in 2\nsubdir/bar.dep 2\n") + +# +test.write(['subdir', 'foo.dep'], "subdir/foo.dep 3\n") + +test.run(arguments = '.') + +test.fail_test(test.read('f1.out') != "f1.in\nsubdir/foo.dep 3\n") +test.fail_test(test.read('f2.out') != "f2.in\nsubdir/foo.dep 3\n") +test.fail_test(test.read(['subdir', 'f3.out']) != "f3.in\nsubdir/bar.dep 2\n") +test.fail_test(test.read(['subdir', 'f4.out']) != + "subdir/f4.in\nsubdir/bar.dep 2\n") +test.fail_test(test.read('f5.out') != "f5.in\nsubdir/foo.dep 2\n") +test.fail_test(test.read(['sub2', 'f6.out']) != "f6.in 2\nsubdir/bar.dep 2\n") +# test.write(['subdir', 'bar.dep'], "subdir/bar.dep 3\n") test.run(arguments = '.') -test.fail_test(test.read('f1.out') != "f1.in\nsubdir/foo.dep 2\n") -test.fail_test(test.read('f2.out') != "f2.in\nsubdir/foo.dep 2\n") +test.fail_test(test.read('f1.out') != "f1.in\nsubdir/foo.dep 3\n") +test.fail_test(test.read('f2.out') != "f2.in\nsubdir/foo.dep 3\n") +test.fail_test(test.read(['subdir', 'f3.out']) != "f3.in\nsubdir/bar.dep 3\n") +test.fail_test(test.read(['subdir', 'f4.out']) != + "subdir/f4.in\nsubdir/bar.dep 3\n") +test.fail_test(test.read('f5.out') != "f5.in\nsubdir/foo.dep 2\n") +test.fail_test(test.read(['sub2', 'f6.out']) != "f6.in 2\nsubdir/bar.dep 2\n") + +# +test.write('f6.in', "f6.in 3\n") + +test.run(arguments = '.') + +test.fail_test(test.read('f1.out') != "f1.in\nsubdir/foo.dep 3\n") +test.fail_test(test.read('f2.out') != "f2.in\nsubdir/foo.dep 3\n") test.fail_test(test.read(['subdir', 'f3.out']) != "f3.in\nsubdir/bar.dep 3\n") test.fail_test(test.read(['subdir', 'f4.out']) != "subdir/f4.in\nsubdir/bar.dep 3\n") +test.fail_test(test.read('f5.out') != "f5.in\nsubdir/foo.dep 3\n") +test.fail_test(test.read(['sub2', 'f6.out']) != "f6.in 3\nsubdir/bar.dep 3\n") test.pass_test() -- cgit v0.12