Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Wed, 11 Sep 2019 17:58:11
Message-Id: 1568224634.2f6f27593eb7d580b2383ef25cef7d1cfea10085.mgorny@gentoo
commit:     2f6f27593eb7d580b2383ef25cef7d1cfea10085
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Tue Sep  3 18:20:04 2019 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Sep 11 17:57:14 2019 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2f6f2759

sgml-catalog-r1.eclass: New eclass to handle SGML catalogs

Create a new, simpler eclass to handle SGML catalog installation.
Rather than relying on external tool to add/remove catalogs
in postinst/postrm, let ebuilds install interim catalogs and just
register all installed catalogs.

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 eclass/sgml-catalog-r1.eclass | 73 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/eclass/sgml-catalog-r1.eclass b/eclass/sgml-catalog-r1.eclass
new file mode 100644
index 00000000000..6dc870af629
--- /dev/null
+++ b/eclass/sgml-catalog-r1.eclass
@@ -0,0 +1,73 @@
+# Copyright 2019 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: sgml-catalog-r1.eclass
+# @MAINTAINER:
+# Michał Górny <mgorny@g.o>
+# @AUTHOR:
+# Michał Górny <mgorny@g.o>
+# @BLURB: Functions for installing SGML catalogs
+# @DESCRIPTION:
+# This eclass regenerates /etc/sgml/catalog, /etc/sgml.{,c}env
+# and /etc/env.d/93sgmltools-lite as necessary for the DocBook tooling.
+# This is done via exported pkg_postinst and pkg_postrm phases.
+
+case ${EAPI:-0} in
+	7) ;;
+	*) die "Unsupported EAPI=${EAPI} for ${ECLASS}";;
+esac
+
+EXPORT_FUNCTIONS pkg_postinst pkg_postrm
+
+if [[ ! ${_SGML_CATALOG_R1} ]]; then
+
+RDEPEND=">=app-text/sgml-common-0.6.3-r7"
+
+# @FUNCTION: sgml-catalog-r1_update_catalog
+# @DESCRIPTION:
+# Regenerate /etc/sgml/catalog to include all installed catalogs.
+sgml-catalog-r1_update_catalog() {
+	local shopt_save=$(shopt -p nullglob)
+	shopt -s nullglob
+	local cats=( "${EROOT}"/etc/sgml/*.cat )
+	${shopt_save}
+
+	if [[ ${#cats[@]} -gt 0 ]]; then
+		ebegin "Updating ${EROOT}/etc/sgml/catalog"
+		printf 'CATALOG "%s"\n' "${cats[@]}" > "${T}"/catalog &&
+		mv "${T}"/catalog "${EROOT}"/etc/sgml/catalog
+		eend "${?}"
+	else
+		ebegin "Removing ${EROOT}/etc/sgml/catalog"
+		rm "${EROOT}"/etc/sgml/catalog &&
+		{ rmdir "${EROOT}"/etc/sgml &>/dev/null || :; }
+		eend "${?}"
+	fi
+}
+
+# @FUNCTION: sgml-catalog-r1_update_env
+# @DESCRIPTION:
+# Regenerate environment variables and copy them to env.d.
+sgml-catalog-r1_update_env() {
+	# gensgmlenv doesn't support overriding root
+	if [[ -z ${ROOT} && -x "${EPREFIX}/usr/bin/gensgmlenv" ]]; then
+		ebegin "Regenerating SGML environment variables"
+		gensgmlenv &&
+		grep -v export "${EPREFIX}/etc/sgml/sgml.env" > "${T}"/93sgmltools-lite &&
+		mv "${T}"/93sgmltools-lite "${EPREFIX}/etc/env.d/93sgmltools-lite"
+		eend "${?}"
+	fi
+}
+
+sgml-catalog-r1_pkg_postinst() {
+	sgml-catalog-r1_update_catalog
+	sgml-catalog-r1_update_env
+}
+
+sgml-catalog-r1_pkg_postrm() {
+	sgml-catalog-r1_update_catalog
+	sgml-catalog-r1_update_env
+}
+
+_SGML_CATALOG_R1=1
+fi