Anonymous avatar Anonymous committed fbc3c53

Pass in the signature Calculator to the Taskmaster.

Comments (0)

Files changed (2)

src/script/scons.py

 class Taskmaster:
     "XXX: this is here only until the build engine is implemented"
 
-    def __init__(self, targets):
+    def __init__(self, targets, calc):
         self.targets = targets
+        self.calc = calc
         self.num_iterated = 0
 
 
     def next_task(self):
-        if self.num_iterated == len(self.targets):
-            return None
-        else:
-            current = self.num_iterated
+        while self.num_iterated < len(self.targets):
+            t = self.targets[self.num_iterated]
             self.num_iterated = self.num_iterated + 1
-            return Task(self.targets[current])
+            if self.calc.current(t):
+                print 'scons: "%s" is up to date.' % t
+            else:
+                return Task(t)
+        return None
 
     def is_blocked(self):
         return 0
     if not targets:
 	targets = default_targets
 
-    # XXX Right now, this next block prints all "up to date" messages
-    # first, and then goes through and builds the other nodes:
-    #
-    #		$ scons aaa bbb ccc ddd
-    #		scons: "aaa" is up to date.
-    #		scons: "ccc" is up to date.
-    #		cc -o bbb bbb.c
-    #		cc -o ddd ddd.c
-    #
-    # When we get the real Task and Taskmaster classes, this should
-    # be changed to interact with the engine to deal with targets in
-    # the same order as specified:
-    #
-    #		$ scons aaa bbb ccc ddd
-    #		scons: "aaa" is up to date.
-    #		cc -o bbb bbb.c
-    #		scons: "ccc" is up to date.
-    #		cc -o ddd ddd.c
-    #
+    nodes = map(lambda x: SCons.Node.FS.default_fs.File(x), targets)
     calc = SCons.Sig.Calculator(SCons.Sig.MD5)
-    nodes = []
-    for t in map(lambda x: SCons.Node.FS.default_fs.File(x), targets):
-	if calc.current(t):
-	    print 'scons: "%s" is up to date.' % t.path
-	else:
-	    nodes.append(t)
-    
-    taskmaster = Taskmaster(nodes)
+
+    taskmaster = Taskmaster(nodes, calc)
 
     jobs = SCons.Job.Jobs(num_jobs, taskmaster)
     jobs.start()

test/up-to-date.py

+#!/usr/bin/env python
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import TestSCons
+import os.path
+import string
+import sys
+
+test = TestSCons.TestSCons()
+
+test.write('build.py', r"""
+import sys
+contents = open(sys.argv[2], 'r').read()
+file = open(sys.argv[1], 'w')
+file.write(contents)
+file.close()
+""")
+
+test.write('SConstruct', """
+B = Builder(name = "B", action = "python build.py %(target)s %(source)s")
+env = Environment(BUILDERS = [B])
+env.B(target = 'f1.out', source = 'f1.in')
+env.B(target = 'f2.out', source = 'f2.in')
+env.B(target = 'f3.out', source = 'f3.in')
+env.B(target = 'f4.out', source = 'f4.in')
+""")
+
+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.run(arguments = 'f1.out f3.out')
+
+test.run(arguments = 'f1.out f2.out f3.out f4.out', stdout =
+"""scons: "f1.out" is up to date.
+python build.py f2.out f2.in
+scons: "f3.out" is up to date.
+python build.py f4.out f4.in
+""")
+
+test.pass_test()
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.