diff --git a/gclient.py b/gclient.py index cef9f1afc..9065952bd 100644 --- a/gclient.py +++ b/gclient.py @@ -1541,11 +1541,11 @@ def Parser(): if platform.machine().startswith('arm'): jobs = 1 else: - jobs = 8 + jobs = max(8, gclient_utils.NumLocalCpus()) gclientfile_default = os.environ.get('GCLIENT_FILE', '.gclient') parser.add_option('-j', '--jobs', default=jobs, type='int', help='Specify how many SCM commands can run in parallel; ' - 'default=%default') + 'defaults to number of cpu cores (%default)') parser.add_option('-v', '--verbose', action='count', default=0, help='Produces additional output for diagnostics. Can be ' 'used up to three times for more logging info.') diff --git a/gclient_utils.py b/gclient_utils.py index ab45d28cc..78fa7222a 100644 --- a/gclient_utils.py +++ b/gclient_utils.py @@ -769,3 +769,17 @@ def ParseCodereviewSettingsContent(content): fix_url('CODE_REVIEW_SERVER') fix_url('VIEW_VC') return keyvals + + +def NumLocalCpus(): + """Returns the number of processors. + + Python on OSX 10.6 raises a NotImplementedError exception. + """ + try: + import multiprocessing + return multiprocessing.cpu_count() + except: # pylint: disable=W0702 + # Mac OS 10.6 only + # pylint: disable=E1101 + return int(os.sysconf('SC_NPROCESSORS_ONLN')) diff --git a/tests/gclient_utils_test.py b/tests/gclient_utils_test.py index 8dc69090f..d47fac992 100755 --- a/tests/gclient_utils_test.py +++ b/tests/gclient_utils_test.py @@ -33,7 +33,7 @@ class GclientUtilsUnittest(GclientUtilBase): 'FileWrite', 'FindFileUpwards', 'FindGclientRoot', 'GetGClientRootAndEntries', 'GetEditor', 'IsDateRevision', 'MakeDateRevision', 'MakeFileAutoFlush', 'MakeFileAnnotated', - 'PathDifference', 'ParseCodereviewSettingsContent', + 'PathDifference', 'ParseCodereviewSettingsContent', 'NumLocalCpus', 'PrintableObject', 'RemoveDirectory', 'RunEditor', 'SplitUrlRevision', 'SyntaxErrorToError', 'UpgradeToHttps', 'Wrapper', 'WorkItem',