summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2006-02-13 03:52:41 (GMT)
committerSteven Knight <knight@baldmt.com>2006-02-13 03:52:41 (GMT)
commit804ff6d25ac70aabcd913fe44d441799867a7dd7 (patch)
tree004e8fcfa1e69736fcbbf7590da8036b9a8ae4eb /src
parentf325a0ceb04f04d045862eee8373a586011e4ebf (diff)
downloadSCons-804ff6d25ac70aabcd913fe44d441799867a7dd7.zip
SCons-804ff6d25ac70aabcd913fe44d441799867a7dd7.tar.gz
SCons-804ff6d25ac70aabcd913fe44d441799867a7dd7.tar.bz2
Add a NoClean() function. (Steven Johnson)
Diffstat (limited to 'src')
-rw-r--r--src/CHANGES.txt5
-rw-r--r--src/engine/SCons/Environment.py9
-rw-r--r--src/engine/SCons/EnvironmentTests.py23
-rw-r--r--src/engine/SCons/Node/NodeTests.py9
-rw-r--r--src/engine/SCons/Node/__init__.py5
-rw-r--r--src/engine/SCons/Script/Main.py4
-rw-r--r--src/engine/SCons/Script/__init__.py1
-rw-r--r--src/engine/SCons/Util.py18
-rw-r--r--src/engine/SCons/UtilTests.py6
9 files changed, 68 insertions, 12 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index e2d5d7c..9e6cb16 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -62,6 +62,11 @@ RELEASE 0.97 - XXX
- Support $MAKEINDEX, $MAKEINDEXCOM, $MAKEINDEXCOMSTR and
$MAKEINDEXFLAGS for generating indices from .idx files.
+ From Steven Johnson:
+
+ - Add a NoClean() Environment method and function to override removal
+ of targets during a -c clean, including documentation and tests.
+
From Steven Knight:
- Check for whether files exist on disk by listing the directory
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index 92b1e3d..691098d 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -1285,6 +1285,15 @@ class Base(SubstitutionEnvironment):
"""
return apply(self.fs.Dir, (self.subst(name),) + args, kw)
+ def NoClean(self, *targets):
+ """Tags a target so that it will not be cleaned by -c"""
+ tlist = []
+ for t in targets:
+ tlist.extend(self.arg2nodes(t, self.fs.Entry))
+ for t in tlist:
+ t.set_noclean()
+ return tlist
+
def Entry(self, name, *args, **kw):
"""
"""
diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py
index 58c8ae8..48b258e 100644
--- a/src/engine/SCons/EnvironmentTests.py
+++ b/src/engine/SCons/EnvironmentTests.py
@@ -2285,6 +2285,29 @@ def generate(env):
d = env.Dir('${BAR}_$BAR')
assert d == 'Dir(bardir_bardir)', d
+ def test_NoClean(self):
+ """Test the NoClean() method"""
+ env = Environment(FOO='ggg', BAR='hhh')
+ env.Dir('p_hhhb')
+ env.File('p_d')
+ t = env.NoClean('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].noclean
+ assert t[1].__class__.__name__ == 'Dir', t[1].__class__.__name__
+ assert t[1].path == 'p_hhhb'
+ assert t[1].noclean
+ assert t[2].__class__.__name__ == 'Entry', t[2].__class__.__name__
+ assert t[2].path == 'p_c'
+ assert t[2].noclean
+ assert t[3].__class__.__name__ == 'File', t[3].__class__.__name__
+ assert t[3].path == 'p_d'
+ assert t[3].noclean
+ assert t[4].__class__.__name__ == 'Entry', t[4].__class__.__name__
+ assert t[4].path == 'p_ggg'
+ assert t[4].noclean
+
def test_Dump(self):
"""Test the Dump() method"""
diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py
index 4f7b65a..cd546cd 100644
--- a/src/engine/SCons/Node/NodeTests.py
+++ b/src/engine/SCons/Node/NodeTests.py
@@ -704,6 +704,15 @@ class NodeTestCase(unittest.TestCase):
node.set_always_build(3)
assert node.always_build == 3
+ def test_set_noclean(self):
+ """Test setting a Node's noclean value
+ """
+ node = SCons.Node.Node()
+ node.set_noclean()
+ assert node.noclean
+ node.set_noclean(7)
+ assert node.noclean == 7
+
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 483e88b..67a72ae 100644
--- a/src/engine/SCons/Node/__init__.py
+++ b/src/engine/SCons/Node/__init__.py
@@ -197,6 +197,7 @@ class Node:
self.env = None
self.state = no_state
self.precious = None
+ self.noclean = None
self.always_build = None
self.found_includes = {}
self.includes = None
@@ -740,6 +741,10 @@ class Node:
"""Set the Node's precious value."""
self.precious = precious
+ def set_noclean(self, noclean = 1):
+ """Set the Node's noclean value."""
+ self.noclean = noclean
+
def set_always_build(self, always_build = 1):
"""Set the Node's always_build value."""
self.always_build = always_build
diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py
index 8b3058a..5b35e14 100644
--- a/src/engine/SCons/Script/Main.py
+++ b/src/engine/SCons/Script/Main.py
@@ -224,7 +224,7 @@ class CleanTask(SCons.Taskmaster.Task):
def show(self):
target = self.targets[0]
- if target.has_builder() or target.side_effect:
+ if (target.has_builder() or target.side_effect) and not target.noclean:
for t in self.targets:
if not t.isdir():
display("Removed " + str(t))
@@ -235,7 +235,7 @@ class CleanTask(SCons.Taskmaster.Task):
def remove(self):
target = self.targets[0]
- if target.has_builder() or target.side_effect:
+ if (target.has_builder() or target.side_effect) and not target.noclean:
for t in self.targets:
try:
removed = t.remove()
diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py
index 97ffdce..ce96867 100644
--- a/src/engine/SCons/Script/__init__.py
+++ b/src/engine/SCons/Script/__init__.py
@@ -281,6 +281,7 @@ GlobalDefaultEnvironmentFunctions = [
#The Command() method is handled separately, below.
'Depends',
'Dir',
+ 'NoClean',
'Entry',
'Execute',
'File',
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py
index 37f3c06..d96f56c 100644
--- a/src/engine/SCons/Util.py
+++ b/src/engine/SCons/Util.py
@@ -343,14 +343,15 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited={}):
if showtags:
if showtags == 2:
- print ' E = exists'
- print ' R = exists in repository only'
- print ' b = implicit builder'
- print ' B = explicit builder'
- print ' S = side effect'
- print ' P = precious'
- print ' A = always build'
- print ' C = current'
+ print ' E = exists'
+ print ' R = exists in repository only'
+ print ' b = implicit builder'
+ print ' B = explicit builder'
+ print ' S = side effect'
+ print ' P = precious'
+ print ' A = always build'
+ print ' C = current'
+ print ' N = no clean'
print ''
tags = ['[']
@@ -362,6 +363,7 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited={}):
tags.append(' P'[IDX(root.precious)])
tags.append(' A'[IDX(root.always_build)])
tags.append(' C'[IDX(root.current())])
+ tags.append(' N'[IDX(root.noclean())])
tags.append(']')
else:
diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py
index 724c51d..aa93db1 100644
--- a/src/engine/SCons/UtilTests.py
+++ b/src/engine/SCons/UtilTests.py
@@ -74,6 +74,8 @@ class UtilTestCase(unittest.TestCase):
return 1
def current(self):
return 1
+ def noclean(self):
+ return 1
def tree_case_1(self):
"""Fixture for the render_tree() and print_tree() tests."""
@@ -98,7 +100,7 @@ class UtilTestCase(unittest.TestCase):
"""
lines = string.split(expect, '\n')[:-1]
- lines = map(lambda l: '[E BSPAC]'+l, lines)
+ lines = map(lambda l: '[E BSPACN]'+l, lines)
withtags = string.join(lines, '\n') + '\n'
return foo, expect, withtags
@@ -121,7 +123,7 @@ class UtilTestCase(unittest.TestCase):
"""
lines = string.split(expect, '\n')[:-1]
- lines = map(lambda l: '[E BSPAC]'+l, lines)
+ lines = map(lambda l: '[E BSPACN]'+l, lines)
withtags = string.join(lines, '\n') + '\n'
return blat_o, expect, withtags