From 9fd13821e9376d98633ec8ae8c0ad0a676eae02a Mon Sep 17 00:00:00 2001 From: stevenknight Date: Tue, 9 Oct 2001 12:48:14 +0000 Subject: [PATCH] Add support for -c (clean targets). git-svn-id: http://scons.tigris.org/svn/scons/trunk@90 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/script/scons.py | 30 ++++++++++++++++++++++-------- test/option-c.py | 20 ++++++++++---------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/script/scons.py b/src/script/scons.py index da907ade..cd81d493 100644 --- a/src/script/scons.py +++ b/src/script/scons.py @@ -53,12 +53,8 @@ from SCons.Builder import Builder # # Task control. # -class Task: +class BuildTask(SCons.Taskmaster.Task): """An SCons build task.""" - - def __init__(self, target): - self.target = target - def execute(self): try: self.target.build() @@ -66,6 +62,13 @@ class Task: sys.stderr.write("scons: *** [%s] Error %d\n" % (e.node, e.stat)) raise +class CleanTask(SCons.Taskmaster.Task): + """An SCons clean task.""" + def execute(self): + if hasattr(self.target, "builder"): + os.unlink(self.target.path) + print "Removed " + self.target.path + class ScriptTaskmaster(SCons.Taskmaster.Taskmaster): """Controlling logic for tasks. @@ -92,6 +95,8 @@ include_dirs = [] help_option = None num_jobs = 1 scripts = [] +task_class = BuildTask # default action is to build targets +current_func = None # utility functions @@ -299,7 +304,12 @@ def options_init(): short = 'bmSt', long = ['no-keep-going', 'stop', 'touch'], help = "Ignored for compatibility.") - Option(func = opt_not_yet, + def opt_c(opt, arg): + global task_class, current_func + task_class = CleanTask + current_func = SCons.Taskmaster.current + + Option(func = opt_c, short = 'c', long = ['clean', 'remove'], help = "Remove specified targets and dependencies.") @@ -517,7 +527,7 @@ def UsageString(): def main(): - global scripts, help_option, num_jobs + global scripts, help_option, num_jobs, task_class, current_func targets = [] @@ -607,9 +617,13 @@ def main(): targets = default_targets nodes = map(lambda x: SCons.Node.FS.default_fs.File(x), targets) + calc = SCons.Sig.Calculator(SCons.Sig.MD5) - taskmaster = ScriptTaskmaster(nodes, Task, calc.current) + if not current_func: + current_func = calc.current + + taskmaster = ScriptTaskmaster(nodes, task_class, current_func) jobs = SCons.Job.Jobs(num_jobs, taskmaster) jobs.start() diff --git a/test/option-c.py b/test/option-c.py index b7f6c17f..d403e043 100644 --- a/test/option-c.py +++ b/test/option-c.py @@ -29,8 +29,6 @@ import TestSCons test = TestSCons.TestSCons() -test.pass_test() #XXX Short-circuit until this is implemented. - test.write('build.py', r""" import sys contents = open(sys.argv[2], 'r').read() @@ -40,7 +38,7 @@ file.close() """) test.write('SConstruct', """ -B = Builder(name = 'B', action = "python ../build.py %(target)s %(source)s") +B = Builder(name = 'B', action = "python build.py %(target)s %(source)s") env = Environment(BUILDERS = [B]) env.B(target = 'foo1.out', source = 'foo1.in') env.B(target = 'foo2.out', source = 'foo2.in') @@ -59,19 +57,19 @@ test.fail_test(test.read(test.workpath('foo1.out')) != "foo1.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.run(arguments = '-c foo1.out') +test.run(arguments = '-c foo1.out', stdout = "Removed foo1.out\n") test.fail_test(os.path.exists(test.workpath('foo1.out'))) test.fail_test(not os.path.exists(test.workpath('foo2.out'))) test.fail_test(not os.path.exists(test.workpath('foo3.out'))) -test.run(arguments = '--clean foo2.out') +test.run(arguments = '--clean foo2.out', stdout = "Removed foo2.out\n") test.fail_test(os.path.exists(test.workpath('foo1.out'))) test.fail_test(os.path.exists(test.workpath('foo2.out'))) test.fail_test(not os.path.exists(test.workpath('foo3.out'))) -test.run(arguments = '--remove foo3.out') +test.run(arguments = '--remove foo3.out', stdout = "Removed foo3.out\n") test.fail_test(os.path.exists(test.workpath('foo1.out'))) test.fail_test(os.path.exists(test.workpath('foo2.out'))) @@ -79,11 +77,13 @@ test.fail_test(os.path.exists(test.workpath('foo3.out'))) test.run(arguments = 'foo1.out foo2.out foo3.out') -test.run(program = test.workpath('foo1.out'), stdout = "foo1.in\n") -test.run(program = test.workpath('foo2.out'), stdout = "foo2.in\n") -test.run(program = test.workpath('foo3.out'), stdout = "foo3.in\n") +test.fail_test(test.read(test.workpath('foo1.out')) != "foo1.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.run(arguments = '-c .') +#XXXtest.run(arguments = '-c .', +test.run(arguments = '-c foo1.out foo2.out foo3.out', + stdout = "Removed foo1.out\nRemoved foo2.out\nRemoved foo3.out\n") test.fail_test(os.path.exists(test.workpath('foo1.out'))) test.fail_test(os.path.exists(test.workpath('foo2.out'))) -- 2.26.2