print "Python %d.%d or greater required, but you have Python %s" %(major,minor,v)
sys.exit(2)
+def GetJobs():
+ return SCons.Script.get_num_jobs(SCons.Script.options)
+
+def SetJobs(num):
+ try:
+ tmp = int(num)
+ if tmp < 1:
+ raise ValueError
+ SCons.Script.num_jobs = tmp
+ except ValueError, x:
+ raise SCons.Errors.UserError, "A positive integer is required: %s"%repr(num)
+
def BuildDefaultGlobals():
"""
Create a dictionary containing all the default globals for
globals['FindFile'] = FindFile
globals['GetBuildPath'] = GetBuildPath
globals['GetCommandHandler'] = SCons.Action.GetCommandHandler
+ globals['GetJobs'] = GetJobs
globals['GetLaunchDir'] = GetLaunchDir
globals['Help'] = Help
globals['Import'] = Import
globals['SetBuildSignatureType'] = SetBuildSignatureType
globals['SetCommandHandler'] = SCons.Action.SetCommandHandler
globals['SetContentSignatureType'] = SetContentSignatureType
+ globals['SetJobs'] = SetJobs
globals['SharedLibrary'] = SCons.Defaults.SharedLibrary
globals['SharedObject'] = SCons.Defaults.SharedObject
globals['Split'] = SCons.Util.Split
profiling = 0
repositories = []
sig_module = None
+num_jobs = 1 # this is modifed by SConscript.SetJobs()
def print_it(text):
print text
# utility functions
+def get_num_jobs(options):
+ if hasattr(options, 'num_jobs'):
+ return options.num_jobs
+ else:
+ return num_jobs
+
def get_all_children(node): return node.all_children(None)
def get_derived_children(node):
opt, arglist = OptionParser.parse_args(self, args, values)
if opt.implicit_deps_changed or opt.implicit_deps_unchanged:
opt.implicit_cache = 1
- if not hasattr(opt, "num_jobs"):
- setattr(opt, "num_jobs", 1)
return opt, arglist
# it's OK if there's no SCONSFLAGS
pass
parser = OptParser()
+ global options
options, args = parser.parse_args(all_args)
if options.help_msg:
display("scons: Building targets ...")
taskmaster = SCons.Taskmaster.Taskmaster(nodes, task_class, calc)
- jobs = SCons.Job.Jobs(options.num_jobs, taskmaster)
+ jobs = SCons.Job.Jobs(get_num_jobs(options), taskmaster)
try:
jobs.run()
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
+"""
+This tests the -j command line option, and the SetJobs() and GetJobs()
+SConscript functions.
+"""
+
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import string
return start2, finish1
-start2, finish1 = RunTest('-j 2 f1 f2', "first")
-
+# Test 2 parallel jobs.
# fail if the second file was not started
-# before the first one was finished
+# before the first one was finished.
+start2, finish1 = RunTest('-j 2 f1 f2', "first")
test.fail_test(not (start2 < finish1))
-s2, f1 = RunTest('-j 2 f1 f2', "first")
-
# re-run the test with the same input, fail if we don't
# get back the same times, which would indicate that
# SCons rebuilt the files even though nothing changed
+s2, f1 = RunTest('-j 2 f1 f2', "first")
test.fail_test(start2 != s2)
test.fail_test(finish1 != f1)
+# Test a single serial job.
+# fail if the second file was started
+# before the first one was finished
start2, finish1 = RunTest('f1 f2', "second")
+test.fail_test(start2 < finish1)
+
+# Make sure that a parallel build using a list builder
+# succeedes.
+test.run(arguments='-j 2 out')
+
+# Test SetJobs() with no -j:
+test.write('SConstruct', """
+MyBuild = Builder(action = r'%s build.py $TARGETS')
+env = Environment(BUILDERS = { 'MyBuild' : MyBuild })
+env.MyBuild(target = 'f1', source = 'f1.in')
+env.MyBuild(target = 'f2', source = 'f2.in')
+
+def copyn(env, target, source):
+ import shutil
+ import time
+ time.sleep(1)
+ for t in target:
+ shutil.copy(str(source[0]), str(t))
+
+t = env.Command(target=['foo/foo1.out', 'foo/foo2.out'], source='foo/foo.in', action=copyn)
+env.Install('out', t)
+
+assert GetJobs() == 1
+SetJobs(2)
+assert GetJobs() == 2
+""" % python)
+
+# This should be a prallel build because the SConscript sets jobs to 2.
+# fail if the second file was not started
+# before the first one was finished
+start2, finish1 = RunTest('f1 f2', "third")
+test.fail_test(not (start2 < finish1))
+
+# Test SetJobs() with -j:
+test.write('SConstruct', """
+MyBuild = Builder(action = r'%s build.py $TARGETS')
+env = Environment(BUILDERS = { 'MyBuild' : MyBuild })
+env.MyBuild(target = 'f1', source = 'f1.in')
+env.MyBuild(target = 'f2', source = 'f2.in')
+def copyn(env, target, source):
+ import shutil
+ import time
+ time.sleep(1)
+ for t in target:
+ shutil.copy(str(source[0]), str(t))
+
+t = env.Command(target=['foo/foo1.out', 'foo/foo2.out'], source='foo/foo.in', action=copyn)
+env.Install('out', t)
+
+assert GetJobs() == 1
+SetJobs(2)
+assert GetJobs() == 1
+""" % python)
+
+# This should be a serial build since -j 1 overrides the call to SetJobs().
# fail if the second file was started
# before the first one was finished
+start2, finish1 = RunTest('-j 1 f1 f2', "fourth")
test.fail_test(start2 < finish1)
-test.run(arguments='-j 2 out')
test.pass_test()