Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH v2] sgml-catalog-r1.eclass: New eclass to handle SGML catalogs
Date: Thu, 05 Sep 2019 11:37:23
Message-Id: 20190905113712.4479-1-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH] sgml-catalog-r1.eclass: New eclass to handle SGML catalogs by "Michał Górny"
1 Create a new, simpler eclass to handle SGML catalog installation.
2 Rather than relying on external tool to add/remove catalogs
3 in postinst/postrm, let ebuilds install interim catalogs and just
4 register all installed catalogs.
5
6 Signed-off-by: Michał Górny <mgorny@g.o>
7 ---
8 eclass/sgml-catalog-r1.eclass | 73 +++++++++++++++++++++++++++++++++++
9 1 file changed, 73 insertions(+)
10 create mode 100644 eclass/sgml-catalog-r1.eclass
11
12 diff --git a/eclass/sgml-catalog-r1.eclass b/eclass/sgml-catalog-r1.eclass
13 new file mode 100644
14 index 000000000000..6dc870af629a
15 --- /dev/null
16 +++ b/eclass/sgml-catalog-r1.eclass
17 @@ -0,0 +1,73 @@
18 +# Copyright 2019 Gentoo Authors
19 +# Distributed under the terms of the GNU General Public License v2
20 +
21 +# @ECLASS: sgml-catalog-r1.eclass
22 +# @MAINTAINER:
23 +# Michał Górny <mgorny@g.o>
24 +# @AUTHOR:
25 +# Michał Górny <mgorny@g.o>
26 +# @BLURB: Functions for installing SGML catalogs
27 +# @DESCRIPTION:
28 +# This eclass regenerates /etc/sgml/catalog, /etc/sgml.{,c}env
29 +# and /etc/env.d/93sgmltools-lite as necessary for the DocBook tooling.
30 +# This is done via exported pkg_postinst and pkg_postrm phases.
31 +
32 +case ${EAPI:-0} in
33 + 7) ;;
34 + *) die "Unsupported EAPI=${EAPI} for ${ECLASS}";;
35 +esac
36 +
37 +EXPORT_FUNCTIONS pkg_postinst pkg_postrm
38 +
39 +if [[ ! ${_SGML_CATALOG_R1} ]]; then
40 +
41 +RDEPEND=">=app-text/sgml-common-0.6.3-r7"
42 +
43 +# @FUNCTION: sgml-catalog-r1_update_catalog
44 +# @DESCRIPTION:
45 +# Regenerate /etc/sgml/catalog to include all installed catalogs.
46 +sgml-catalog-r1_update_catalog() {
47 + local shopt_save=$(shopt -p nullglob)
48 + shopt -s nullglob
49 + local cats=( "${EROOT}"/etc/sgml/*.cat )
50 + ${shopt_save}
51 +
52 + if [[ ${#cats[@]} -gt 0 ]]; then
53 + ebegin "Updating ${EROOT}/etc/sgml/catalog"
54 + printf 'CATALOG "%s"\n' "${cats[@]}" > "${T}"/catalog &&
55 + mv "${T}"/catalog "${EROOT}"/etc/sgml/catalog
56 + eend "${?}"
57 + else
58 + ebegin "Removing ${EROOT}/etc/sgml/catalog"
59 + rm "${EROOT}"/etc/sgml/catalog &&
60 + { rmdir "${EROOT}"/etc/sgml &>/dev/null || :; }
61 + eend "${?}"
62 + fi
63 +}
64 +
65 +# @FUNCTION: sgml-catalog-r1_update_env
66 +# @DESCRIPTION:
67 +# Regenerate environment variables and copy them to env.d.
68 +sgml-catalog-r1_update_env() {
69 + # gensgmlenv doesn't support overriding root
70 + if [[ -z ${ROOT} && -x "${EPREFIX}/usr/bin/gensgmlenv" ]]; then
71 + ebegin "Regenerating SGML environment variables"
72 + gensgmlenv &&
73 + grep -v export "${EPREFIX}/etc/sgml/sgml.env" > "${T}"/93sgmltools-lite &&
74 + mv "${T}"/93sgmltools-lite "${EPREFIX}/etc/env.d/93sgmltools-lite"
75 + eend "${?}"
76 + fi
77 +}
78 +
79 +sgml-catalog-r1_pkg_postinst() {
80 + sgml-catalog-r1_update_catalog
81 + sgml-catalog-r1_update_env
82 +}
83 +
84 +sgml-catalog-r1_pkg_postrm() {
85 + sgml-catalog-r1_update_catalog
86 + sgml-catalog-r1_update_env
87 +}
88 +
89 +_SGML_CATALOG_R1=1
90 +fi
91 --
92 2.23.0