Support targets that always rebuild. (Stephen Ng)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 28 Jun 2003 05:07:53 +0000 (05:07 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 28 Jun 2003 05:07:53 +0000 (05:07 +0000)
[Updating a change that was previously not synchronized to CVS.]

git-svn-id: http://scons.tigris.org/svn/scons/trunk@727 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/engine/SCons/Environment.py
src/engine/SCons/Node/NodeTests.py
src/engine/SCons/Node/__init__.py
src/engine/SCons/Sig/SigTests.py
src/engine/SCons/Sig/__init__.py
test/AlwaysBuild.py [new file with mode: 0644]

index 214401f7edd519f2d4fabaae84a84834c0ad5e4e..cdfc7d802fb80d5122c9a8ebb3aad20b87e9fdd7 100644 (file)
@@ -688,7 +688,9 @@ Walks up the directory structure until an
 or 
 .I sconstruct
 file is found, and uses that
-as the top of the directory tree. Only targets at or below the
+as the top of the directory tree.
+If no targets are specified on the command line,
+only targets at or below the
 current directory will be built.
 
 .TP
index 0f5cb30fdde75126382dd956cd5bbb45718e8b80..04452a9c01e56988e5e56a82351b62e528e1de47 100644 (file)
@@ -338,6 +338,18 @@ class Environment:
             tlist = tlist[0]
         return tlist
 
+    def AlwaysBuild(self, *targets):
+        tlist = []
+        for t in targets:
+            tlist.extend(SCons.Node.arg2nodes(t, self.fs.File))
+
+        for t in tlist:
+            t.set_always_build()
+
+        if len(tlist) == 1:
+            tlist = tlist[0]
+        return tlist
+
     def Precious(self, *targets):
         tlist = []
         for t in targets:
index ff578719de070d1bdaecd225ac3e4f73978b2964..f8593d7ec331342d6e53ee3a10953c05cd397bbe 100644 (file)
@@ -381,6 +381,15 @@ class NodeTestCase(unittest.TestCase):
         node = SCons.Node.Node()
         node.store_timestamp()
 
+    def test_set_always_build(self):
+        """Test setting a Node's always_build value
+        """
+        node = SCons.Node.Node()
+        node.set_always_build()
+        assert node.always_build
+        node.set_always_build(3)
+        assert node.always_build == 3
+
     def test_set_precious(self):
         """Test setting a Node's precious value
         """
index 43ae7c5c26fc31ad293af6083b905d3067f4fffb..0fc2365b4067ced934430ab13f3a1b621417f8a7 100644 (file)
@@ -107,6 +107,7 @@ class Node:
         self.env = None
         self.state = None
         self.precious = None
+        self.always_build = None
         self.found_includes = {}
         self.includes = None
         self.overrides = {}     # construction variable overrides for building this node
@@ -521,6 +522,10 @@ class Node:
         """Set the Node's precious value."""
         self.precious = precious
 
+    def set_always_build(self, always_build = 1):
+        """Set the Node's always_build value."""
+        self.always_build = always_build
+
     def exists(self):
         """Does this node exists?"""
         # All node exist by default:
index bb3efb8f9ec5978af761a4d798bb80686142bf55..30103968ec02e530a493c579d44441c8e364f8ac 100644 (file)
@@ -58,6 +58,7 @@ class DummyNode:
         self.oldtime = 0
         self.oldbsig = 0
         self.oldcsig = 0
+        self.always_build = 0
 
     def has_builder(self):
         return self.builder
@@ -380,12 +381,15 @@ class CalcTestCase(unittest.TestCase):
 
     def test_Calc_current(self):
         class NN(self.nodeclass):
+            always_build = 0
             def current(self):
                 return None
 
         nn = NN('nn', 33, 34)
         assert not self.calc.current(nn, 30)
         assert self.calc.current(nn, 33)
+        nn.always_build = 1
+        assert not self.calc.current(nn, 33)
 
 class SConsignEntryTestCase(unittest.TestCase):
 
index 6f830b6497b198a6dfe21d48c5a52a8fa84b046d..65fe8077ffdbdebb0e4a8332feabf27a8b92055e 100644 (file)
@@ -344,6 +344,10 @@ class Calculator:
         returns - 1 if the file is current with the specified signature,
         0 if it isn't
         """
+
+        if node.always_build:
+            return 0
+        
         oldtime, oldbsig, oldcsig = node.get_prevsiginfo()
 
         if not node.has_builder() and node.get_timestamp() == oldtime:
diff --git a/test/AlwaysBuild.py b/test/AlwaysBuild.py
new file mode 100644 (file)
index 0000000..f4126c1
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import os
+import sys
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+def bfunc(target, source, env):
+    import shutil
+    shutil.copyfile('f2.in', str(target[0]))
+
+B = Builder(action=bfunc)
+env = Environment(BUILDERS = { 'B' : B })
+env.B('f1.out', source='f1.in')
+env.AlwaysBuild('f1.out')
+""")
+
+test.write('f1.in', "f1.in\n")
+test.write('f2.in', "1")
+
+test.run(arguments = ".")
+test.fail_test(test.read('f1.out') != '1')
+
+test.write('f2.in', "2")
+test.run(arguments = ".")
+test.fail_test(test.read('f1.out') != '2')
+
+test.pass_test()