Commits

Steven Knight  committed 0416d3a

add the -j argument

  • Participants
  • Parent commits c7c4a92

Comments (0)

Files changed (1)

File src/scons.py

 import string
 import sys
 
-opts, targets = getopt.getopt(sys.argv[1:], 'f:')
+def PrintUsage():
+    print "Usage: scons [OPTION]... TARGET..."
+    print "Build TARGET or multiple TARGET(s)"
+    print " "
+    print '  -f CONSCRIPT        execute CONSCRIPT instead of "SConstruct"'
+    print "  -j N                execute N parallel jobs"
+    print "  --help              print this message and exit"
+
+try:
+    opts, targets = getopt.getopt(sys.argv[1:], 'f:j:', ['help'])
+except getopt.GetoptError, x:
+    print x
+    PrintUsage()
+    sys.exit()
 
 Scripts = []
 
+num_jobs = 1
 for o, a in opts:
     if o == '-f': Scripts.append(a)
 
+    if o == '-j':
+        try:
+            num_jobs = int(a)
+        except:
+            PrintUsage()
+            sys.exit(1)
+
+        if num_jobs <= 0:
+            PrintUsage()
+            sys.exit(1)
+            
+    if o == '--help':
+        PrintUsage()
+        sys.exit(0)
+    
 if not Scripts:
     Scripts.append('SConstruct')
 
 #for dir in sys.path:
 #    scons = os.path.join(dir, 'scons')
 #    if os.path.isdir(scons):
-#	dirlist = dirlist + [scons]
+#     dirlist = dirlist + [scons]
 #    dirlist = dirlist + [dir]
 #
 #sys.path = dirlist
 
+
 from scons.Node.FS import init, Dir, File, lookup
 from scons.Environment import Environment
+import scons.Job
+from scons.Builder import Builder
 
 init()
 
 
 
 
-for path in targets:
-	target = lookup(File, path)
-	target.build()
+class Task:
+    "this is here only until the build engine is implemented"
+
+    def __init__(self, target):
+        self.target = target
+
+    def execute(self):
+        self.target.build()
+
+
+
+class Taskmaster:
+    "this is here only until the build engine is implemented"
+
+    def __init__(self, targets):
+        self.targets = targets
+        self.num_iterated = 0
+
+
+    def next_task(self):
+        if self.num_iterated == len(self.targets):
+            return None
+        else:
+            current = self.num_iterated
+            self.num_iterated = self.num_iterated + 1
+            return Task(self.targets[current])
+
+    def is_blocked(self):
+        return 0
+
+    def executed(self, task):
+        pass
+
+
+
+taskmaster = Taskmaster(map(lambda x: lookup(File, x), targets))
+
+jobs = scons.Job.Jobs(num_jobs, taskmaster)
+jobs.start()
+jobs.wait()
+
+