Gentoo Archives: gentoo-dev

From: Andreas Sturmlechner <asturm@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH v2] font.eclass: Port to EAPI-7
Date: Tue, 15 Oct 2019 22:05:57
Message-Id: 1597215.ePjIQn5g5U@tuxbrain
In Reply to: Re: [gentoo-dev] [PATCH] font.eclass: Port to EAPI-7 by "Michał Górny"
1 (ignore previous mail, this time hopefully not scrambled)
2
3 --- a/eclass/font.eclass
4 +++ b/eclass/font.eclass
5 @@ -4,16 +4,15 @@
6 # @ECLASS: font.eclass
7 # @MAINTAINER:
8 # fonts@g.o
9 -# @SUPPORTED_EAPIS: 0 1 2 3 4 5 6
10 +# @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
11 # @BLURB: Eclass to make font installation uniform
12
13 case ${EAPI:-0} in
14 - 0|1|2|3|4|5|6) ;;
15 - *) die "EAPI ${EAPI} is not supported by font.eclass." ;;
16 + 0|1|2|3|4|5|6) inherit eutils ;;
17 + 7) ;;
18 + *) die "EAPI ${EAPI} is not supported by font.eclass." ;;
19 esac
20
21 -inherit eutils
22 -
23 EXPORT_FUNCTIONS pkg_setup src_install pkg_postinst pkg_postrm
24
25 # @ECLASS-VARIABLE: FONT_SUFFIX
26 @@ -67,18 +66,18 @@ fi
27 # Generate Xorg font files (mkfontscale/mkfontdir).
28 font_xfont_config() {
29 local dir_name
30 - if has X ${IUSE//+} && use X ; then
31 + if in_iuse X && use X ; then
32 dir_name="${1:-${FONT_PN}}"
33 - ebegin "Creating fonts.scale & fonts.dir in ${dir_name##*/}"
34 - rm -f "${ED}${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir}
35 - mkfontscale "${ED}${FONTDIR}/${1//${S}/}"
36 + rm -f "${ED%/}/${FONTDIR}/${1//${S}/}"/{fonts.{dir,scale},encodings.dir} \
37 + || die "failed to prepare ${FONTDIR}/${1//${S}/}"
38 + einfo "Creating fonts.scale & fonts.dir in ${dir_name##*/}"
39 + mkfontscale "${ED%/}/${FONTDIR}/${1//${S}/}" || eerror "failed to create fonts.scale"
40 mkfontdir \
41 -e ${EPREFIX}/usr/share/fonts/encodings \
42 -e ${EPREFIX}/usr/share/fonts/encodings/large \
43 - "${ED}${FONTDIR}/${1//${S}/}"
44 - eend $?
45 - if [[ -e fonts.alias ]] ; then
46 - doins fonts.alias
47 + "${ED%/}/${FONTDIR}/${1//${S}/}" || eerror "failed to create fonts.dir"
48 + if [[ -e fonts.alias ]]; then
49 + doins fonts.alias || die "failed to install fonts.alias" # TODO old EAPI cleanup
50 fi
51 fi
52 }
53 @@ -91,7 +90,9 @@ font_fontconfig() {
54 if [[ -n ${FONT_CONF[@]} ]]; then
55 insinto /etc/fonts/conf.avail/
56 for conffile in "${FONT_CONF[@]}"; do
57 - [[ -e ${conffile} ]] && doins ${conffile}
58 + if [[ -e ${conffile} ]]; then
59 + doins ${conffile} || die "failed to install conf file" # TODO old EAPI cleanup
60 + fi
61 done
62 fi
63 }
64 @@ -105,20 +106,18 @@ font_cleanup_dirs() {
65 local d f g generated candidate otherfile
66
67 ebegin "Cleaning up font directories"
68 - find -L "${EROOT}"usr/share/fonts/ -type d -print0 | while read -d $'\0' d; do
69 + while read -d $'\0' -r; do
70 candidate=false
71 otherfile=false
72 for f in "${d}"/*; do
73 generated=false
74 # make sure this is a file and not a subdir
75 [[ -e ${f} || -L ${f} ]] || continue
76 - for g in ${genfiles}; do
77 - if [[ ${f##*/} == ${g} ]]; then
78 - # this is a generated file
79 - generated=true
80 - break
81 - fi
82 - done
83 + if has ${f##*/} ${genfiles}; then
84 + # this is a generated file
85 + generated=true
86 + break
87 + fi
88 # if the file is a generated file then we know this is a font dir (as
89 # opposed to something like encodings or util) and a candidate for
90 # removal. if it's not generated then it's an "otherfile".
91 @@ -133,13 +132,14 @@ font_cleanup_dirs() {
92 # media-fonts/font-alias. any other fonts.alias files will have
93 # already been unmerged with their packages.
94 for g in ${genfiles}; do
95 - [[ ${g} != fonts.alias && ( -e ${d}/${g} || -L ${d}/${g} ) ]] \
96 - && rm "${d}"/${g}
97 + if [[ ${g} != fonts.alias && ( -e ${d}/${g} || -L ${d}/${g} ) ]] ; then
98 + rm "${d}"/${g} || eerror "failed to remove ${d}/${g}"
99 + fi
100 done
101 # if there's nothing left remove the directory
102 - find "${d}" -maxdepth 0 -type d -empty -exec rmdir '{}' \;
103 + find "${d}" -maxdepth 0 -type d -empty -delete || eerror "failed to purge ${d}"
104 fi
105 - done
106 + done < <(find -L "${EROOT%/}"/usr/share/fonts/ -type d -print0)
107 eend 0
108 }
109
110 @@ -162,7 +162,9 @@ font_pkg_setup() {
111
112 # make sure we get no collisions
113 # setup is not the nicest place, but preinst doesn't cut it
114 - [[ -e "${EROOT}/${FONTDIR}/fonts.cache-1" ]] && rm -f "${EROOT}/${FONTDIR}/fonts.cache-1"
115 + if [[ -e "${EROOT%/}/${FONTDIR}/fonts.cache-1" ]] ; then
116 + rm "${EROOT%/}/${FONTDIR}/fonts.cache-1" || die "failed to remove fonts.cache-1"
117 + fi
118 }
119
120 # @FUNCTION: font_src_install
121 @@ -179,7 +181,7 @@ font_src_install() {
122 pushd "${dir}" > /dev/null
123 insinto "${FONTDIR}/${dir//${S}/}"
124 for suffix in ${FONT_SUFFIX}; do
125 - doins *.${suffix}
126 + doins *.${suffix} || die "font installation failed" # TODO old EAPI cleanup
127 done
128 font_xfont_config "${dir}"
129 popd > /dev/null
130 @@ -188,7 +190,7 @@ font_src_install() {
131 pushd "${FONT_S}" > /dev/null
132 insinto "${FONTDIR}"
133 for suffix in ${FONT_SUFFIX}; do
134 - doins *.${suffix}
135 + doins *.${suffix} || die "font installation failed" # TODO old EAPI cleanup
136 done
137 font_xfont_config
138 popd > /dev/null
139 @@ -196,7 +198,7 @@ font_src_install() {
140
141 font_fontconfig
142
143 - [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; }
144 + [[ -n ${DOCS} ]] && { dodoc ${DOCS} || die "docs installation failed" ; } # TODO old EAPI cleanup
145
146 # install common docs
147 for commondoc in COPYRIGHT README{,.md,.txt} NEWS AUTHORS BUGS ChangeLog FONTLOG.txt; do
148 @@ -204,36 +206,47 @@ font_src_install() {
149 done
150 }
151
152 +# @FUNCTION: _update_fontcache
153 +# @DESCRIPTION:
154 +# Updates fontcache if !prefix and media-libs/fontconfig installed
155 +_update_fontcache() {
156 + # unreadable font files = fontconfig segfaults
157 + find "${EROOT%/}"/usr/share/fonts/ -type f '!' -perm 0644 \
158 + -exec chmod -v 0644 2>/dev/null {} + || die "failed to fix font files perms"
159 +
160 + if [[ -z ${ROOT%/} ]] ; then
161 + if has_version media-libs/fontconfig ; then
162 + ebegin "Updating global fontcache"
163 + fc-cache -fs
164 + if ! eend $? ; then
165 + die "failed to update global fontcache"
166 + fi
167 + else
168 + einfo "Skipping fontcache update (media-libs/fontconfig not installed)"
169 + fi
170 + else
171 + einfo "Skipping fontcache update (ROOT != /)"
172 + fi
173 +}
174 +
175 # @FUNCTION: font_pkg_postinst
176 # @DESCRIPTION:
177 # The font pkg_postinst function.
178 font_pkg_postinst() {
179 - # unreadable font files = fontconfig segfaults
180 - find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
181 - | xargs -0 chmod -v 0644 2>/dev/null
182 -
183 if [[ -n ${FONT_CONF[@]} ]]; then
184 local conffile
185 - echo
186 elog "The following fontconfig configuration files have been installed:"
187 elog
188 for conffile in "${FONT_CONF[@]}"; do
189 - if [[ -e ${EROOT}etc/fonts/conf.avail/$(basename ${conffile}) ]]; then
190 - elog " $(basename ${conffile})"
191 + if [[ -e "${EROOT%/}"/etc/fonts/conf.avail/${conffile##*/} ]]; then
192 + elog " ${conffile##*/}"
193 fi
194 done
195 elog
196 elog "Use \`eselect fontconfig\` to enable/disable them."
197 - echo
198 fi
199
200 - if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
201 - ebegin "Updating global fontcache"
202 - fc-cache -fs
203 - eend $?
204 - else
205 - einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
206 - fi
207 + _update_fontcache
208 }
209
210 # @FUNCTION: font_pkg_postrm
211 @@ -241,16 +254,5 @@ font_pkg_postinst() {
212 # The font pkg_postrm function.
213 font_pkg_postrm() {
214 font_cleanup_dirs
215 -
216 - # unreadable font files = fontconfig segfaults
217 - find "${EROOT}"usr/share/fonts/ -type f '!' -perm 0644 -print0 \
218 - | xargs -0 chmod -v 0644 2>/dev/null
219 -
220 - if has_version media-libs/fontconfig && [[ ${ROOT} == / ]]; then
221 - ebegin "Updating global fontcache"
222 - fc-cache -fs
223 - eend $?
224 - else
225 - einfo "Skipping fontcache update (media-libs/fontconfig is not installed or ROOT != /)"
226 - fi
227 + _update_fontcache
228 }

Replies

Subject Author
Re: [gentoo-dev] [PATCH v2] font.eclass: Port to EAPI-7 "Michał Górny" <mgorny@g.o>