From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-dev+bounces-102798-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 48A391581FB
	for <garchives@archives.gentoo.org>; Sun, 24 Nov 2024 12:25:00 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 14B06E07E6;
	Sun, 24 Nov 2024 12:24:54 +0000 (UTC)
Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 29517E07D7
	for <gentoo-dev@lists.gentoo.org>; Sun, 24 Nov 2024 12:24:53 +0000 (UTC)
From: =?utf-8?Q?Ulrich_M=C3=BCller?= <ulm@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: [gentoo-dev] New eclass: eapi9-pipestatus.eclass
Date: Sun, 24 Nov 2024 13:24:43 +0100
Message-ID: <u4j3wrf90@urania.mail-host-address-is-not-set>
User-Agent: Gnus/5.13 (Gnus v5.13)
Precedence: bulk
List-Post: <mailto:gentoo-dev@lists.gentoo.org>
List-Help: <mailto:gentoo-dev+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-dev+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-dev+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-dev.gentoo.org>
X-BeenThere: gentoo-dev@lists.gentoo.org
Reply-to: gentoo-dev@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
MIME-Version: 1.0
Content-Type: multipart/signed; boundary="==-=-=";
	micalg=pgp-sha256; protocol="application/pgp-signature"
X-Archives-Salt: 0904ccd5-6236-412f-9bbd-246f029f7ecb
X-Archives-Hash: fc29b78654674461a57a18d7e1de0c80

--==-=-=
Content-Type: multipart/mixed; boundary="=-=-="

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

This implements a pipestatus command, as discussed in bug 566342 [1]
and on IRC.

Subject to approval by the council, the command would be added in
EAPI 9. Its definition in the Package Manager Specification would be
along the lines of:

=E2=95=93=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=95=91 Tests the shell's pipe status array, i.e. the exit status of the
=E2=95=91 command(s) in the most recently executed foreground pipeline.
=E2=95=91 Returns shell true (0) if all elements are zero, or the last
=E2=95=91 non-zero element otherwise. If called with -v as the first argume=
nt,
=E2=95=91 also outputs the pipe status array as a space-separated list.
=E2=95=99=E2=94=80=E2=94=80=E2=94=80=E2=94=80

The "assert" command could then be banned (either in the same EAPI or
in the following EAPI), typically to be replaced by "pipestatus || die".

I would commit the eclass after the next council meeting, and obviously
only under the condition that the council will pre-approve the command
for EAPI 9.

[1] https://bugs.gentoo.org/566342


--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline; filename=eapi9-pipestatus.eclass
Content-Transfer-Encoding: quoted-printable

# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: eapi9-pipestatus.eclass
# @MAINTAINER:
# Ulrich M=C3=BCller <ulm@gentoo.org>
# @AUTHOR:
# Ulrich M=C3=BCller <ulm@gentoo.org>
# @SUPPORTED_EAPIS: 7 8
# @BLURB: test the PIPESTATUS array
# @DESCRIPTION:
# A stand-alone implementation of a possible future pipestatus command
# (which would be aimed for EAPI 9).  It is meant as a replacement for
# "assert".  In its simplest form it can be called like this:
#
# @CODE
# foo | bar
# pipestatus || die
# @CODE
#
# With the -v option, the command will also echo the pipe status array,
# so it can be assigned to a variable like in the following example:
#
# @CODE
# local status
# foo | bar
# status=3D$(pipestatus -v) || die "foo | bar failed, status ${status}"
# @CODE

case ${EAPI} in
	7|8) ;;
	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac

# @FUNCTION: pipestatus
# @USAGE: [-v]
# @RETURN: last non-zero element of PIPESTATUS, or zero if all are zero
# @DESCRIPTION:
# Test the PIPESTATUS array, i.e. the exit status of the command(s)
# in the most recently executed foreground pipeline.  If called with
# option -v, also output the PIPESTATUS array.
pipestatus() {
	local -a status=3D( "${PIPESTATUS[@]}" )
	local s ret=3D0

	[[ $# -gt 0 && ${1} !=3D -v || $# -gt 1 ]] \
		&& die "${FUNCNAME}: bad arguments: $@"

	[[ ${1} =3D=3D -v ]] && echo "${status[@]}"

	for s in "${status[@]}"; do
		[[ ${s} -ne 0 ]] && ret=3D${s}
	done

	return "${ret}"
}

--=-=-=--

--==-=-=
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQFDBAEBCAAtFiEEtDnZ1O9xIP68rzDbUYgzUIhBXi4FAmdDGwsPHHVsbUBnZW50
b28ub3JnAAoJEFGIM1CIQV4u3W4H/1kybz6ohbS1NJ40yJJhTiiXUyCwr8aqL7zR
9GsDo8COGBscCeDCAIhYMdxpa8gRL6jwHYhcIDlmnRSyPyTuqeRy0PrYLV2BKi0R
Tw+m485DTqvF9wu5hnDymqv2Iiy4xYD3Y7QmTbh0u/gjzVxpoSwwNRlNIu91XYBo
u4nw1f6Q9yEkhYPsau61U5Oh+mWAvXmMl+CzVS7ZZlcUrcCDtydTclK4PyN01edg
t3SzPnulDwbailxVTqOlUMEa5l1CFZdc6y2RkTUmokHuwP4u5ogOpcM8Onje1Mff
LQvodfjOhIekrnRfLmn5faNkhn9h16U5QM+eaVzqXq74sZ5c/OY=
=0pUl
-----END PGP SIGNATURE-----
--==-=-=--