summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/CHANGES.txt2
-rw-r--r--src/engine/SCons/Node/FS.py7
-rw-r--r--src/engine/SCons/Node/FSTests.py29
-rw-r--r--src/engine/SCons/Node/__init__.py4
-rw-r--r--src/engine/SCons/Script/__init__.py26
-rw-r--r--test/option-c.py11
6 files changed, 61 insertions, 18 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index ea65a0a..96e1939 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -35,6 +35,8 @@ RELEASE 0.09 -
- Fix an exception thrown when a Default() directory was specified
when using the -U option.
+ - Issue a warning when -c can't remove a target.
+
From Anthony Roach:
- Fixed use of command lines with spaces in their arguments,
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index c4b220f..7174b99 100644
--- a/src/engine/SCons/Node/FS.py
+++ b/src/engine/SCons/Node/FS.py
@@ -781,6 +781,13 @@ class File(Entry):
else:
self.__createDir()
+ def remove(self):
+ """Remove this file."""
+ if os.path.exists(self.path):
+ os.unlink(self.path)
+ return 1
+ return None
+
def current(self, calc):
bsig = calc.bsig(self)
if not self.exists():
diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py
index f87abe7..adcccae 100644
--- a/src/engine/SCons/Node/FSTests.py
+++ b/src/engine/SCons/Node/FSTests.py
@@ -583,6 +583,35 @@ class FSTestCase(unittest.TestCase):
# XXX test current()
+ d = fs.Dir('dir')
+ r = d.remove()
+ assert r is None, r
+
+ f = fs.File('does_not_exist')
+ r = f.remove()
+ assert r == None, r
+
+ test.write('exists', "exists\n")
+ f = fs.File('exists')
+ r = f.remove()
+ assert r, r
+
+ test.write('can_not_remove', "can_not_remove\n")
+ test.writable(test.workpath('.'), 0)
+ fp = open(test.workpath('can_not_remove'))
+
+ f = fs.File('can_not_remove')
+ exc_caught = 0
+ try:
+ r = f.remove()
+ except OSError:
+ exc_caught = 1
+
+ fp.close()
+
+ assert exc_caught, "Should have caught an OSError, r = " + str(r)
+
+
class RepositoryTestCase(unittest.TestCase):
def runTest(self):
"""Test FS (file system) Repository operations
diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py
index d12edae..09ceea0 100644
--- a/src/engine/SCons/Node/__init__.py
+++ b/src/engine/SCons/Node/__init__.py
@@ -339,6 +339,10 @@ class Node:
"""Prepare for this Node to be created: no-op by default."""
pass
+ def remove(self):
+ """Remove this Node: no-op by default."""
+ return None
+
def add_dependency(self, depend):
"""Adds dependencies. The depend argument must be a list."""
self._add_child(self.depends, depend)
diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py
index cff3a21..365a0b1 100644
--- a/src/engine/SCons/Script/__init__.py
+++ b/src/engine/SCons/Script/__init__.py
@@ -130,26 +130,18 @@ class CleanTask(SCons.Taskmaster.Task):
"""An SCons clean task."""
def show(self):
if self.targets[0].builder or self.targets[0].side_effect:
- print "Removed " + self.targets[0].path
+ print "Removed " + str(self.targets[0])
def remove(self):
if self.targets[0].builder or self.targets[0].side_effect:
- try:
- os.unlink(self.targets[0].path)
- except OSError:
- pass
- else:
- print "Removed " + self.targets[0].path
- try:
- for t in self.targets[1:]:
- try:
- os.unlink(t.path)
- except OSError:
- pass
- else:
- print "Removed " + t.path
- except IndexError:
- pass
+ for t in self.targets:
+ try:
+ removed = t.remove()
+ except OSError, e:
+ print "scons: Could not remove '%s':" % str(t), e.strerror
+ else:
+ if removed:
+ print "Removed " + str(t)
execute = remove
diff --git a/test/option-c.py b/test/option-c.py
index a686f5a..6bb25da 100644
--- a/test/option-c.py
+++ b/test/option-c.py
@@ -121,5 +121,14 @@ test.fail_test(test.read(test.workpath('foo2.xxx')) != "foo2.in\n")
test.fail_test(test.read(test.workpath('foo2.out')) != "foo2.in\n")
test.fail_test(test.read(test.workpath('foo3.out')) != "foo3.in\n")
+test.writable('.', 0)
+f = open(test.workpath('foo1.out'))
+
+test.run(arguments = '-c foo1.out',
+ stdout = "scons: Could not remove 'foo1.out': Permission denied\n")
+
+test.fail_test(not os.path.exists(test.workpath('foo1.out')))
+
+f.close()
+
test.pass_test()
-