Allow the MAKEFLAGS environment variable to pass through, in case a centralized GNU Make POSIX Jobserver is available. In order to prevent persistence of this variable in environment.bz2, exclude it when the __save_ebuild_env --exclude-init-phases argument is given.
Ultimately we may want to add support for portage to parse MAKEFLAGS and use it to allocate job tokens in various circumstances. For example, emerge could allocate a job token for each job started for emerge --jobs. This would remove a job token from the pool that is available to nested make calls, but is reasonable because nested make calls will execute jobs serially when no jobserver tokens remain. Bug: https://bugs.gentoo.org/692576 Signed-off-by: Zac Medico <zmed...@gentoo.org> --- [PATCH v2] documents MAKEFLAGS in make.conf.5 and disables an automatic MAKEOPTS setting if it would conflict with MAKEFLAGS. bin/save-ebuild-env.sh | 5 ++++- lib/portage/__init__.py | 3 ++- lib/portage/package/ebuild/_config/special_env_vars.py | 3 ++- lib/portage/package/ebuild/doebuild.py | 3 ++- man/make.conf.5 | 10 +++++++++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh index 3a2560aabf..6943e59b0b 100644 --- a/bin/save-ebuild-env.sh +++ b/bin/save-ebuild-env.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 1999-2021 Gentoo Authors +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @FUNCTION: __save_ebuild_env @@ -24,6 +24,9 @@ __save_ebuild_env() { unset PYTHONPATH fi fi + + # Discard stale GNU Make POSIX Jobserver flags. + unset MAKEFLAGS fi # misc variables inherited from the calling environment diff --git a/lib/portage/__init__.py b/lib/portage/__init__.py index 21bf993170..10c303477f 100644 --- a/lib/portage/__init__.py +++ b/lib/portage/__init__.py @@ -1,4 +1,4 @@ -# Copyright 1998-2023 Gentoo Authors +# Copyright 1998-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # pylint: disable=ungrouped-imports @@ -657,6 +657,7 @@ def create_trees( # environment to apply to the config that's associated # with ROOT != "/", so pass a nearly empty dict for the env parameter. env_sequence = ( + "MAKEFLAGS", "PATH", "PORTAGE_GRPNAME", "PORTAGE_REPOSITORIES", diff --git a/lib/portage/package/ebuild/_config/special_env_vars.py b/lib/portage/package/ebuild/_config/special_env_vars.py index 1a66192c96..55e5111ef0 100644 --- a/lib/portage/package/ebuild/_config/special_env_vars.py +++ b/lib/portage/package/ebuild/_config/special_env_vars.py @@ -1,4 +1,4 @@ -# Copyright 2010-2021 Gentoo Authors +# Copyright 2010-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 __all__ = ( @@ -112,6 +112,7 @@ environ_whitelist = frozenset( "FEATURES", "FILESDIR", "HOME", + "MAKEFLAGS", "MERGE_TYPE", "NOCOLOR", "NO_COLOR", diff --git a/lib/portage/package/ebuild/doebuild.py b/lib/portage/package/ebuild/doebuild.py index 403836b80b..bb888e7ae4 100644 --- a/lib/portage/package/ebuild/doebuild.py +++ b/lib/portage/package/ebuild/doebuild.py @@ -598,7 +598,8 @@ def doebuild_environment( ) mysettings.features.remove(feature) - if "MAKEOPTS" not in mysettings: + # MAKEOPTS conflicts with MAKEFLAGS, so skip this if MAKEFLAGS exists. + if "MAKEOPTS" not in mysettings and "MAKEFLAGS" not in mysettings: nproc = get_cpu_count() if nproc: mysettings["MAKEOPTS"] = "-j%d" % (nproc) diff --git a/man/make.conf.5 b/man/make.conf.5 index 21ae09e574..9af563a5c8 100644 --- a/man/make.conf.5 +++ b/man/make.conf.5 @@ -1,4 +1,4 @@ -.TH "MAKE.CONF" "5" "Jan 2024" "Portage @VERSION@" "Portage" +.TH "MAKE.CONF" "5" "Aug 2024" "Portage @VERSION@" "Portage" .SH "NAME" make.conf \- custom settings for Portage .SH "SYNOPSIS" @@ -948,6 +948,14 @@ Setting this and other *FLAGS variables arbitrarily may cause compile or runtime failures. Bug reports submitted when nonstandard values are enabled for these flags may be closed as INVALID. .TP +.B MAKEFLAGS +Use this variable instead of \fBMAKEOPTS\fR if you want to inject a +centralized job server for make. In this case \fBMAKEOPTS\fR should be +unset or else it can cause the make jobserver mode to reset. Include +a \fB--jobserver-auth=fifo:PATH\fR flag to specify the path of the +centralized jobserver fifo, which needs to be readable and writable by +the portage group when userpriv is enabled. +.TP .B MAKEOPTS Use this variable if you want to use parallel make. For example, if you have a dual\-processor system, set this variable to "\-j2" or "\-j3" for -- 2.44.2