1 |
Default MAKEOPTS job number to (number of CPUs + 1) when it is not |
2 |
provided in the ebuild environment. |
3 |
|
4 |
Suggested-By: Daniel Robbins <drobbins@××××××.org> |
5 |
--- |
6 |
pym/portage/package/ebuild/doebuild.py | 8 +++++++- |
7 |
pym/portage/util/cpuinfo.py | 19 +++++++++++++++++++ |
8 |
2 files changed, 26 insertions(+), 1 deletion(-) |
9 |
create mode 100644 pym/portage/util/cpuinfo.py |
10 |
|
11 |
diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py |
12 |
index bf97660..f43dddc 100644 |
13 |
--- a/pym/portage/package/ebuild/doebuild.py |
14 |
+++ b/pym/portage/package/ebuild/doebuild.py |
15 |
@@ -1,4 +1,4 @@ |
16 |
-# Copyright 2010-2013 Gentoo Foundation |
17 |
+# Copyright 2010-2015 Gentoo Foundation |
18 |
# Distributed under the terms of the GNU General Public License v2 |
19 |
|
20 |
from __future__ import unicode_literals |
21 |
@@ -66,6 +66,7 @@ from portage.package.ebuild.prepare_build_dirs import prepare_build_dirs |
22 |
from portage.util import apply_recursive_permissions, \ |
23 |
apply_secpass_permissions, noiselimit, normalize_path, \ |
24 |
writemsg, writemsg_stdout, write_atomic |
25 |
+from portage.util.cpuinfo import get_cpu_count |
26 |
from portage.util.lafilefixer import rewrite_lafile |
27 |
from portage.versions import _pkgsplit |
28 |
from _emerge.BinpkgEnvExtractor import BinpkgEnvExtractor |
29 |
@@ -463,6 +464,11 @@ def doebuild_environment(myebuild, mydo, myroot=None, settings=None, |
30 |
mysettings["PATH"] = os.path.join(os.sep, eprefix_lstrip, |
31 |
"usr", libdir, "ccache", "bin") + ":" + mysettings["PATH"] |
32 |
|
33 |
+ if 'MAKEOPTS' not in mysettings: |
34 |
+ nproc = get_cpu_count() |
35 |
+ if nproc: |
36 |
+ mysettings['MAKEOPTS'] = '-j%d' % (nproc + 1) |
37 |
+ |
38 |
if not eapi_exports_KV(eapi): |
39 |
# Discard KV for EAPIs that don't support it. Cached KV is restored |
40 |
# from the backupenv whenever config.reset() is called. |
41 |
diff --git a/pym/portage/util/cpuinfo.py b/pym/portage/util/cpuinfo.py |
42 |
new file mode 100644 |
43 |
index 0000000..157e2e7 |
44 |
--- /dev/null |
45 |
+++ b/pym/portage/util/cpuinfo.py |
46 |
@@ -0,0 +1,19 @@ |
47 |
+# Copyright 2015 Gentoo Foundation |
48 |
+# Distributed under the terms of the GNU General Public License v2 |
49 |
+ |
50 |
+__all__ = ['get_cpu_count'] |
51 |
+ |
52 |
+import multiprocessing |
53 |
+ |
54 |
+ |
55 |
+def get_cpu_count(): |
56 |
+ """ |
57 |
+ Try to obtain the number of CPUs available. |
58 |
+ |
59 |
+ @return: Number of CPUs or None if unable to obtain. |
60 |
+ """ |
61 |
+ |
62 |
+ try: |
63 |
+ return multiprocessing.cpu_count() |
64 |
+ except NotImplementedError: |
65 |
+ return None |
66 |
-- |
67 |
2.2.1 |