From 2a699f9f42a4249b2de91972680066f5b40f44cb Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sat, 28 Jun 2003 05:07:53 +0000 Subject: [PATCH] Support targets that always rebuild. (Stephen Ng) [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 | 4 ++- src/engine/SCons/Environment.py | 12 +++++++ src/engine/SCons/Node/NodeTests.py | 9 +++++ src/engine/SCons/Node/__init__.py | 5 +++ src/engine/SCons/Sig/SigTests.py | 4 +++ src/engine/SCons/Sig/__init__.py | 4 +++ test/AlwaysBuild.py | 55 ++++++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 test/AlwaysBuild.py diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 214401f7..cdfc7d80 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -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 diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 0f5cb30f..04452a9c 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -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: diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py index ff578719..f8593d7e 100644 --- a/src/engine/SCons/Node/NodeTests.py +++ b/src/engine/SCons/Node/NodeTests.py @@ -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 """ diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index 43ae7c5c..0fc2365b 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -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: diff --git a/src/engine/SCons/Sig/SigTests.py b/src/engine/SCons/Sig/SigTests.py index bb3efb8f..30103968 100644 --- a/src/engine/SCons/Sig/SigTests.py +++ b/src/engine/SCons/Sig/SigTests.py @@ -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): diff --git a/src/engine/SCons/Sig/__init__.py b/src/engine/SCons/Sig/__init__.py index 6f830b64..65fe8077 100644 --- a/src/engine/SCons/Sig/__init__.py +++ b/src/engine/SCons/Sig/__init__.py @@ -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 index 00000000..f4126c15 --- /dev/null +++ b/test/AlwaysBuild.py @@ -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() -- 2.26.2