Upgrade sys-apps/pv package from 1.6.6 to 1.6.20

BUG=b:216306532
TEST=built pv on amd64 host

Change-Id: I0a31dc88c71842fc7a831baab0d41d6dda433c01
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/portage-stable/+/3465428
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Gilberto Contreras <gcontreras@google.com>
Commit-Queue: Gilberto Contreras <gcontreras@google.com>
diff --git a/eclass/plocale.eclass b/eclass/plocale.eclass
new file mode 100644
index 0000000..3a7b78e
--- /dev/null
+++ b/eclass/plocale.eclass
@@ -0,0 +1,169 @@
+# Copyright 2012-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: plocale.eclass
+# @MAINTAINER:
+# Ulrich Müller <ulm@gentoo.org>
+# @AUTHOR:
+# Ben de Groot <yngwin@gentoo.org>
+# @SUPPORTED_EAPIS: 6 7 8
+# @BLURB: convenience functions to handle localizations
+# @DESCRIPTION:
+# The plocale (localization) eclass offers a number of functions to more
+# conveniently handle localizations (translations) offered by packages.
+# These are meant to prevent code duplication for such boring tasks as
+# determining the cross-section between the user's set LINGUAS and what
+# is offered by the package.
+#
+# Typical usage in an ebuild looks like this:
+#
+# @CODE
+#   PLOCALES="de en fr pt_BR zh_CN"
+#   PLOCALE_BACKUP="en"
+# @CODE
+#
+# There, PLOCALES is the list of locales that the package supports.
+# PLOCALE_BACKUP is optional and specifies a single locale, which is
+# used as a fallback if none of the PLOCALES matches the user's
+# LINGUAS selection.
+#
+# The eclass functions then operate on the intersection of the package's
+# PLOCALES with the user's LINGUAS setting.  (As a special case, if the
+# LINGUAS variable is unset then all items in PLOCALES will be used,
+# emulating the behaviour of gettext.)
+#
+# In the following simple example, locale specific README files
+# (e.g. README.de, README.en) are added to the DOCS variable:
+#
+# @CODE
+#   my_add_to_docs() {
+#       DOCS+=( ${1}.${2} )
+#   }
+#   plocale_for_each_locale my_add_to_docs README
+# @CODE
+#
+# A complementary function plocale_for_each_disabled_locale exists as
+# well, which operates on the set difference of PLOCALES and LINGUAS,
+# i.e. on the locales that the user hasn't enabled.  For example, it can
+# be used to remove unnecessary locale files.
+#
+# Finally, plocale_find_changes is purely a helper function for ebuild
+# maintenance.  It can be used to scan a directory for available
+# translations and check if the ebuild's PLOCALES are still up to date.
+
+case ${EAPI} in
+	6|7|8) ;;
+	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+if [[ -z ${_PLOCALE_ECLASS} ]]; then
+_PLOCALE_ECLASS=1
+
+# @ECLASS-VARIABLE: PLOCALES
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Variable listing the locales for which localizations are offered by
+# the package.
+#
+# Example: PLOCALES="cy de el_GR en_US pt_BR vi zh_CN"
+
+# @ECLASS-VARIABLE: PLOCALE_BACKUP
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# In some cases the package fails when none of the offered PLOCALES are
+# selected by the user.  In that case this variable should be set to a
+# default locale (usually 'en' or 'en_US') as backup.
+#
+# Example: PLOCALE_BACKUP="en_US"
+
+# @FUNCTION: plocale_for_each_locale
+# @USAGE: <function> [<args>...]
+# @DESCRIPTION:
+# Convenience function for processing all enabled localizations.
+# The parameter should be a function (defined in the consuming eclass
+# or ebuild) which takes an individual locale as its (last) parameter.
+#
+# Example: plocale_for_each_locale install_locale
+plocale_for_each_locale() {
+	local locs x
+	locs=$(plocale_get_locales)
+	for x in ${locs}; do
+		"$@" ${x} || die "failed to process enabled ${x} locale"
+	done
+}
+
+# @FUNCTION: plocale_for_each_disabled_locale
+# @USAGE: <function> [<args>...]
+# @DESCRIPTION:
+# Complementary to plocale_for_each_locale, this function will process
+# locales that are disabled.  This could be used for example to remove
+# locales from a Makefile, to prevent them from being built needlessly.
+plocale_for_each_disabled_locale() {
+	local locs x
+	locs=$(plocale_get_locales disabled)
+	for x in ${locs}; do
+		"$@" ${x} || die "failed to process disabled ${x} locale"
+	done
+}
+
+# @FUNCTION: plocale_find_changes
+# @USAGE: <translations dir> <filename pre pattern> <filename post pattern>
+# @DESCRIPTION:
+# Ebuild maintenance helper function to find changes in package offered
+# locales when doing a version bump.  This could be added for example
+# to src_prepare.
+#
+# Example: plocale_find_changes "${S}/src/translations" "${PN}_" '.ts'
+plocale_find_changes() {
+	[[ $# -eq 3 ]] || die "Exactly 3 arguments are needed!"
+	ebegin "Looking in ${1} for new locales"
+	pushd "${1}" >/dev/null || die "Cannot access ${1}"
+	local current="" x
+	for x in ${2}*${3}; do
+		x=${x#"${2}"}
+		x=${x%"${3}"}
+		current+="${x} "
+	done
+	popd >/dev/null || die
+	# RHS will be sorted with single spaces so ensure the LHS is too
+	# before attempting to compare them for equality. See bug #513242.
+	# Run them both through the same sorting algorithm so we don't have
+	# to worry about them being the same.
+	[[ "$(printf '%s\n' ${PLOCALES} | LC_ALL=C sort)" \
+		== "$(printf '%s\n' ${current} | LC_ALL=C sort)" ]]
+	if ! eend $? "There are changes in locales!"; then
+		eerror "This ebuild should be updated to:"
+		eerror "PLOCALES=\"${current%[[:space:]]}\""
+		return 1
+	fi
+}
+
+# @FUNCTION: plocale_get_locales
+# @USAGE: [disabled]
+# @DESCRIPTION:
+# Determine which LINGUAS the user has enabled that are offered by the
+# package, as listed in PLOCALES, and return them.  In case no locales
+# are selected, fall back on PLOCALE_BACKUP.  When the disabled argument
+# is given, return the disabled locales instead of the enabled ones.
+plocale_get_locales() {
+	local loc locs
+	if [[ -z ${LINGUAS+set} ]]; then
+		# enable all if unset
+		locs=${PLOCALES}
+	else
+		for loc in ${LINGUAS}; do
+			has ${loc} ${PLOCALES} && locs+="${loc} "
+		done
+	fi
+	[[ -z ${locs} ]] && locs=${PLOCALE_BACKUP}
+	if [[ ${1} == disabled ]]; then
+		local disabled_locs
+		for loc in ${PLOCALES}; do
+			has ${loc} ${locs} || disabled_locs+="${loc} "
+		done
+		locs=${disabled_locs}
+	fi
+	printf "%s" "${locs}"
+}
+
+fi
diff --git a/sys-apps/pv/Manifest b/sys-apps/pv/Manifest
index 097373f..57d6f41 100644
--- a/sys-apps/pv/Manifest
+++ b/sys-apps/pv/Manifest
@@ -1 +1 @@
-DIST pv-1.6.6.tar.bz2 109220 BLAKE2B 1cfb60e49f6301f0d990467a58013522bbc1e28e2936a1a2141918af05149b59b6cc494f290d99ee7072247b8f0e230b799cd5dae6f8aa59d116691319e952cb SHA512 cc841b4bd00e4e8fcaed97da094ebac4a11af1c3f843ce5f73d0c3ab20aca29498c6b1a224c653d40127304d8269d96f413df66b980809e9278ff9544c834a26
+DIST pv-1.6.20.tar.bz2 115310 BLAKE2B b50623f623231e8e8615f960bad83d10e12d5274c57d23ea843d16fce30b3e690284b2d9b01f82a16b9790e2bf26f80f560e226589a62ca677a2cf90ea007691 SHA512 e445f91b298ed285ddab54a3f8a6b5d5297e2e2eb8ad7b2ee2cbacca4adda9c6ca2bf3c77bf2a93373d3875c5b3b0b345d3945cbd91fc2647c6c25f1661a6752
diff --git a/sys-apps/pv/metadata.xml b/sys-apps/pv/metadata.xml
index b9de93a..882536d 100644
--- a/sys-apps/pv/metadata.xml
+++ b/sys-apps/pv/metadata.xml
@@ -1,11 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
 <pkgmetadata>
-  <maintainer type="person">
-    <email>jer@gentoo.org</email>
-    <name>Jeroen Roovers</name>
-  </maintainer>
-  <upstream>
-    <remote-id type="google-code">pipeviewer</remote-id>
-  </upstream>
+	<maintainer type="person">
+		<email>gyakovlev@gentoo.org</email>
+		<name>Georgy Yakovlev</name>
+	</maintainer>
+	<maintainer type="person">
+		<email>sam@gentoo.org</email>
+		<name>Sam James</name>
+	</maintainer>
+	<upstream>
+		<remote-id type="google-code">pipeviewer</remote-id>
+		<remote-id type="github">a-j-wood/pv</remote-id>
+	</upstream>
 </pkgmetadata>
diff --git a/sys-apps/pv/pv-1.6.20.ebuild b/sys-apps/pv/pv-1.6.20.ebuild
new file mode 100644
index 0000000..b6e2069
--- /dev/null
+++ b/sys-apps/pv/pv-1.6.20.ebuild
@@ -0,0 +1,60 @@
+# Copyright 1999-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit linux-info toolchain-funcs plocale
+
+DESCRIPTION="Pipe Viewer: a tool for monitoring the progress of data through a pipe"
+HOMEPAGE="https://www.ivarch.com/programs/pv.shtml"
+SRC_URI="https://www.ivarch.com/programs/sources/${P}.tar.bz2"
+
+LICENSE="Artistic-2"
+SLOT="0"
+KEYWORDS="*"
+IUSE="debug nls"
+
+PLOCALES="de fr pl pt"
+PLOCALE_BACKUP="en"
+
+DOCS=( README doc/NEWS doc/TODO )
+
+# Doesn't build a library.
+QA_CONFIGURE_OPTIONS="--disable-static"
+
+pkg_setup() {
+	if use kernel_linux; then
+		CONFIG_CHECK="~SYSVIPC"
+		ERROR_SYSVIPC="You will need to enable CONFIG_SYSVIPC in your kernel to use the --remote option."
+		linux-info_pkg_setup
+	fi
+}
+
+src_prepare() {
+	default
+
+	sed -i configure -e 's|CFLAGS="-g -Wall"|:|g' || die
+
+	# These should produce the same end result (working `pv`).
+	sed -i \
+		-e 's:$(LD) $(LDFLAGS) -o:$(AR) rc:' \
+		autoconf/make/modules.mk~ || die
+
+	sed -i -e 's:usleep 200000 || ::g' tests/019-remote-cksum || die
+
+	disable_locale() {
+		local locale=${1}
+		sed -i configure -e "/ALL_LINGUAS=/s:${locale}::g" || die
+	}
+
+	plocale_find_changes src/nls '' '.po'
+	plocale_for_each_disabled_locale disable_locale
+}
+
+src_configure() {
+	tc-export AR
+
+	econf \
+		$(use_enable debug debugging) \
+		$(use_enable nls)
+}
diff --git a/sys-apps/pv/pv-1.6.6.ebuild b/sys-apps/pv/pv-1.6.6.ebuild
deleted file mode 100644
index 0993209..0000000
--- a/sys-apps/pv/pv-1.6.6.ebuild
+++ /dev/null
@@ -1,53 +0,0 @@
-# Copyright 1999-2018 Gentoo Authors
-# Distributed under the terms of the GNU General Public License v2
-
-EAPI=6
-inherit linux-info toolchain-funcs
-
-DESCRIPTION="Pipe Viewer: a tool for monitoring the progress of data through a pipe"
-HOMEPAGE="http://www.ivarch.com/programs/pv.shtml"
-SRC_URI="http://www.ivarch.com/programs/sources/${P}.tar.bz2"
-
-LICENSE="Artistic-2"
-SLOT="0"
-KEYWORDS="*"
-IUSE="debug nls"
-
-PV_LINGUAS=( de fr pl pt )
-
-DOCS=( README doc/NEWS doc/TODO )
-
-pkg_setup() {
-	if use kernel_linux; then
-		CONFIG_CHECK="~SYSVIPC"
-		ERROR_SYSVIPC="You will need to enable CONFIG_SYSVIPC in your kernel to use the --remote option."
-		linux-info_pkg_setup
-	fi
-}
-
-src_prepare() {
-	default
-
-	sed -i configure -e 's|CFLAGS="-g -Wall"|:|g' || die
-
-	# These should produce the same end result (working `pv`).
-	sed -i \
-		-e 's:$(LD) $(LDFLAGS) -o:$(AR) rc:' \
-		autoconf/make/modules.mk~ || die
-}
-
-src_configure() {
-	tc-export AR
-	local lingua
-	for lingua in ${PV_LINGUAS[@]}; do
-		if ! has ${lingua} ${LINGUAS-${lingua}}; then
-			sed -i configure -e "/ALL_LINGUAS=/s:${lingua}::g" || die
-		fi
-	done
-	econf $(use_enable debug debugging) $(use_enable nls)
-}
-
-src_test() {
-	sed -i -e 's:usleep 200000 || ::g' tests/019-remote-cksum || die
-	default
-}