add the -j argument
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 29 Jul 2001 12:16:01 +0000 (12:16 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 29 Jul 2001 12:16:01 +0000 (12:16 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@11 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/scons.py

index c700f779ff5deb8f1c05b0fb129f2e2a36f81ef6..70d336a5dbd9c1142927398c8015e85825652704 100644 (file)
@@ -5,13 +5,42 @@ import os.path
 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')
 
@@ -26,13 +55,16 @@ if not Scripts:
 #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()
 
@@ -49,6 +81,45 @@ while Scripts:
 
 
 
-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()
+
+