Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass through MAKEFLAGS and exclude from environment.bz2 #1364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bin/save-ebuild-env.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/portage/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion lib/portage/package/ebuild/_config/special_env_vars.py
Original file line number Diff line number Diff line change
@@ -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__ = (
Expand Down Expand Up @@ -112,6 +112,7 @@
"FEATURES",
"FILESDIR",
"HOME",
"MAKEFLAGS",
"MERGE_TYPE",
"NOCOLOR",
"NO_COLOR",
Expand Down
5 changes: 3 additions & 2 deletions lib/portage/package/ebuild/doebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,12 @@ 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duplication of this with the GNUMAKEFLAGS + MAKEFLAGS condition below is suspicious?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that second "MAKEFLAGS" not in mysettings became redundant so I've removed it now. Thanks!

nproc = get_cpu_count()
if nproc:
mysettings["MAKEOPTS"] = "-j%d" % (nproc)
if "GNUMAKEFLAGS" not in mysettings and "MAKEFLAGS" not in mysettings:
if "GNUMAKEFLAGS" not in mysettings:
mysettings["GNUMAKEFLAGS"] = (
f"--load-average {nproc} --output-sync=line"
)
Expand Down
10 changes: 9 additions & 1 deletion man/make.conf.5
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we parse MAKEFLAGS then we can automatically add a sandbox exemption for the jobserver fifo. Otherwise users will have to do this themselves or put the fifo in an unsandboxed location like $PORTAGE_TMPDIR (they might have to do that for sesandbox too).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this pass option like -k though, too?

Yes, in fact -k is considered a "simple" option because it has no argument, and make represents these simple options as a group of letters at the beginning of MAKEFLAGS like MAKEFLAGS="k -j4 -l4 --jobserver-auth=fifo:/tmp/GMfifo30205".
If there are no simple options then MAKEFLAGS begins with a space.

I mean, passing arbitrary options sounds dangerous and undesirable. If someone currently runs emerge via make -k as part of some bigger script, I don't think we should pass that one to make invocations within package builds.

If we parse MAKEFLAGS in order to add a sandbox exemption for the fifo, I suppose we might filter out the simple options while we're there.

.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
Expand Down