From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 90B8F138A1A for ; Sun, 18 Jan 2015 18:04:37 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E0886E08F8; Sun, 18 Jan 2015 18:04:35 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 4183BE08F1 for ; Sun, 18 Jan 2015 18:04:35 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 73A6D3406A1 for ; Sun, 18 Jan 2015 18:04:34 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 2E337FDBA for ; Sun, 18 Jan 2015 18:04:33 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <1421604264.5a1e6c9710becab384b684ad6ba55e025d63a60e.mgorny@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/package/ebuild/, pym/portage/util/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/package/ebuild/doebuild.py pym/portage/util/cpuinfo.py X-VCS-Directories: pym/portage/package/ebuild/ pym/portage/util/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 5a1e6c9710becab384b684ad6ba55e025d63a60e X-VCS-Branch: master Date: Sun, 18 Jan 2015 18:04:33 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: e15c8231-205a-4144-8aa6-f63dc2220490 X-Archives-Hash: 0b35efad68beea2385e54edf913b5840 commit: 5a1e6c9710becab384b684ad6ba55e025d63a60e Author: Michał Górny gentoo org> AuthorDate: Sat Jan 17 10:36:18 2015 +0000 Commit: Michał Górny gentoo org> CommitDate: Sun Jan 18 18:04:24 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=5a1e6c97 Default MAKEOPTS to -j(ncpus+1) when unset Default MAKEOPTS job number to (number of CPUs + 1) when it is not provided in the ebuild environment. Suggested-By: Daniel Robbins funtoo.org> --- pym/portage/package/ebuild/doebuild.py | 8 +++++++- pym/portage/util/cpuinfo.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py index bf97660..f43dddc 100644 --- a/pym/portage/package/ebuild/doebuild.py +++ b/pym/portage/package/ebuild/doebuild.py @@ -1,4 +1,4 @@ -# Copyright 2010-2013 Gentoo Foundation +# Copyright 2010-2015 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 from __future__ import unicode_literals @@ -66,6 +66,7 @@ from portage.package.ebuild.prepare_build_dirs import prepare_build_dirs from portage.util import apply_recursive_permissions, \ apply_secpass_permissions, noiselimit, normalize_path, \ writemsg, writemsg_stdout, write_atomic +from portage.util.cpuinfo import get_cpu_count from portage.util.lafilefixer import rewrite_lafile from portage.versions import _pkgsplit from _emerge.BinpkgEnvExtractor import BinpkgEnvExtractor @@ -463,6 +464,11 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None, mysettings["PATH"] = os.path.join(os.sep, eprefix_lstrip, "usr", libdir, "ccache", "bin") + ":" + mysettings["PATH"] + if 'MAKEOPTS' not in mysettings: + nproc = get_cpu_count() + if nproc: + mysettings['MAKEOPTS'] = '-j%d' % (nproc + 1) + if not eapi_exports_KV(eapi): # Discard KV for EAPIs that don't support it. Cached KV is restored # from the backupenv whenever config.reset() is called. diff --git a/pym/portage/util/cpuinfo.py b/pym/portage/util/cpuinfo.py new file mode 100644 index 0000000..669e707 --- /dev/null +++ b/pym/portage/util/cpuinfo.py @@ -0,0 +1,18 @@ +# Copyright 2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +__all__ = ['get_cpu_count'] + + +def get_cpu_count(): + """ + Try to obtain the number of CPUs available. + + @return: Number of CPUs or None if unable to obtain. + """ + + try: + import multiprocessing + return multiprocessing.cpu_count() + except (ImportError, NotImplementedError): + return None