From 1e8177ee178b131afa86d874b062a8ae3fae0cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Tue, 10 Feb 2009 18:11:56 +0000 Subject: scons: Use parallel builds by default. --- scons/generic.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'scons/generic.py') diff --git a/scons/generic.py b/scons/generic.py index 05f7356b76..2323196673 100644 --- a/scons/generic.py +++ b/scons/generic.py @@ -206,6 +206,25 @@ _bool_map = { } +def num_jobs(): + try: + return int(os.environ['NUMBER_OF_PROCESSORS']) + except (ValueError, KeyError): + pass + + try: + return os.sysconf('SC_NPROCESSORS_ONLN') + except (ValueError, OSError, AttributeError): + pass + + try: + return int(os.popen2("sysctl -n hw.ncpu")[1].read()) + except ValueError: + pass + + return 1 + + def generate(env): """Common environment generation code""" @@ -266,6 +285,10 @@ def generate(env): # different scons versions building the same source file env.SConsignFile(os.path.join(env['build'], '.sconsign')) + # Parallel build + if env.GetOption('num_jobs') <= 1: + env.SetOption('num_jobs', num_jobs()) + # Summary print print ' platform=%s' % env['platform'] @@ -274,6 +297,7 @@ def generate(env): print ' debug=%s' % ['no', 'yes'][env['debug']] print ' profile=%s' % ['no', 'yes'][env['profile']] print ' build=%s' % env['build'] + print ' %s jobs' % env.GetOption('num_jobs') print # Load tool chain -- cgit v1.2.3