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 A6F53138A1A for ; Sat, 17 Jan 2015 10:45:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DC115E0863; Sat, 17 Jan 2015 10:45:43 +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 60A90E0855 for ; Sat, 17 Jan 2015 10:45:43 +0000 (UTC) Received: from pomiot.lan (mgorny-1-pt.tunnel.tserv28.waw1.ipv6.he.net [IPv6:2001:470:70:353::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id 833AF3407A9; Sat, 17 Jan 2015 10:45:41 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-portage-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-portage-dev] [PATCH] Default MAKEOPTS to -j(ncpus+1) when unset Date: Sat, 17 Jan 2015 11:45:35 +0100 Message-Id: <1421491535-32166-1-git-send-email-mgorny@gentoo.org> X-Mailer: git-send-email 2.2.1 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Archives-Salt: 0d98ba7e-a7c5-4b3d-a3eb-73c32e2d046a X-Archives-Hash: f3efa61619596ad445d2468974d25cd0 Default MAKEOPTS job number to (number of CPUs + 1) when it is not provided in the ebuild environment. Suggested-By: Daniel Robbins --- pym/portage/package/ebuild/doebuild.py | 8 +++++++- pym/portage/util/cpuinfo.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 pym/portage/util/cpuinfo.py 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..157e2e7 --- /dev/null +++ b/pym/portage/util/cpuinfo.py @@ -0,0 +1,19 @@ +# Copyright 2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +__all__ = ['get_cpu_count'] + +import multiprocessing + + +def get_cpu_count(): + """ + Try to obtain the number of CPUs available. + + @return: Number of CPUs or None if unable to obtain. + """ + + try: + return multiprocessing.cpu_count() + except NotImplementedError: + return None -- 2.2.1