Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH] font.eclass: Port to EAPI-7
Date: Sun, 24 Mar 2019 18:41:35
Message-Id: 5ccc85650ff65a817046f5d81dd3ba20b3968158.camel@gentoo.org
In Reply to: [gentoo-dev] [PATCH] font.eclass: Port to EAPI-7 by Andreas Sturmlechner
1 On Sun, 2019-03-24 at 18:17 +0100, Andreas Sturmlechner wrote:
2 > ---
3 > eclass/font.eclass | 57 +++++++++++++++++++++++-----------------------
4 > 1 file changed, 28 insertions(+), 29 deletions(-)
5
6 -U9999, please. This is a huge eclass and probably requires more work
7 than you're showing us ;-).
8
9 >
10 > diff --git a/eclass/font.eclass b/eclass/font.eclass
11 > index 58ec9e3..622f143 100644
12 > --- a/eclass/font.eclass
13 > +++ b/eclass/font.eclass
14 > @@ -1,4 +1,4 @@
15 > -# Copyright 1999-2015 Gentoo Foundation
16 > +# Copyright 1999-2019 Gentoo Foundation
17 > # Distributed under the terms of the GNU General Public License v2
18 >
19 > # @ECLASS: font.eclass
20 > @@ -7,12 +7,11 @@
21 > # @BLURB: Eclass to make font installation uniform
22 >
23 > case ${EAPI:-0} in
24 > - 0|1|2|3|4|5|6) ;;
25 > - *) die "EAPI ${EAPI} is not supported by font.eclass." ;;
26 > + 0|1|2|3|4|5|6) inherit eutils ;;
27 > + 7) ;;
28 > + *) die "EAPI ${EAPI} is not supported by font.eclass." ;;
29 > esac
30 >
31 > -inherit eutils
32 > -
33 > EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
34 >
35 > # @ECLASS-VARIABLE: FONT_SUFFIX
36 > @@ -68,12 +67,12 @@ font_xfont_config() {
37 > if has X ${IUSE//+} && use X ; then
38 > dir_name="${1:-${FONT_PN}}"
39 > ebegin "Creating fonts.scale & fonts.dir in ${dir_name##*/}"
40 > - rm -f "${ED}${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir}
41 > - mkfontscale "${ED}${FONTDIR}/${1//${S}/}"
42 > + rm -f "${ED%/}/${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir}
43 > + mkfontscale "${ED%/}/${FONTDIR}/${1//${S}/}"
44 > mkfontdir \
45 > -e ${EPREFIX}/usr/share/fonts/encodings \
46 > -e ${EPREFIX}/usr/share/fonts/encodings/large \
47 > - "${ED}${FONTDIR}/${1//${S}/}"
48 > + "${ED%/}/${FONTDIR}/${1//${S}/}"
49 > eend $?
50 > if [[ -e fonts.alias ]] ; then
51 > doins fonts.alias
52
53 Would it make sense to add some error handling? It seems silly to try
54 to do a few things, then report one $? for the last of them,
55 independently of whether previous actions succeeded or failed.
56
57 > @@ -103,7 +102,7 @@ font_cleanup_dirs() {
58 > local d f g generated candidate otherfile
59 >
60 > ebegin "Cleaning up font directories"
61 > - find -L "${EROOT}"usr/share/fonts/ -type d -print0 | while read -d $'\0' d; do
62 > + find -L "${EROOT%/}"/usr/share/fonts/ -type d -print0 | while read -d $'\0' d; do
63
64 Move while to primary shell, and use < <(find ...).
65
66 > candidate=false
67 > otherfile=false
68 > for f in "${d}"/*; do
69 > @@ -160,7 +159,7 @@ font_pkg_setup() {
70 >
71 > # make sure we get no collisions
72 > # setup is not the nicest place, but preinst doesn't cut it
73 > - [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1"
74 > + [[ -e "${EROOT%/}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT%/}/${FONTDIR}/fonts.cache-1"
75
76 What's the point of checking the existence, if you pass '-f' to rm
77 anyway?
78
79 > }
80 >
81 > # @FUNCTION: font_src_install
82 > @@ -202,36 +201,42 @@ font_src_install() {
83 > done
84 > }
85 >
86 > +# @FUNCTION: _update_fontcache
87 > +# @DESCRIPTION:
88 > +# Updates fontcache if !prefix and media-libs/fontconfig installed
89 > +_update_fontcache() {
90 > + # TODO: cleanup after <EAPI-7 is banned
91 > + if has_version media-libs/fontconfig && { [[ -z ${ROOT} ]] || [[ ${ROOT} == / ]] ; } then
92
93 [[ -z ${ROOT} || ${ROOT} == / ]] is valid in bash.
94
95 [[ -z ${ROOT%/} ]] is shorter.
96
97 > + ebegin "Updating global fontcache"
98 > + fc-cache -fs
99 > + eend $?
100 > + else
101 > + einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
102 > + fi
103 > +}
104 > +
105 > # @FUNCTION: font_pkg_postinst
106 > # @DESCRIPTION:
107 > # The font pkg_postinst function.
108 > font_pkg_postinst() {
109 > # unreadable font files = fontconfig segfaults
110 > - find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
111 > + find "${EROOT%/}"/usr/share/fonts/ -type f '!' -perm 0644 -print0 \
112 > | xargs -0 chmod -v 0644 2>/dev/null
113
114 find ... -exec chmod ... {} +
115
116 >
117 > if [[ -n ${FONT_CONF[@]} ]]; then
118 > local conffile
119 > - echo
120 > elog "The following fontconfig configuration files have been installed:"
121 > elog
122 > for conffile in "${FONT_CONF[@]}"; do
123 > - if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then
124 > + if [[ -e ${EROOT%/}/etc/fonts/conf.avail/$(basename ${conffile}) ]]; then
125
126 Don't call basename if you can do the same via ${conffile##*/}.
127
128 > elog " $(basename ${conffile})"
129 > fi
130 > done
131 > elog
132 > elog "Use \`eselect fontconfig\` to enable/disable them."
133 > - echo
134 > fi
135 >
136 > - if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
137 > - ebegin "Updating global fontcache"
138 > - fc-cache -fs
139 > - eend $?
140 > - else
141 > - einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
142 > - fi
143 > + _update_fontcache
144 > }
145 >
146 > # @FUNCTION: font_pkg_postrm
147 > @@ -241,14 +246,8 @@ font_pkg_postrm() {
148 > font_cleanup_dirs
149 >
150 > # unreadable font files = fontconfig segfaults
151 > - find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
152 > + find "${EROOT%/}"/usr/share/fonts/ -type f '!' -perm 0644 -print0 \
153 > | xargs -0 chmod -v 0644 2>/dev/null
154
155 Likewise. Also, wouldn't it make sense to put it inside
156 _update_fontcache()? It seems identical here and in postinst.
157
158 >
159 > - if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
160 > - ebegin "Updating global fontcache"
161 > - fc-cache -fs
162 > - eend $?
163 > - else
164 > - einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
165 > - fi
166 > + _update_fontcache
167 > }
168
169 --
170 Best regards,
171 Michał Górny

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies