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

Florian Schmaus <[email protected]> Thu, 25 Jun 2026 12:28:16 +0200
Newsgroups gmane.linux.gentoo.devel
Message-ID <[email protected]>
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 <[email protected]>
---
 eclass/greadme.eclass | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/eclass/greadme.eclass b/eclass/greadme.eclass
index 6c1e1fd57458..7e3f715fffa8 100644
--- a/eclass/greadme.eclass
+++ b/eclass/greadme.eclass
@@ -4,7 +4,7 @@
 # @ECLASS: greadme.eclass
 # @MAINTAINER:
 # Florian Schmaus <[email protected]>
-# @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.
-- 
2.53.0