commit: 3785489c07bd653e021c8e176ab7b6e4d463f55d Author: Florian Schmaus <flow <AT> gentoo <DOT> org> AuthorDate: Sat Dec 20 12:52:11 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Sat Dec 20 21:57:14 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3785489c
Limit emerge jobs to processor count when "--jobs 0" is used Akin to similar options in other tools, e.g., "xz -T 0", special case the '0' argument of --jobs to limit the number of emerge jobs to the processor count. This improves configuration portability across heterogeneous systems, aiding configuration management. Signed-off-by: Florian Schmaus <flow <AT> gentoo.org> Part-of: https://github.com/gentoo/portage/pull/1531 Closes: https://github.com/gentoo/portage/pull/1531 Signed-off-by: Sam James <sam <AT> gentoo.org> lib/_emerge/main.py | 12 +++++++----- man/emerge.1 | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/_emerge/main.py b/lib/_emerge/main.py index b495e5afd5..12cfdd1378 100644 --- a/lib/_emerge/main.py +++ b/lib/_emerge/main.py @@ -1025,12 +1025,14 @@ def parse_opts(tmpcmdline, silent=False): try: jobs = int(myoptions.jobs) except ValueError: - jobs = -1 + jobs = None - if jobs is not True and jobs < 1: - jobs = None - if not silent: - parser.error(f"Invalid --jobs parameter: '{myoptions.jobs}'\n") + if jobs is None and not silent: + parser.error(f"Invalid --jobs parameter: '{myoptions.jobs}'\n") + elif jobs == 0: + from portage.util.cpuinfo import get_cpu_count + + jobs = get_cpu_count() myoptions.jobs = jobs diff --git a/man/emerge.1 b/man/emerge.1 index 8215c82fca..c3d0c22ce6 100644 --- a/man/emerge.1 +++ b/man/emerge.1 @@ -684,7 +684,8 @@ in the \fBmake.conf\fR(5) man page. .BR \-j\ [JOBS] ", " \-\-jobs[=JOBS] Specifies the number of packages to build simultaneously. If this option is given without an argument, emerge will not limit the number of jobs that can -run simultaneously. Also see the related \fB\-\-load\-average\fR option. +run simultaneously. If 0 is given as argument, emerge will limit the jobs to +the number of processors. Also see the related \fB\-\-load\-average\fR option. Similarly to the \-\-quiet\-build option, the \-\-jobs option causes all build output to be redirected to logs. Note that interactive packages currently force a setting
