Skip to content

Commit

Permalink
ebuild.sh: disable patsub_replacement in Bash 5.2
Browse files Browse the repository at this point in the history
patsub_replacement is a new option in bash-5.2 that is also default-on
in that release. The default value is not gated by BASH_COMPAT (see bug #881383),
hence we need to disable it for older Bashes to avoid behaviour changes in ebuilds
and eclasses.

Thanks to Kerin for both raising this & being persistent with trying
to get Bash 5.2 to be suitable for use in Gentoo.

Bug: https://bugs.gentoo.org/881383
Thanks-to: Kerin Millar <kfm@plushkava.net>
Signed-off-by: Sam James <sam@gentoo.org>
  • Loading branch information
thesamesam committed Nov 30, 2022
1 parent 839ab46 commit 69cac73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Features:
scratch using a crossdev environment under /usr/${CHOST}.

Bug fixes:
* ebuild: Handle Bash 5.2's change in behavior which enables the shopt
'patsub_replacement' by default. This is needed to avoid breaking existing
working ebuilds. Future EAPIs will need to adjust the logic
added by this change. See bug #881383.

* sync: Clobber repositories using sync-type=git to match rsync behavior. This
helps with issues where git-synced repositories can become confused
if the remote is a CDN and then starts to diverge, preventing further
Expand Down
14 changes: 14 additions & 0 deletions bin/ebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit 1
# used instead.
__check_bash_version() {
# Figure out which min version of bash we require.
# Adjust patsub_replacement logic below on new EAPI!
local maj min
if ___eapi_bash_3_2 ; then
maj=3 min=2
Expand Down Expand Up @@ -50,6 +51,19 @@ __check_bash_version() {
if ___eapi_bash_3_2 && [[ ${BASH_VERSINFO[0]} -gt 3 ]] ; then
shopt -s compat32
fi

# patsub_replacement is a new option in bash-5.2 that is also default-on
# in that release. The default value is not gated by BASH_COMPAT (see bug #881383),
# hence we need to disable it for older Bashes to avoid behaviour changes in ebuilds
# and eclasses.
#
# New EAPI note: a newer EAPI (after 8) may well adopt Bash 5.2 as its minimum version.
# If it does, this logic will need to be adjusted to only disable patsub_replacement
# for < ${new_api}!
if (( BASH_VERSINFO[0] >= 6 || ( BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 2 ) )) ; then
shopt -u patsub_replacement
fi

}
__check_bash_version

Expand Down

0 comments on commit 69cac73

Please sign in to comment.