greadme.eclass: support EAPI 9, make auto-format opt-in

Experience has shown that having auto-formatting enabled by default
is more of a nuisance than it is helpful. Since greadme allows
creating the readme file via Bash here-docs, ebuild authors typically
control the exact formatting and line breaks themselves rather than
wanting to rely on the external 'fmt' tool.

To address this, EAPI 9 changes the default behavior to disable
auto-formatting. The formatting feature is still fully supported,
but it is now strictly opt-in via the new GREADME_AUTOFORMAT variable.

For backwards compatibility, EAPI 8 retains the old behavior and
defaults to auto-formatting (opt-out via GREADME_DISABLE_AUTOFORMAT).

Additionally, the eapi9-pipestatus inherit is now conditionally
restricted to EAPI 8, as pipestatus is provided by EAPI 9.

Signed-off-by: Florian Schmaus <flow@gentoo.org>
This commit is contained in:
Florian Schmaus
2026-06-25 12:23:34 +02:00
parent 2bf3ff4c27
commit 1454aa9c4d

View File

@@ -4,7 +4,7 @@
# @ECLASS: greadme.eclass
# @MAINTAINER:
# Florian Schmaus <flow@gentoo.org>
# @SUPPORTED_EAPIS: 8
# @SUPPORTED_EAPIS: 8 9
# @BLURB: install a doc file, that will be conditionally shown via elog messages
# @DESCRIPTION:
# An eclass for installing a README.gentoo doc file with important
@@ -45,6 +45,7 @@ _GREADME_ECLASS=1
case ${EAPI} in
8) inherit eapi9-pipestatus ;;
9) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
@@ -61,7 +62,14 @@ _GREADME_REL_PATH="/usr/share/doc/${PF}/README.gentoo"
# @ECLASS_VARIABLE: GREADME_DISABLE_AUTOFORMAT
# @DEFAULT_UNSET
# @DESCRIPTION:
# If non-empty, the readme file will not be automatically formatted.
# If non-empty, the readme file will not be automatically formatted if
# EAPI < 9.
# @ECLASS_VARIABLE: GREADME_AUTOFORMAT
# @DEFAULT_UNSET
# @DESCRIPTION:
# If non-empty, the readme file will be automatically formatted if
# EAPI >= 9.
# @FUNCTION: greadme_stdin
# @USAGE: [--append]
@@ -113,7 +121,19 @@ _greadme_install_doc() {
debug-print-function ${FUNCNAME} "$@"
local greadme="${_GREADME_TMP_FILE}"
if [[ ! ${GREADME_DISABLE_AUTOFORMAT} ]]; then
local autoformat
if [[ ${EAPI} == 8 ]]; then
# Older EAPI default is to auto-format.
autoformat=1
[[ ${GREADME_DISABLE_AUTOFORMAT} ]] && autoformat=
else
# The modern default is not to auto-format.
autoformat=
[[ ${GREADME_AUTOFORMAT} ]] && autoformat=1
fi
if [[ ${autoformat} ]]; then
greadme="${_GREADME_TMP_FILE}".formatted
# Use fold, followed by a sed to strip trailing whitespace.