Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.gentoo.dev > #70459

[gentoo-dev] [PATCH v3 1/5] rpm.eclass: rework app-arch/rpm support into pre-inherit variable

From Eli Schwartz <eschwartz@gentoo.org>
Newsgroups linux.gentoo.dev
Subject [gentoo-dev] [PATCH v3 1/5] rpm.eclass: rework app-arch/rpm support into pre-inherit variable
Date 2026-04-24 16:50 +0200
Message-ID <MNq0V-4DW-7@gated-at.bofh.it> (permalink)
References <MMGKt-h9hY-3@gated-at.bofh.it> <MNq0V-4DW-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


app-arch/rpm supports various compression types, but usually via USE
flags. We need ugly strings|grep to see which one is needed. rpm2targz
dynamically detects `@system` set tools which is why it has worked
forever.

To solve this we add RPM_COMPRESS_TYPE="" before inheriting the eclass,
which controls if app-arch/rpm is used. While testing this it also turns
out legacy lzma, i.e. PayloadIsLzma rather than PayloadIsXz, is not
supported by rpm2targz at all (despite bug 321439 implying it *was*
added? the one instance I found in-tree fails). So, exclude it in such
cases.

The eclass now has effectively a "mandatory for proper support" eclass
pre-inherit variable which nothing ever set before. Emit an eqawarn if
it is being "held wrong", to encourage people to set this variable.

Closes: https://bugs.gentoo.org/973073
Closes: https://bugs.gentoo.org/971578
Bug: https://bugs.gentoo.org/971600
Bug: https://bugs.gentoo.org/321439
Signed-off-by: Eli Schwartz <eschwartz@gentoo.org>
---

v3: add (+) to all USE flags, to handle app-arch/rpm-4.19 that
unconditionally enabled them.

 eclass/rpm.eclass | 101 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 90 insertions(+), 11 deletions(-)

diff --git a/eclass/rpm.eclass b/eclass/rpm.eclass
index 3b7f9e64355b..6a096aba78bd 100644
--- a/eclass/rpm.eclass
+++ b/eclass/rpm.eclass
@@ -15,14 +15,62 @@ esac
 if [[ -z ${_RPM_ECLASS} ]] ; then
 _RPM_ECLASS=1
 
-inherit estack
+inherit estack toolchain-funcs
 
-BDEPEND="
-	|| (
-		app-arch/rpm2targz
-		>=app-arch/rpm-4.19.0
-	)
-"
+# @ECLASS_VARIABLE: RPM_COMPRESS_TYPE
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Comma-separated list of app-arch/rpm compression formats. If set,
+# app-arch/rpm will be allowed as a BDEPEND to unpack distfiles. Supported
+# types:
+#
+# - none (rpm is supported but distfile is uncompressed or builtin zlib)
+#
+# - bzip2 (.bz2)
+#
+# - lzma (deprecated pre-xz iteration of the lzma SDK. rpm2targz doesn't
+#   support it)
+#
+# - xz (.xz)
+#
+# - zstd (.zst)
+#
+# - "" (empty -- the ebuild hasn't been updated to resolve deprecations)
+
+_rpm_set_globals() {
+	local rpmdep= rpmuse= rpm2tar="true" t= types=()
+	IFS=, declare -a 'types=(${RPM_COMPRESS_TYPE})'
+
+	if [[ ${RPM_COMPRESS_TYPE} = none ]]; then
+		rpmdep=">=app-arch/rpm-4.19.0"
+	elif [[ "${#types[@]}" -gt 0 ]]; then
+		for t in "${types[@]}"; do
+			case ${t} in
+				bzip2|zstd) rpmuse+="${t}(+)," ;;
+				lzma) rpmuse+="${t}(+),"; rpm2tar="false" ;;
+				xz) rpmuse+="lzma(+)," ;;
+				none) die "RPM_COMPRESS_TYPE: 'none' cannot be combined with other values" ;;
+				*) die "invalid RPM_COMPRESS_TYPE: ${RPM_COMPRESS_TYPE} (found: ${t})" ;;
+			esac
+		done
+		rpmdep=">=app-arch/rpm-4.19.0"
+		[[ ${rpmuse} ]] && rpmdep+="[${rpmuse%,}]"
+	fi
+
+	if [[ ${rpm2tar} = true ]]; then
+		BDEPEND="
+			|| (
+				app-arch/rpm2targz
+				${rpmdep}
+			)
+		"
+	else
+		BDEPEND="${rpmdep}"
+	fi
+}
+_rpm_set_globals
+unset -f _rpm_set_globals
 
 # @FUNCTION: rpm_unpack
 # @USAGE: <rpms>
@@ -30,7 +78,10 @@ BDEPEND="
 # Unpack the contents of the specified rpms like the unpack() function.
 rpm_unpack() {
 	[[ $# -eq 0 ]] && set -- ${A}
-	local a
+	local a noticed=()
+
+	IFS=, declare -a 'types=(${RPM_COMPRESS_TYPE})'
+
 	for a in "$@" ; do
 		echo ">>> Unpacking ${a} to ${PWD}"
 		if [[ ${a} == ./* ]] ; then
@@ -43,11 +94,39 @@ rpm_unpack() {
 			a="${DISTDIR}/${a}"
 		fi
 
-		if command -v rpm2tar >/dev/null; then
-			local extracttool=(rpm2tar -O)
+		local payload= usedep=""
+		if [[ ${a} = *.src.rpm ]]; then
+			payload=none
 		else
-			# app-arch/rpm fallback
+			payload=$($(tc-getSTRINGS) "${a}" | grep -o 'PayloadIs[a-zA-Z]*'; pipestatus || die "failed to grep rpm payload")
+		fi
+
+		case ${payload} in
+			"") payload=none;; # gzip/uncompressed
+			PayloadIsBzip) payload=bzip2 usedep="[bzip2(+)]";;
+			PayloadIsXz) payload=xz usedep="[lzma(+)]";;
+			PayloadIsLzma) payload=lzma usedep="[lzma(+)]";;
+			PayloadIsZstd) payload=zstd usedep="[zstd(+)]";;
+		esac
+
+		local use_rpm=
+		if [[ ${RPM_COMPRESS_TYPE} = *${payload}* ||
+			  ( ${payload} = none && ${RPM_COMPRESS_TYPE} ) ]]; then
+			use_rpm=true
+		elif ! has "${payload}" "${noticed[@]}"; then
+			eqawarn "QA Notice: rpm_unpack called without supporting app-arch/rpm."
+			eqawarn "\${RPM_COMPRESS_TYPE} should include '${payload}'."
+			noticed+=("${payload}")
+		fi
+
+		if [[ ${use_rpm} = true ]] && has_version -b "app-arch/rpm${usedep}"; then
+			# prefer it if correct USE is in BDEPEND and installed
 			local extracttool=(rpm2archive -n)
+		elif [[ ${payload} = lzma ]]; then
+			# bug 321439
+			die "rpm_unpack called with legacy lzma compression that rpm2targz doesn't support"
+		else
+			local extracttool=(rpm2tar -O)
 		fi
 
 		"${extracttool[@]}" "${a}" | tar xf -
-- 
2.52.0

Back to linux.gentoo.dev | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

[gentoo-dev] [PATCH 1/5] rpm.eclass: rework app-arch/rpm support into pre-inherit variable Eli Schwartz <eschwartz@gentoo.org> - 2026-04-22 16:30 +0200
  [gentoo-dev] [PATCH 4/5] x11-themes/leonidas-backgrounds: set rpm.eclass var for reference rpm support Eli Schwartz <eschwartz@gentoo.org> - 2026-04-22 16:30 +0200
  Re: [gentoo-dev] [PATCH 1/5] rpm.eclass: rework app-arch/rpm support  into pre-inherit variable Nowa Ammerlaan <nowa@gentoo.org> - 2026-04-22 17:20 +0200
    Re: [gentoo-dev] [PATCH 1/5] rpm.eclass: rework app-arch/rpm support  into pre-inherit variable Eli Schwartz <eschwartz@gentoo.org> - 2026-04-23 00:20 +0200
  Re: [gentoo-dev] [PATCH 1/5] rpm.eclass: rework app-arch/rpm  support into pre-inherit variable Sam James <sam@gentoo.org> - 2026-04-22 18:20 +0200
    Re: [gentoo-dev] [PATCH 1/5] rpm.eclass: rework app-arch/rpm support  into pre-inherit variable Eli Schwartz <eschwartz@gentoo.org> - 2026-04-23 00:20 +0200
      Re: [gentoo-dev] [PATCH 1/5] rpm.eclass: rework app-arch/rpm  support into pre-inherit variable Sam James <sam@gentoo.org> - 2026-04-23 02:10 +0200
  [gentoo-dev] [PATCH v2 1/5] rpm.eclass: rework app-arch/rpm support into pre-inherit variable Eli Schwartz <eschwartz@gentoo.org> - 2026-04-23 02:50 +0200
    Re: [gentoo-dev] [PATCH v2 1/5] rpm.eclass: rework app-arch/rpm  support into pre-inherit variable Sam James <sam@gentoo.org> - 2026-04-23 03:20 +0200
    Re: [gentoo-dev] [PATCH v2 1/5] rpm.eclass: rework app-arch/rpm  support into pre-inherit variable Nicolas PARLANT <nicolas.parlant@parhuet.fr> - 2026-04-23 06:30 +0200
      Re: [gentoo-dev] [PATCH v2 1/5] rpm.eclass: rework app-arch/rpm  support into pre-inherit variable Eli Schwartz <eschwartz@gentoo.org> - 2026-04-23 07:00 +0200
  [gentoo-dev] [PATCH v3 0/5] rpm.eclass: rework app-arch/rpm support into pre-inherit variable Eli Schwartz <eschwartz@gentoo.org> - 2026-04-24 16:50 +0200
    [gentoo-dev] [PATCH v3 4/5] x11-themes/leonidas-backgrounds: set rpm.eclass var for reference rpm support Eli Schwartz <eschwartz@gentoo.org> - 2026-04-24 16:50 +0200
    [gentoo-dev] [PATCH v3 1/5] rpm.eclass: rework app-arch/rpm support into pre-inherit variable Eli Schwartz <eschwartz@gentoo.org> - 2026-04-24 16:50 +0200
    [gentoo-dev] [PATCH v3 3/5] app-backup/tsm: set rpm.eclass var for reference rpm support Eli Schwartz <eschwartz@gentoo.org> - 2026-04-24 16:50 +0200
    [gentoo-dev] [PATCH v3 5/5] rpm.eclass: make RPM_COMPRESS_TYPE mandatory in EAPI 9 Eli Schwartz <eschwartz@gentoo.org> - 2026-04-24 16:50 +0200
    [gentoo-dev] [PATCH v3 2/5] app-office/libreoffice-l10n: set rpm.eclass var for reference rpm support Eli Schwartz <eschwartz@gentoo.org> - 2026-04-24 16:50 +0200

csiph-web