summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/man/scons.1169
-rw-r--r--etc/TestSCons.py4
-rw-r--r--src/CHANGES.txt10
-rw-r--r--src/engine/SCons/Action.py85
-rw-r--r--src/engine/SCons/ActionTests.py106
-rw-r--r--src/engine/SCons/Defaults.py56
-rw-r--r--src/engine/SCons/Script/SConscript.py8
-rw-r--r--test/Chmod.py133
-rw-r--r--test/Copy.py115
-rw-r--r--test/Delete.py121
-rw-r--r--test/Mkdir.py97
-rw-r--r--test/Move.py90
-rw-r--r--test/Touch.py101
13 files changed, 1089 insertions, 6 deletions
diff --git a/doc/man/scons.1 b/doc/man/scons.1
index d271d0e..a264d7c 100644
--- a/doc/man/scons.1
+++ b/doc/man/scons.1
@@ -6617,6 +6617,175 @@ a = Action(build_it, varlist=['XXX'])
If the action argument is not one of the above,
None is returned.
+.SS Miscellaneous Action Functions
+
+.B scons
+supplies a number of functions
+that arrange for various common
+file and directory manipulations
+to be performed.
+These are similar in concept to "tasks" in the
+Ant build tool,
+although the implementation is slightly different.
+These functions do not actually
+perform the specified action
+at the time the function is called,
+but instead return an Action object
+that can be executed at the
+appropriate time.
+(In Object-Oriented terminology,
+these are actually
+Action
+.I Factory
+functions
+that return Action objects.)
+
+In practice,
+there are two natural ways
+that these
+Action Functions
+are intended to be used.
+
+First,
+if you need
+to perform the action
+at the time the SConscript
+file is being read,
+you can use the
+.B Execute
+global function to do so:
+.ES
+Execute(Touch('file'))
+.EE
+
+Second,
+you can use these functions
+to supply Actions in a list
+for use by the
+.B Command
+method.
+This can allow you to
+perform more complicated
+sequences of file manipulation
+without relying
+on platform-specific
+external commands:
+that
+.ES
+env = Environment(TMPBUILD = '/tmp/builddir')
+env.Command('foo.out', 'foo.in',
+ [Mkdir('$TMPBUILD'),
+ Copy('${SOURCE.dir}', '$TMPBUILD')
+ "cd $TMPBUILD && make",
+ Delete('$TMPBUILD')])
+.EE
+
+.TP
+.RI Chmod( dest ", " mode )
+Returns an Action object that
+changes the permissions on the specified
+.I dest
+file or directory to the specified
+.IR mode .
+Examples:
+
+.ES
+Execute(Chmod('file', 0755))
+
+env.Command('foo.out', 'foo.in',
+ [Copy('$TARGET', '$SOURCE'),
+ Chmod('$TARGET', 0755)])
+.EE
+
+.TP
+.RI Copy( dest ", " src )
+Returns an Action object
+that will copy the
+.I src
+source file or directory to the
+.I dest
+destination file or directory.
+Examples:
+
+.ES
+Execute(Copy('foo.output', 'foo.input'))
+
+env.Command('bar.out', 'bar.in',
+ Copy('$TARGET', '$SOURCE'))
+.EE
+
+.TP
+.RI Delete( entry )
+Returns an Action that
+deletes the specified
+.IR entry ,
+which may be a file or a directory tree.
+If a directory is specified,
+the entire directory tree
+will be removed.
+Examples:
+
+.ES
+Execute(Delete('/tmp/buildroot'))
+
+env.Command('foo.out', 'foo.in',
+ [Delete('${TARGET.dir}'),
+ MyBuildAction])
+.EE
+
+.TP
+.RI Mkdir( dir )
+Returns an Action
+that creates the specified
+directory
+.I dir .
+Examples:
+
+.ES
+Execute(Mkdir('/tmp/outputdir'))
+
+env.Command('foo.out', 'foo.in',
+ [Mkdir('/tmp/builddir',
+ Copy('$SOURCE', '/tmp/builddir')
+ "cd /tmp/builddir && ])
+
+.EE
+
+.TP
+.RI Move( dest ", " src )
+Returns an Action
+that moves the specified
+.I src
+file or directory to
+the specified
+.I dest
+file or directory.
+Examples:
+
+.ES
+Execute(Move('file.destination', 'file.source'))
+
+env.Command('output_file', 'input_file',
+ [MyBuildAction,
+ Move('$TARGET', 'file_created_by_MyBuildAction')])
+.EE
+
+.TP
+.RI Touch( file )
+Returns an Action
+that updates the modification time
+on the specified
+.IR file .
+Examples:
+
+.ES
+Execute(Touch('file_to_be_touched'))
+
+env.Command('marker', 'input_file',
+ [MyBuildAction,
+ Touch('$TARGET')])
+.EE
+
.SS Variable Substitution
Before executing a command,
diff --git a/etc/TestSCons.py b/etc/TestSCons.py
index b39b581..8cba239 100644
--- a/etc/TestSCons.py
+++ b/etc/TestSCons.py
@@ -180,14 +180,14 @@ class TestSCons(TestCommon):
build_str + \
term
- def up_to_date(self, options = None, arguments = None, **kw):
+ def up_to_date(self, options = None, arguments = None, read_str = "", **kw):
s = ""
for arg in string.split(arguments):
s = s + "scons: `%s' is up to date.\n" % arg
if options:
arguments = options + " " + arguments
kw['arguments'] = arguments
- kw['stdout'] = self.wrap_stdout(build_str = s)
+ kw['stdout'] = self.wrap_stdout(read_str = read_str, build_str = s)
apply(self.run, [], kw)
def not_up_to_date(self, options = None, arguments = None, **kw):
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index f3e9a3d..0d28a0a 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -83,6 +83,16 @@ RELEASE 0.96 - XXX
Environments are the same object, not if their underlying dictionaries
are equivalent.
+ - Add a --debug=explain option that reports the reason(s) why SCons
+ thinks it must rebuild something.
+
+ - Add support for functions that return platform-independent Actions
+ to Chmod(), Copy(), Delete(), Mkdir(), Move() and Touch() files
+ and/or directories. Like any other Actions, the returned Action
+ object may be executed directly using the Execute() global function
+ or env.Execute() environment method, or may be used as a Builder
+ action or in an env.Command() action list.
+
From Gary Oberbrunner:
- Add a --debug=presub option to print actions prior to substitution.
diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py
index 7397873..6b8b184 100644
--- a/src/engine/SCons/Action.py
+++ b/src/engine/SCons/Action.py
@@ -58,6 +58,14 @@ this module:
pre-substitution representations, and *then* execute an action
without worrying about the specific Actions involved.
+There is a related independent ActionCaller class that looks like a
+regular Action, and which serves as a wrapper for arbitrary functions
+that we want to let the user specify the arguments to now, but actually
+execute later (when an out-of-date check determines that it's needed to
+be executed, for example). Objects of this class are returned by an
+ActionFactory class that provides a __call__() method as a convenient
+way for wrapping up the functions.
+
"""
#
@@ -512,11 +520,21 @@ class FunctionAction(ActionBase):
"""
try:
# "self.execfunction" is a function.
- code = self.execfunction.func_code.co_code
+ contents = str(self.execfunction.func_code.co_code)
except AttributeError:
# "self.execfunction" is a callable object.
- code = self.execfunction.__call__.im_func.func_code.co_code
- return str(code) + env.subst(string.join(map(lambda v: '${'+v+'}',
+ try:
+ contents = str(self.execfunction.__call__.im_func.func_code.co_code)
+ except AttributeError:
+ try:
+ # See if execfunction will do the heavy lifting for us.
+ gc = self.execfunction.get_contents
+ except AttributeError:
+ # This is weird, just do the best we can.
+ contents = str(self.execfunction)
+ else:
+ contents = gc(target, source, env, dict)
+ return contents + env.subst(string.join(map(lambda v: '${'+v+'}',
self.varlist)))
class ListAction(ActionBase):
@@ -565,3 +583,64 @@ class ListAction(ActionBase):
x.get_contents(t, s, e, d),
self.list),
"")
+
+class ActionCaller:
+ """A class for delaying calling an Action function with specific
+ (positional and keyword) arguments until the Action is actually
+ executed.
+
+ This class looks to the rest of the world like a normal Action object,
+ but what it's really doing is hanging on to the arguments until we
+ have a target, source and env to use for the expansion.
+ """
+ def __init__(self, parent, args, kw):
+ self.parent = parent
+ self.args = args
+ self.kw = kw
+ def get_contents(self, target, source, env, dict=None):
+ actfunc = self.parent.actfunc
+ try:
+ # "self.actfunc" is a function.
+ contents = str(actfunc.func_code.co_code)
+ except AttributeError:
+ # "self.actfunc" is a callable object.
+ try:
+ contents = str(actfunc.__call__.im_func.func_code.co_code)
+ except AttributeError:
+ # No __call__() method, so it might be a builtin
+ # or something like that. Do the best we can.
+ contents = str(actfunc)
+ return contents
+ def subst_args(self, target, source, env):
+ return map(lambda x, e=env, t=target, s=source:
+ e.subst(x, 0, t, s),
+ self.args)
+ def subst_kw(self, target, source, env):
+ kw = {}
+ for key in self.kw.keys():
+ kw[key] = env.subst(self.kw[key], 0, target, source)
+ return kw
+ def __call__(self, target, source, env):
+ args = self.subst_args(target, source, env)
+ kw = self.subst_kw(target, source, env)
+ return apply(self.parent.actfunc, args, kw)
+ def strfunction(self, target, source, env):
+ args = self.subst_args(target, source, env)
+ kw = self.subst_kw(target, source, env)
+ return apply(self.parent.strfunc, args, kw)
+
+class ActionFactory:
+ """A factory class that will wrap up an arbitrary function
+ as an SCons-executable Action object.
+
+ The real heavy lifting here is done by the ActionCaller class.
+ We just collect the (positional and keyword) arguments that we're
+ called with and give them to the ActionCaller object we create,
+ so it can hang onto them until it needs them.
+ """
+ def __init__(self, actfunc, strfunc):
+ self.actfunc = actfunc
+ self.strfunc = strfunc
+ def __call__(self, *args, **kw):
+ ac = ActionCaller(self, args, kw)
+ return Action(ac, strfunction=ac.strfunction)
diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py
index a273607..589d1d3 100644
--- a/src/engine/SCons/ActionTests.py
+++ b/src/engine/SCons/ActionTests.py
@@ -1103,6 +1103,13 @@ class FunctionActionTestCase(unittest.TestCase):
c = a.get_contents(target=[], source=[], env=Environment(XYZ = 'foo'))
assert c == "\177\036\000\177\037\000d\000\000Sfoo", repr(c)
+ class Foo:
+ def get_contents(self, target, source, env, dict=None):
+ return 'xyzzy'
+ a = SCons.Action.FunctionAction(Foo())
+ c = a.get_contents(target=[], source=[], env=Environment())
+ assert c == 'xyzzy', repr(c)
+
class ListActionTestCase(unittest.TestCase):
def test___init__(self):
@@ -1265,6 +1272,101 @@ class LazyActionTestCase(unittest.TestCase):
c = a.get_contents(target=[], source=[], env=env, dict={})
assert c == "This is a test", c
+class ActionCallerTestCase(unittest.TestCase):
+ def test___init__(self):
+ """Test creation of an ActionCaller"""
+ ac = SCons.Action.ActionCaller(1, [2, 3], {'FOO' : 4, 'BAR' : 5})
+ assert ac.parent == 1, ac.parent
+ assert ac.args == [2, 3], ac.args
+ assert ac.kw == {'FOO' : 4, 'BAR' : 5}, ac.kw
+
+ def test_get_contents(self):
+ """Test fetching the contents of an ActionCaller"""
+ def actfunc():
+ pass
+ def strfunc():
+ pass
+
+ af = SCons.Action.ActionFactory(actfunc, strfunc)
+ ac = SCons.Action.ActionCaller(af, [], {})
+ c = ac.get_contents([], [], Environment())
+ assert c == "\177\005\005\177\006\005d\000\000S", repr(c)
+
+ class ActFunc:
+ def __call__(self):
+ pass
+
+ af = SCons.Action.ActionFactory(ActFunc(), strfunc)
+ ac = SCons.Action.ActionCaller(af, [], {})
+ c = ac.get_contents([], [], Environment())
+ assert c == "\177\020\005\177\021\005d\000\000S", repr(c)
+
+ af = SCons.Action.ActionFactory(str, strfunc)
+ ac = SCons.Action.ActionCaller(af, [], {})
+ c = ac.get_contents([], [], Environment())
+ assert c == "<built-in function str>" or \
+ c == "<type 'str'>", repr(c)
+
+ def test___call__(self):
+ """Test calling an ActionCaller"""
+ actfunc_args = []
+ def actfunc(a1, a2, a3, args=actfunc_args):
+ args.extend([a1, a2, a3])
+ def strfunc(a1, a2, a3):
+ pass
+
+ af = SCons.Action.ActionFactory(actfunc, strfunc)
+ ac = SCons.Action.ActionCaller(af, [1, '$FOO', 3], {})
+ ac([], [], Environment(FOO = 2))
+ assert actfunc_args == [1, '2', 3], actfunc_args
+
+ del actfunc_args[:]
+ ac = SCons.Action.ActionCaller(af, [], {'a3' : 6, 'a2' : '$BAR', 'a1' : 4})
+ ac([], [], Environment(BAR = 5))
+ assert actfunc_args == [4, '5', 6], actfunc_args
+
+ def test_strfunction(self):
+ """Test calling the ActionCaller strfunction() method"""
+ strfunc_args = []
+ def actfunc(a1, a2, a3):
+ pass
+ def strfunc(a1, a2, a3, args=strfunc_args):
+ args.extend([a1, a2, a3])
+
+ af = SCons.Action.ActionFactory(actfunc, strfunc)
+ ac = SCons.Action.ActionCaller(af, [1, '$FOO', 3], {})
+ ac.strfunction([], [], Environment(FOO = 2))
+ assert strfunc_args == [1, '2', 3], strfunc_args
+
+ del strfunc_args[:]
+ ac = SCons.Action.ActionCaller(af, [], {'a3' : 6, 'a2' : '$BAR', 'a1' : 4})
+ ac.strfunction([], [], Environment(BAR = 5))
+ assert strfunc_args == [4, '5', 6], strfunc_args
+
+class ActionFactoryTestCase(unittest.TestCase):
+ def test___init__(self):
+ """Test creation of an ActionFactory"""
+ def actfunc():
+ pass
+ def strfunc():
+ pass
+ ac = SCons.Action.ActionFactory(actfunc, strfunc)
+ assert ac.actfunc is actfunc, ac.actfunc
+ assert ac.strfunc is strfunc, ac.strfunc
+
+ def test___call__(self):
+ """Test calling whatever's returned from an ActionFactory"""
+ actfunc_args = []
+ strfunc_args = []
+ def actfunc(a1, a2, a3, args=actfunc_args):
+ args.extend([a1, a2, a3])
+ def strfunc(a1, a2, a3, args=strfunc_args):
+ args.extend([a1, a2, a3])
+ af = SCons.Action.ActionFactory(actfunc, strfunc)
+ af(3, 6, 9)([], [], Environment())
+ assert actfunc_args == [3, 6, 9], actfunc_args
+ assert strfunc_args == [3, 6, 9], strfunc_args
+
if __name__ == "__main__":
suite = unittest.TestSuite()
@@ -1274,7 +1376,9 @@ if __name__ == "__main__":
CommandGeneratorActionTestCase,
FunctionActionTestCase,
ListActionTestCase,
- LazyActionTestCase ]
+ LazyActionTestCase,
+ ActionCallerTestCase,
+ ActionFactoryTestCase ]
for tclass in tclasses:
names = unittest.getTestCaseNames(tclass, 'test_')
suite.addTests(map(tclass, names))
diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py
index 89ac0d3..98c9195 100644
--- a/src/engine/SCons/Defaults.py
+++ b/src/engine/SCons/Defaults.py
@@ -41,6 +41,7 @@ import os.path
import shutil
import stat
import string
+import time
import types
import SCons.Action
@@ -144,6 +145,61 @@ def PDF():
prefix = '$PDFPREFIX',
suffix = '$PDFSUFFIX')
+# Common tasks that we allow users to perform in platform-independent
+# ways by creating ActionFactory instances.
+ActionFactory = SCons.Action.ActionFactory
+
+Chmod = ActionFactory(os.chmod,
+ lambda dest, mode: 'Chmod("%s", 0%o)' % (dest, mode))
+
+def Copy(dest, src):
+ def _copy_func(target, source, env, dest=dest, src=src):
+ dest = str(env.arg2nodes(dest, env.fs.Entry)[0])
+ src = str(env.arg2nodes(src, env.fs.Entry)[0])
+ shutil.copytree(src, dest, 1)
+ def _copy_str(target, source, env, dest=dest, src=src):
+ dest = str(env.arg2nodes(dest, env.fs.Entry)[0])
+ src = str(env.arg2nodes(src, env.fs.Entry)[0])
+ return 'Copy("%s", "%s")' % (dest, src)
+ return SCons.Action.Action(_copy_func, strfunction=_copy_str)
+
+def copy_func(dest, src):
+ if os.path.isfile(src):
+ return shutil.copy(src, dest)
+ else:
+ return shutil.copytree(src, dest, 1)
+
+Copy = ActionFactory(copy_func,
+ lambda dest, src: 'Copy("%s", "%s")' % (dest, src))
+
+def delete_func(entry):
+ if os.path.isfile(entry):
+ return os.unlink(entry)
+ else:
+ return shutil.rmtree(entry, 1)
+
+Delete = ActionFactory(delete_func,
+ lambda entry: 'Delete("%s")' % entry)
+
+Mkdir = ActionFactory(os.makedirs,
+ lambda dir: 'Mkdir("%s")' % dir)
+
+Move = ActionFactory(lambda dest, src: os.rename(src, dest),
+ lambda dest, src: 'Move("%s", "%s")' % (dest, src))
+
+def touch_func(file):
+ mtime = int(time.time())
+ if os.path.exists(file):
+ atime = os.path.getatime(file)
+ else:
+ open(file, 'w')
+ atime = mtime
+ return os.utime(file, (atime, mtime))
+
+Touch = ActionFactory(touch_func,
+ lambda file: 'Touch("%s")' % file)
+
+# Internal utility functions
def copyFunc(dest, source, env):
"""Install a source file into a destination by copying it (and its
permission/mode bits)."""
diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py
index 417e1c0..6a414b7 100644
--- a/src/engine/SCons/Script/SConscript.py
+++ b/src/engine/SCons/Script/SConscript.py
@@ -674,6 +674,14 @@ def BuildDefaultGlobals():
'Tool' : SCons.Tool.Tool,
'WhereIs' : SCons.Util.WhereIs,
+ # Action factories.
+ 'Chmod' : SCons.Defaults.Chmod,
+ 'Copy' : SCons.Defaults.Copy,
+ 'Delete' : SCons.Defaults.Delete,
+ 'Mkdir' : SCons.Defaults.Mkdir,
+ 'Move' : SCons.Defaults.Move,
+ 'Touch' : SCons.Defaults.Touch,
+
# Other variables we provide.
'ARGUMENTS' : Arguments,
'BUILD_TARGETS' : BuildTargets,
diff --git a/test/Chmod.py b/test/Chmod.py
new file mode 100644
index 0000000..517b83d
--- /dev/null
+++ b/test/Chmod.py
@@ -0,0 +1,133 @@
+#!/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__"
+
+"""
+Verify that the Chmod() Action works.
+"""
+
+import os
+import os.path
+import stat
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+Execute(Chmod('f1', 0777))
+Execute(Chmod('d2', 0777))
+def cat(env, source, target):
+ target = str(target[0])
+ source = map(str, source)
+ f = open(target, "wb")
+ for src in source:
+ f.write(open(src, "rb").read())
+ f.close()
+Cat = Action(cat)
+env = Environment()
+env.Command('bar.out', 'bar.in', [Cat,
+ Chmod("f3", 0755),
+ Chmod("d4", 0755)])
+env = Environment(FILE = 'f5')
+env.Command('f6.out', 'f6.in', [Chmod('$FILE', 0775), Cat])
+env.Command('f7.out', 'f7.in', [Cat,
+ Chmod('Chmod-$SOURCE', 0775),
+ Chmod('${TARGET}-Chmod', 0775)])
+""")
+
+test.write('f1', "f1\n")
+test.subdir('d2')
+test.write(['d2', 'file'], "d2/file\n")
+test.write('bar.in', "bar.in\n")
+test.write('f3', "f3\n")
+test.subdir('d4')
+test.write(['d4', 'file'], "d4/file\n")
+test.write('f5', "f5\n")
+test.write('f6.in', "f6.in\n")
+test.write('f7.in', "f7.in\n")
+test.write('Chmod-f7.in', "Chmod-f7.in\n")
+test.write('f7.out-Chmod', "f7.out-Chmod\n")
+
+os.chmod(test.workpath('f1'), 0700)
+os.chmod(test.workpath('d2'), 0700)
+os.chmod(test.workpath('f3'), 0700)
+os.chmod(test.workpath('d4'), 0700)
+os.chmod(test.workpath('f5'), 0700)
+os.chmod(test.workpath('Chmod-f7.in'), 0700)
+os.chmod(test.workpath('f7.out-Chmod'), 0700)
+
+expect = test.wrap_stdout(read_str = 'Chmod("f1", 0777)\nChmod("d2", 0777)\n',
+ build_str = """\
+cat("bar.out", "bar.in")
+Chmod("f3", 0755)
+Chmod("d4", 0755)
+Chmod("f5", 0775)
+cat("f6.out", "f6.in")
+cat("f7.out", "f7.in")
+Chmod("Chmod-f7.in", 0775)
+Chmod("f7.out-Chmod", 0775)
+""")
+test.run(options = '-n', arguments = '.', stdout = expect)
+
+s = stat.S_IMODE(os.stat(test.workpath('f1'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+s = stat.S_IMODE(os.stat(test.workpath('d2'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+test.must_not_exist('bar.out')
+s = stat.S_IMODE(os.stat(test.workpath('f3'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+s = stat.S_IMODE(os.stat(test.workpath('d4'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+s = stat.S_IMODE(os.stat(test.workpath('f5'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+test.must_not_exist('f6.out')
+test.must_not_exist('f7.out')
+s = stat.S_IMODE(os.stat(test.workpath('Chmod-f7.in'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+s = stat.S_IMODE(os.stat(test.workpath('f7.out-Chmod'))[stat.ST_MODE])
+test.fail_test(s != 0700)
+
+test.run()
+
+s = stat.S_IMODE(os.stat(test.workpath('f1'))[stat.ST_MODE])
+test.fail_test(s != 0777)
+s = stat.S_IMODE(os.stat(test.workpath('d2'))[stat.ST_MODE])
+test.fail_test(s != 0777)
+test.must_match('bar.out', "bar.in\n")
+s = stat.S_IMODE(os.stat(test.workpath('f3'))[stat.ST_MODE])
+test.fail_test(s != 0755)
+s = stat.S_IMODE(os.stat(test.workpath('d4'))[stat.ST_MODE])
+test.fail_test(s != 0755)
+s = stat.S_IMODE(os.stat(test.workpath('f5'))[stat.ST_MODE])
+test.fail_test(s != 0775)
+test.must_match('f6.out', "f6.in\n")
+test.must_match('f7.out', "f7.in\n")
+s = stat.S_IMODE(os.stat(test.workpath('Chmod-f7.in'))[stat.ST_MODE])
+test.fail_test(s != 0775)
+s = stat.S_IMODE(os.stat(test.workpath('f7.out-Chmod'))[stat.ST_MODE])
+test.fail_test(s != 0775)
+
+test.pass_test()
diff --git a/test/Copy.py b/test/Copy.py
new file mode 100644
index 0000000..00642da
--- /dev/null
+++ b/test/Copy.py
@@ -0,0 +1,115 @@
+#!/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__"
+
+"""
+Verify that the Delete() Action works.
+"""
+
+import os.path
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+Execute(Copy('f1.out', 'f1.in'))
+Execute(Copy('d2.out', 'd2.in'))
+Execute(Copy('d3.out', 'f3.in'))
+def cat(env, source, target):
+ target = str(target[0])
+ source = map(str, source)
+ f = open(target, "wb")
+ for src in source:
+ f.write(open(src, "rb").read())
+ f.close()
+Cat = Action(cat)
+env = Environment()
+env.Command('bar.out', 'bar.in', [Cat,
+ Copy("f4.out", "f4.in"),
+ Copy("d5.out", "d5.in"),
+ Copy("d6.out", "f6.in")])
+env = Environment(OUTPUT = 'f7.out', INPUT = 'f7.in')
+env.Command('f8.out', 'f8.in', [Copy('$OUTPUT', '$INPUT'), Cat])
+env.Command('f9.out', 'f9.in', [Cat, Copy('${TARGET}-Copy', '$SOURCE')])
+""")
+
+test.write('f1.in', "f1.in\n")
+test.subdir('d2.in')
+test.write(['d2.in', 'file'], "d2.in/file\n")
+test.write('f3.in', "f3.in\n")
+test.subdir('d3.out')
+test.write('bar.in', "bar.in\n")
+test.write('f4.in', "f4.in\n")
+test.subdir('d5.in')
+test.write(['d5.in', 'file'], "d5.in/file\n")
+test.write('f6.in', "f6.in\n")
+test.subdir('d6.out')
+test.write('f7.in', "f7.in\n")
+test.write('f8.in', "f8.in\n")
+test.write('f9.in', "f9.in\n")
+
+expect = test.wrap_stdout(read_str = """\
+Copy("f1.out", "f1.in")
+Copy("d2.out", "d2.in")
+Copy("d3.out", "f3.in")
+""",
+ build_str = """\
+cat("bar.out", "bar.in")
+Copy("f4.out", "f4.in")
+Copy("d5.out", "d5.in")
+Copy("d6.out", "f6.in")
+Copy("f7.out", "f7.in")
+cat("f8.out", "f8.in")
+cat("f9.out", "f9.in")
+Copy("f9.out-Copy", "f9.in")
+""")
+test.run(options = '-n', arguments = '.', stdout = expect)
+
+test.must_not_exist('f1.out')
+test.must_not_exist('d2.out')
+test.must_not_exist(os.path.join('d3.out', 'f3.in'))
+test.must_not_exist('f4.out')
+test.must_not_exist('d5.out')
+test.must_not_exist(os.path.join('d6.out', 'f6.in'))
+test.must_not_exist('f7.out')
+test.must_not_exist('f8.out')
+test.must_not_exist('f9.out')
+test.must_not_exist('f9.out-Copy')
+
+test.run()
+
+test.must_match('f1.out', "f1.in\n")
+test.must_match(['d2.out', 'file'], "d2.in/file\n")
+test.must_match(['d3.out', 'f3.in'], "f3.in\n")
+test.must_match('f4.out', "f4.in\n")
+test.must_match(['d5.out', 'file'], "d5.in/file\n")
+test.must_match(['d6.out', 'f6.in'], "f6.in\n")
+test.must_match('f7.out', "f7.in\n")
+test.must_match('f8.out', "f8.in\n")
+test.must_match('f9.out', "f9.in\n")
+test.must_match('f9.out-Copy', "f9.in\n")
+
+test.pass_test()
diff --git a/test/Delete.py b/test/Delete.py
new file mode 100644
index 0000000..ece9aa8
--- /dev/null
+++ b/test/Delete.py
@@ -0,0 +1,121 @@
+#!/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__"
+
+"""
+Verify that the Delete() Action works.
+"""
+
+import os.path
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+Execute(Delete('f1'))
+Execute(Delete('d2'))
+def cat(env, source, target):
+ target = str(target[0])
+ source = map(str, source)
+ f = open(target, "wb")
+ for src in source:
+ f.write(open(src, "rb").read())
+ f.close()
+Cat = Action(cat)
+env = Environment()
+env.Command('f3.out', 'f3.in', [Cat, Delete("f4"), Delete("d5")])
+env = Environment(FILE='f6', DIR='d7')
+env.Command('f8.out', 'f8.in', [Delete("$FILE"), Delete("$DIR"), Cat])
+env.Command('f9.out', 'f9.in', [Cat,
+ Delete("Delete-$SOURCE"),
+ Delete("$TARGET-Delete")])
+""")
+
+test.write('f1', "f1\n")
+test.subdir('d2')
+test.write(['d2', 'file'], "d2/file\n")
+test.write('f3.in', "f3.in\n")
+test.write('f4', "f4\n")
+test.subdir('d5')
+test.write(['d5', 'file'], "d5/file\n")
+test.write('f6', "f6\n")
+test.subdir('d7')
+test.write(['d7', 'file'], "d7/file\n")
+test.write('f8.in', "f8.in\n")
+test.write('f9.in', "f9.in\n")
+test.write('Delete-f9.in', "Delete-f9.in\n")
+test.write('f9.out-Delete', "f9.out-Delete\n")
+
+expect = test.wrap_stdout(read_str = """\
+Delete("f1")
+Delete("d2")
+""",
+ build_str = """\
+cat("f3.out", "f3.in")
+Delete("f4")
+Delete("d5")
+Delete("f6")
+Delete("d7")
+cat("f8.out", "f8.in")
+cat("f9.out", "f9.in")
+Delete("Delete-f9.in")
+Delete("f9.out-Delete")
+""")
+test.run(options = '-n', arguments = '.', stdout = expect)
+
+test.must_exist('f1')
+test.must_exist('d2')
+test.must_exist(os.path.join('d2', 'file'))
+test.must_not_exist('f3.out')
+test.must_exist('f4')
+test.must_exist('d5')
+test.must_exist(os.path.join('d5', 'file'))
+test.must_exist('f6')
+test.must_exist('d7')
+test.must_exist(os.path.join('d7', 'file'))
+test.must_not_exist('f8.out')
+test.must_not_exist('f9.out')
+test.must_exist('Delete-f9.in')
+test.must_exist('f9.out-Delete')
+
+test.run()
+
+test.must_not_exist('f1')
+test.must_not_exist('d2')
+test.must_not_exist(os.path.join('d2', 'file'))
+test.must_match('f3.out', "f3.in\n")
+test.must_not_exist('f4')
+test.must_not_exist('d5')
+test.must_not_exist(os.path.join('d5', 'file'))
+test.must_not_exist('f6')
+test.must_not_exist('d7')
+test.must_not_exist(os.path.join('d7', 'file'))
+test.must_match('f8.out', "f8.in\n")
+test.must_match('f9.out', "f9.in\n")
+test.must_not_exist('Delete-f9.in')
+test.must_not_exist('f9.out-Delete')
+
+test.pass_test()
diff --git a/test/Mkdir.py b/test/Mkdir.py
new file mode 100644
index 0000000..e0ac3fd
--- /dev/null
+++ b/test/Mkdir.py
@@ -0,0 +1,97 @@
+#!/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__"
+
+"""
+Verify that the Mkdir() Action works.
+"""
+
+import os.path
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+Execute(Mkdir('d1'))
+def cat(env, source, target):
+ target = str(target[0])
+ source = map(str, source)
+ f = open(target, "wb")
+ for src in source:
+ f.write(open(src, "rb").read())
+ f.close()
+Cat = Action(cat)
+env = Environment()
+env.Command('f2.out', 'f2.in', [Cat, Mkdir("d3")])
+env = Environment(DIR = 'd4')
+env.Command('f5.out', 'f5.in', [Mkdir("$DIR"), Cat])
+env.Command('f6.out', 'f6.in', [Cat,
+ Mkdir("Mkdir-$SOURCE"),
+ Mkdir("$TARGET-Mkdir")])
+""")
+
+test.write('f2.in', "f2.in\n")
+test.write('f5.in', "f5.in\n")
+test.write('f6.in', "f6.in\n")
+
+expect = test.wrap_stdout(read_str = 'Mkdir("d1")\n',
+ build_str = """\
+cat("f2.out", "f2.in")
+Mkdir("d3")
+Mkdir("d4")
+cat("f5.out", "f5.in")
+cat("f6.out", "f6.in")
+Mkdir("Mkdir-f6.in")
+Mkdir("f6.out-Mkdir")
+""")
+test.run(options = '-n', arguments = '.', stdout = expect)
+
+test.must_not_exist('d1')
+test.must_not_exist('f2.out')
+test.must_not_exist('d3')
+test.must_not_exist('d4')
+test.must_not_exist('f5.out')
+test.must_not_exist('f6.out')
+test.must_not_exist('Mkdir-f6.in')
+test.must_not_exist('f6.out-Mkdir')
+
+test.run()
+
+test.must_exist('d1')
+test.must_match('f2.out', "f2.in\n")
+test.must_exist('d3')
+test.must_exist('d4')
+test.must_match('f5.out', "f5.in\n")
+test.must_exist('f6.out')
+test.must_exist('Mkdir-f6.in')
+test.must_exist('f6.out-Mkdir')
+
+test.write(['d1', 'file'], "d1/file\n")
+test.write(['d3', 'file'], "d3/file\n")
+test.write(['Mkdir-f6.in', 'file'], "Mkdir-f6.in/file\n")
+test.write(['f6.out-Mkdir', 'file'], "f6.out-Mkdir/file\n")
+
+test.pass_test()
diff --git a/test/Move.py b/test/Move.py
new file mode 100644
index 0000000..a1d9772
--- /dev/null
+++ b/test/Move.py
@@ -0,0 +1,90 @@
+#!/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__"
+
+"""
+Verify that the Move() Action works.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+Execute(Move('f1.out', 'f1.in'))
+def cat(env, source, target):
+ target = str(target[0])
+ source = map(str, source)
+ f = open(target, "wb")
+ for src in source:
+ f.write(open(src, "rb").read())
+ f.close()
+Cat = Action(cat)
+env = Environment()
+env.Command('f2.out', 'f2.in', [Cat, Move("f3.out", "f3.in")])
+env = Environment(OUT = 'f4.out', IN = 'f4.in')
+env.Command('f5.out', 'f5.in', [Move("$OUT", "$IN"), Cat])
+env.Command('f6.out', 'f6.in', [Cat, Move("Move-$TARGET", "$SOURCE-Move")])
+""")
+
+test.write('f1.in', "f1.in\n")
+test.write('f2.in', "f2.in\n")
+test.write('f3.in', "f3.in\n")
+test.write('f4.in', "f4.in\n")
+test.write('f5.in', "f5.in\n")
+test.write('f6.in', "f6.in\n")
+test.write('f6.in-Move', "f6.in-Move\n")
+
+expect = test.wrap_stdout(read_str = 'Move("f1.out", "f1.in")\n',
+ build_str = """\
+cat("f2.out", "f2.in")
+Move("f3.out", "f3.in")
+Move("f4.out", "f4.in")
+cat("f5.out", "f5.in")
+cat("f6.out", "f6.in")
+Move("Move-f6.out", "f6.in-Move")
+""")
+test.run(options = '-n', arguments = '.', stdout = expect)
+
+test.must_not_exist('f1.out')
+test.must_not_exist('f2.out')
+test.must_not_exist('f3.out')
+test.must_not_exist('f4.out')
+test.must_not_exist('f5.out')
+test.must_not_exist('f6.out')
+test.must_not_exist('Move-f6.out')
+
+test.run()
+
+test.must_match('f1.out', "f1.in\n")
+test.must_match('f2.out', "f2.in\n")
+test.must_not_exist('f3.in')
+test.must_match('f3.out', "f3.in\n")
+test.must_match('f4.out', "f4.in\n")
+test.must_match('f5.out', "f5.in\n")
+test.must_match('f6.out', "f6.in\n")
+test.must_match('Move-f6.out', "f6.in-Move\n")
+
+test.pass_test()
diff --git a/test/Touch.py b/test/Touch.py
new file mode 100644
index 0000000..7a3ca19
--- /dev/null
+++ b/test/Touch.py
@@ -0,0 +1,101 @@
+#!/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__"
+
+"""
+Verify that the Touch() Action works.
+"""
+
+import os.path
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+Execute(Touch('f1'))
+def cat(env, source, target):
+ target = str(target[0])
+ source = map(str, source)
+ f = open(target, "wb")
+ for src in source:
+ f.write(open(src, "rb").read())
+ f.close()
+Cat = Action(cat)
+env = Environment()
+env.Command('f2.out', 'f2.in', [Cat, Touch("f3")])
+env = Environment(FILE='f4')
+env.Command('f5.out', 'f5.in', [Touch("$FILE"), Cat])
+env.Command('f6.out', 'f6.in', [Cat,
+ Touch("Touch-$SOURCE"),
+ Touch("$TARGET-Touch")])
+""")
+
+test.write('f1', "f1\n")
+test.write('f2.in', "f2.in\n")
+test.write('f5.in', "f5.in\n")
+test.write('f6.in', "f6.in\n")
+
+oldtime = os.path.getmtime(test.workpath('f1'))
+
+expect = test.wrap_stdout(read_str = 'Touch("f1")\n',
+ build_str = """\
+cat("f2.out", "f2.in")
+Touch("f3")
+Touch("f4")
+cat("f5.out", "f5.in")
+cat("f6.out", "f6.in")
+Touch("Touch-f6.in")
+Touch("f6.out-Touch")
+""")
+test.run(options = '-n', arguments = '.', stdout = expect)
+
+test.sleep(2)
+
+newtime = os.path.getmtime(test.workpath('f1'))
+test.fail_test(oldtime != newtime)
+
+test.must_not_exist(test.workpath('f2.out'))
+test.must_not_exist(test.workpath('f3'))
+test.must_not_exist(test.workpath('f4'))
+test.must_not_exist(test.workpath('f5.out'))
+test.must_not_exist(test.workpath('f6.out'))
+test.must_not_exist(test.workpath('Touch-f6.in'))
+test.must_not_exist(test.workpath('f6.out-Touch'))
+
+test.run()
+
+newtime = os.path.getmtime(test.workpath('f1'))
+test.fail_test(oldtime == newtime)
+
+test.must_match('f2.out', "f2.in\n")
+test.must_exist(test.workpath('f3'))
+test.must_exist(test.workpath('f4'))
+test.must_match('f5.out', "f5.in\n")
+test.must_match('f6.out', "f6.in\n")
+test.must_exist(test.workpath('Touch-f6.in'))
+test.must_exist(test.workpath('f6.out-Touch'))
+
+test.pass_test()