commit: 968df8172a30781408a60c974d60050098d36971
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Sep 28 20:15:42 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Sep 29 20:49:46 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=968df817
phase-helpers.sh: unpack(): handle "--" in accordance with PMS
As concerns the unpack() function, a recent commit cleaned up its
option parsing routine. However, the revised code fails to account for
the fact that PMS mandates that the "--" argument be treated in a
somewhat unconventional way. Consider the following invocation.
eapply -d "${S}/subdir" -- "${FILESDIR}/${PN}-some-necessary.patch"
Those familiar with getopt(3) conventions will immediately understand
that "--" is used to separate options and option-arguments from operands
(non-options). But the specification for eapply() goes further by
mandating that, if "--" is encountered, all arguments to its left are to
be conveyed to the patch(1) utility, irrespective of their values.
Further, in that event, the specification mandates that the rule of
options only being able to precede operands shall not be enforced.
Such an approach confers the benefit of being able to convey
option-arguments following short options to patch(1), without eapply()
needing to be aware of how the utility parses them. Therein lies the
rub, since the revised code fails to handle "--" in the prescribed way.
Instead, the "${S}/subdir" argument is considered as an eapply() operand
on account of not leading with a <hyphen-minus>.
Address this issue by once again permitting for the positional
parameters to be iterated over up to two times, and handling the
presence of the "--" argument as a special case. Yet, do so without
unduly impacting on the simplicity of the code that is a consequence of
its original refactoring.
Reported-by: Pavel Sobolev <contact <AT> paveloom.dev>
Closes: https://bugs.gentoo.org/963536
Fixes: d594f7a29999779aa644c30a85a25c9811f02970
Link: https://projects.gentoo.org/pms/8/pms.html#x1-127001r1
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/phase-helpers.sh | 42 ++++++++++++++++++++++++++++++++----------
1 file changed, 32 insertions(+), 10 deletions(-)
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index aa9f6af8be..e1f301a5f5 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -1024,26 +1024,48 @@ if ___eapi_has_eapply; then
local LC_ALL LC_COLLATE=C f i path
local -a operands options
+ # PMS mandates an unconventional option parsing scheme whereby
+ # the rule that options must precede non-option arguments is
+ # only enforced in the case that no "--" argument is found.
+ # https://projects.gentoo.org/pms/8/pms.html#x1-127001r1
while (( $# )); do
case $1 in
--)
- shift
- operands+=("$@")
break
;;
- -*)
- if (( ! ${#operands[@]} )); then
- options+=("$1")
- else
- die "eapply: options must
precede non-option arguments"
- fi
- ;;
*)
- operands+=("$1")
+ options+=("$1")
esac
shift
done
+ if (( $# )); then
+ # The "--" argument was encountered. Forward those to
+ # its left to the patch(1) utility, while considering
+ # those to its right as eapply operands.
+ shift
+ operands=("$@")
+ else
+ # Restore the positional parameters and parse normally.
+ set -- "${options[@]}"
+ options=()
+
+ while (( $# )); do
+ case $1 in
+ -*)
+ if (( ! ${#operands[@]} )); then
+ options+=("$1")
+ else
+ die "eapply: options
must precede non-option arguments"
+ fi
+ ;;
+ *)
+ operands+=("$1")
+ esac
+ shift
+ done
+ fi
+
if (( ! ${#operands[@]} )); then
die "eapply: no operands were specified"
fi