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: Wed, 10 Apr 2019 13:21:48
Message-Id: f1402d79825b7caa8b8139dc953fec17046fb573.camel@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH] font.eclass: Port to EAPI-7 by Andreas Sturmlechner
1 On Tue, 2019-04-09 at 21:41 +0200, Andreas Sturmlechner wrote:
2 > On Sonntag, 24. März 2019 19:41:24 CEST Michał Górny wrote:
3 > > -U9999, please. This is a huge eclass and probably requires more work
4 > > than you're showing us ;-).
5 >
6 > As requested, without any changes to v2 - and if this does not receive
7 > a reply I'll assume silent ack by fonts proj.
8 >
9 >
10 > --- a/eclass/font.eclass 2019-04-04 08:28:12.336171811 +0200
11 > +++ b/eclass/font.eclass 2019-03-25 20:34:15.306062926 +0100
12 > @@ -1,254 +1,257 @@
13 > -# Copyright 1999-2015 Gentoo Foundation
14 > +# Copyright 1999-2019 Gentoo Foundation
15 > # Distributed under the terms of the GNU General Public License v2
16 >
17 > # @ECLASS: font.eclass
18 > # @MAINTAINER:
19 > # fonts@g.o
20 > # @BLURB: Eclass to make font installation uniform
21 >
22 > case ${EAPI:-0} in
23 > - 0|1|2|3|4|5|6) ;;
24 > - *) die "EAPI ${EAPI} is not supported by font.eclass." ;;
25 > + 0|1|2|3|4|5|6) inherit eutils ;;
26 > + 7) ;;
27 > + *) die "EAPI ${EAPI} is not supported by font.eclass." ;;
28 > esac
29 >
30 > -inherit eutils
31 > -
32 > EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
33 >
34 > # @ECLASS-VARIABLE: FONT_SUFFIX
35 > # @DEFAULT_UNSET
36 > # @REQUIRED
37 > # @DESCRIPTION:
38 > # Space delimited list of font suffixes to install.
39 > FONT_SUFFIX=${FONT_SUFFIX:-}
40 >
41 > # @ECLASS-VARIABLE: FONT_S
42 > # @REQUIRED
43 > # @DESCRIPTION:
44 > # Space delimited list of directories containing the fonts.
45 > FONT_S=${FONT_S:-${S}}
46 >
47 > # @ECLASS-VARIABLE: FONT_PN
48 > # @DESCRIPTION:
49 > # Font name (ie. last part of FONTDIR).
50 > FONT_PN=${FONT_PN:-${PN}}
51 >
52 > # @ECLASS-VARIABLE: FONTDIR
53 > # @DESCRIPTION:
54 > # Full path to installation directory.
55 > FONTDIR=${FONTDIR:-/usr/share/fonts/${FONT_PN}}
56 >
57 > # @ECLASS-VARIABLE: FONT_CONF
58 > # @DEFAULT_UNSET
59 > # @DESCRIPTION:
60 > # Array containing fontconfig conf files to install.
61 > FONT_CONF=( "" )
62 >
63 > # @ECLASS-VARIABLE: DOCS
64 > # @DEFAULT_UNSET
65 > # @DESCRIPTION:
66 > # Space delimited list of docs to install.
67 > # We always install these:
68 > # COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt
69 > DOCS=${DOCS:-}
70 >
71 > IUSE="X"
72 >
73 > DEPEND="X? (
74 > || ( >=x11-apps/mkfontscale-1.2.0 x11-apps/mkfontdir )
75 > media-fonts/encodings
76 > )"
77 > RDEPEND=""
78 >
79 > # @FUNCTION: font_xfont_config
80 > # @DESCRIPTION:
81 > # Generate Xorg font files (mkfontscale/mkfontdir).
82 > font_xfont_config() {
83 > local dir_name
84 > if has X ${IUSE//+} && use X ; then
85
86 Looks like in_iuse candidate.
87
88 > dir_name="${1:-${FONT_PN}}"
89 > + rm -f "${ED%/}/${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir} \
90 > + || die "failed to prepare ${FONTDIR}/${1//${S}/}"
91 > ebegin "Creating fonts.scale & fonts.dir in ${dir_name##*/}"
92 > - rm -f "${ED}${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir}
93 > - mkfontscale "${ED}${FONTDIR}/${1//${S}/}"
94 > + mkfontscale "${ED%/}/${FONTDIR}/${1//${S}/}" || eerror "failed to create fonts.scale"
95 > mkfontdir \
96 > -e ${EPREFIX}/usr/share/fonts/encodings \
97 > -e ${EPREFIX}/usr/share/fonts/encodings/large \
98 > - "${ED}${FONTDIR}/${1//${S}/}"
99 > - eend $?
100 > - if [[ -e fonts.alias ]] ; then
101 > - doins fonts.alias
102 > + "${ED%/}/${FONTDIR}/${1//${S}/}" || eerror "failed to create fonts.dir"
103 > + if ! eend $? ; then
104 > + die "failed to run mkfontscale or mkfontdir"
105
106 ...but this doesn't catch failure from mkfontscale.
107
108 > fi
109 > + [[ -e fonts.alias ]] && doins fonts.alias
110 > fi
111 > }
112 >
113 > # @FUNCTION: font_fontconfig
114 > # @DESCRIPTION:
115 > # Install fontconfig conf files given in FONT_CONF.
116 > font_fontconfig() {
117 > local conffile
118 > if [[ -n ${FONT_CONF[@]} ]]; then
119 > insinto /etc/fonts/conf.avail/
120 > for conffile in "${FONT_CONF[@]}"; do
121 > [[ -e ${conffile} ]] && doins ${conffile}
122 > done
123 > fi
124 > }
125 >
126 > # @FUNCTION: font_cleanup_dirs
127 > # @DESCRIPTION:
128 > # Remove font directories containing only generated files.
129 > font_cleanup_dirs() {
130 > local genfiles="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale"
131 > # fonts.alias isn't generated but it's a special case (see below).
132 > local d f g generated candidate otherfile
133 >
134 > ebegin "Cleaning up font directories"
135 > - find -L "${EROOT}"usr/share/fonts/ -type d -print0 | while read -d $'\0' d; do
136 > + while read d; do
137
138 read -d $'\0' -r
139
140 > candidate=false
141 > otherfile=false
142 > for f in "${d}"/*; do
143 > generated=false
144 > # make sure this is a file and not a subdir
145 > [[ -e ${f} || -L ${f} ]] || continue
146 > for g in ${genfiles}; do
147
148 Could you use 'has' here?
149
150 > if [[ ${f##*/} == ${g} ]]; then
151 > # this is a generated file
152 > generated=true
153 > break
154 > fi
155 > done
156 > # if the file is a generated file then we know this is a font dir (as
157 > # opposed to something like encodings or util) and a candidate for
158 > # removal. if it's not generated then it's an "otherfile".
159 > ${generated} && candidate=true || otherfile=true
160 > # if the directory is both a candidate for removal and contains at
161 > # least one "otherfile" then don't remove it.
162 > [[ ${candidate} == ${otherfile} ]] && break
163 > done
164 > # if in the end we only have generated files, purge the directory.
165 > if [[ ${candidate} == true && ${otherfile} == false ]]; then
166 > # we don't want to remove fonts.alias files that were installed by
167 > # media-fonts/font-alias. any other fonts.alias files will have
168 > # already been unmerged with their packages.
169 > for g in ${genfiles}; do
170 > - [[ ${g} != fonts.alias && ( -e ${d}/${g} || -L ${d}/${g} ) ]] \
171 > - && rm "${d}"/${g}
172 > + if [[ ${g} != fonts.alias && ( -e ${d}/${g} || -L ${d}/${g} ) ]] ; then
173 > + rm "${d}"/${g} || eerror "failed to remove ${d}/${g}"
174 > + fi
175 > done
176 > # if there's nothing left remove the directory
177 > - find "${d}" -maxdepth 0 -type d -empty -exec rmdir '{}' \;
178 > + find "${d}" -maxdepth 0 -type d -empty -delete || eerror "failed to purge ${d}"
179 > fi
180 > - done
181 > + done < <(find -L "${EROOT%/}"/usr/share/fonts/ -type d -print0)
182 > eend 0
183 > }
184 >
185 > # @FUNCTION: font_pkg_setup
186 > # @DESCRIPTION:
187 > # The font pkg_setup function.
188 > # Collision protection and Prefix compat for eapi < 3.
189 > font_pkg_setup() {
190 > # Prefix compat
191 > case ${EAPI:-0} in
192 > 0|1|2)
193 > if ! use prefix; then
194 > EPREFIX=
195 > ED=${D}
196 > EROOT=${ROOT}
197 > [[ ${EROOT} = */ ]] || EROOT+="/"
198 > fi
199 > ;;
200 > esac
201
202 This is really ugly but I guess you can ignore it.
203
204 >
205 > # make sure we get no collisions
206 > # setup is not the nicest place, but preinst doesn't cut it
207 > - [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1"
208 > + if [[ -e "${EROOT%/}/${FONTDIR}/fonts.cache-1" ]] ; then
209 > + rm "${EROOT%/}/${FONTDIR}/fonts.cache-1" || die "failed to remove fonts.cache-1"
210 > + fi
211 > }
212 >
213 > # @FUNCTION: font_src_install
214 > # @DESCRIPTION:
215 > # The font src_install function.
216 > font_src_install() {
217 > local dir suffix commondoc
218 >
219 > set -- ${FONT_S:-${S}}
220 > if [[ $# -gt 1 ]]; then
221 > # if we have multiple FONT_S elements then we want to recreate the dir
222 > # structure
223 > for dir in ${FONT_S}; do
224 > pushd "${dir}" > /dev/null
225 > insinto "${FONTDIR}/${dir//${S}/}"
226 > for suffix in ${FONT_SUFFIX}; do
227 > doins *.${suffix}
228
229 Old EAPIs need ||die.
230
231 > done
232 > font_xfont_config "${dir}"
233 > popd > /dev/null
234 > done
235 > else
236 > pushd "${FONT_S}" > /dev/null
237 > insinto "${FONTDIR}"
238 > for suffix in ${FONT_SUFFIX}; do
239 > doins *.${suffix}
240
241 Likewise.
242
243 > done
244 > font_xfont_config
245 > popd > /dev/null
246 > fi
247 >
248 > font_fontconfig
249 >
250 > - [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
251 > + [[ -n ${DOCS} ]] && dodoc ${DOCS}
252
253 I suppose this kills proper support for old EAPIs.
254
255 >
256 > # install common docs
257 > for commondoc in COPYRIGHT README{,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
258 > [[ -s ${commondoc} ]] && dodoc ${commondoc}
259 > done
260 > }
261 >
262 > +# @FUNCTION: _update_fontcache
263 > +# @DESCRIPTION:
264 > +# Updates fontcache if !prefix and media-libs/fontconfig installed
265 > +_update_fontcache() {
266 > + # unreadable font files = fontconfig segfaults
267 > + find "${EROOT%/}"/usr/share/fonts/ -type f '!' -perm 0644 \
268 > + -exec chmod -v 0644 2>/dev/null {} + || die "failed to fix font files perms"
269 > +
270 > + if [[ -z ${ROOT%/} ]] ; then
271 > + if has_version media-libs/fontconfig ; then
272 > + ebegin "Updating global fontcache"
273 > + fc-cache -fs
274 > + if ! eend $? ; then
275 > + die "failed to update global fontcache"
276 > + fi
277 > + else
278 > + einfo "Skipping fontcache update (media-libs/fontconfig not installed)"
279 > + fi
280 > + else
281 > + einfo "Skipping fontcache update (ROOT != /)"
282 > + fi
283 > +}
284 > +
285 > # @FUNCTION: font_pkg_postinst
286 > # @DESCRIPTION:
287 > # The font pkg_postinst function.
288 > font_pkg_postinst() {
289 > - # unreadable font files = fontconfig segfaults
290 > - find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
291 > - | xargs -0 chmod -v 0644 2>/dev/null
292 > -
293 > if [[ -n ${FONT_CONF[@]} ]]; then
294 > local conffile
295 > - echo
296 > elog "The following fontconfig configuration files have been installed:"
297 > elog
298 > for conffile in "${FONT_CONF[@]}"; do
299 > - if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then
300 > - elog " $(basename ${conffile})"
301 > + if [[ -e "${EROOT%/}"/etc/fonts/conf.avail/${conffile##*/} ]]; then
302 > + elog " ${conffile##*/}"
303 > fi
304 > done
305 > elog
306 > elog "Use \`eselect fontconfig\` to enable/disable them."
307 > - echo
308 > fi
309 >
310 > - if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
311 > - ebegin "Updating global fontcache"
312 > - fc-cache -fs
313 > - eend $?
314 > - else
315 > - einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
316 > - fi
317 > + _update_fontcache
318 > }
319 >
320 > # @FUNCTION: font_pkg_postrm
321 > # @DESCRIPTION:
322 > # The font pkg_postrm function.
323 > font_pkg_postrm() {
324 > font_cleanup_dirs
325 > -
326 > - # unreadable font files = fontconfig segfaults
327 > - find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
328 > - | xargs -0 chmod -v 0644 2>/dev/null
329 > -
330 > - if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
331 > - ebegin "Updating global fontcache"
332 > - fc-cache -fs
333 > - eend $?
334 > - else
335 > - einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
336 > - fi
337 > + _update_fontcache
338 > }
339 >
340 >
341 >
342 >
343
344 --
345 Best regards,
346 Michał Górny

Attachments

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

Replies