1. Rob Managan
  2. SCons_biblatex2.2

Commits

Steven Knight  committed 0b3ef7c

Add support for -c (clean targets).

  • Participants
  • Parent commits 8bf0437
  • Branches default

Comments (0)

Files changed (2)

File src/script/scons.py

View file
 #
 # 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()
             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.
     
 help_option = None
 num_jobs = 1
 scripts = []
+task_class = BuildTask	# default action is to build targets
+current_func = None
 
 # utility functions
 
 	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.")
 
 
 
 def main():
-    global scripts, help_option, num_jobs
+    global scripts, help_option, num_jobs, task_class, current_func
 
     targets = []
 
 	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()

File test/option-c.py

View file
 
 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()
 """)
 
 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')
 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')))
 
 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')))