x11-terms/mlterm: Fix typo in metadata.xml
[gentoo.git] / eclass / gnome2-utils.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: gnome2-utils.eclass
5 # @MAINTAINER:
6 # gnome@gentoo.org
7 # @BLURB: Auxiliary functions commonly used by Gnome packages.
8 # @DESCRIPTION:
9 # This eclass provides a set of auxiliary functions needed by most Gnome
10 # packages. It may be used by non-Gnome packages as needed for handling various
11 # Gnome stack related functions such as:
12 #  * Gtk+ icon cache management
13 #  * GSettings schemas management
14 #  * GConf schemas management
15 #  * scrollkeeper (old Gnome help system) management
16
17 [[ ${EAPI:-0} == [012345] ]] && inherit multilib
18 inherit eutils xdg-utils
19
20 case "${EAPI:-0}" in
21         0|1|2|3|4|5|6) ;;
22         *) die "EAPI=${EAPI} is not supported" ;;
23 esac
24
25 # @ECLASS-VARIABLE: GCONFTOOL_BIN
26 # @INTERNAL
27 # @DESCRIPTION:
28 # Path to gconftool-2
29 : ${GCONFTOOL_BIN:="/usr/bin/gconftool-2"}
30
31 # @ECLASS-VARIABLE: SCROLLKEEPER_DIR
32 # @INTERNAL
33 # @DESCRIPTION:
34 # Directory where scrollkeeper-update should do its work
35 : ${SCROLLKEEPER_DIR:="/var/lib/scrollkeeper"}
36
37 # @ECLASS-VARIABLE: SCROLLKEEPER_UPDATE_BIN
38 # @INTERNAL
39 # @DESCRIPTION:
40 # Path to scrollkeeper-update
41 : ${SCROLLKEEPER_UPDATE_BIN:="/usr/bin/scrollkeeper-update"}
42
43 # @ECLASS-VARIABLE: GTK_UPDATE_ICON_CACHE
44 # @INTERNAL
45 # @DESCRIPTION:
46 # Path to gtk-update-icon-cache
47 : ${GTK_UPDATE_ICON_CACHE:="/usr/bin/gtk-update-icon-cache"}
48
49 # @ECLASS-VARIABLE: GLIB_COMPILE_SCHEMAS
50 # @INTERNAL
51 # @DESCRIPTION:
52 # Path to glib-compile-schemas
53 : ${GLIB_COMPILE_SCHEMAS:="/usr/bin/glib-compile-schemas"}
54
55 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCHEMAS
56 # @INTERNAL
57 # @DEFAULT_UNSET
58 # @DESCRIPTION:
59 # List of GConf schemas provided by the package
60
61 # @ECLASS-VARIABLE: GNOME2_ECLASS_ICONS
62 # @INTERNAL
63 # @DEFAULT_UNSET
64 # @DESCRIPTION:
65 # List of icons provided by the package
66
67 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCROLLS
68 # @INTERNAL
69 # @DEFAULT_UNSET
70 # @DESCRIPTION:
71 # List of scrolls (documentation files) provided by the package
72
73 # @ECLASS-VARIABLE: GNOME2_ECLASS_GLIB_SCHEMAS
74 # @INTERNAL
75 # @DEFAULT_UNSET
76 # @DESCRIPTION:
77 # List of GSettings schemas provided by the package
78
79 # @ECLASS-VARIABLE: GNOME2_ECLASS_GDK_PIXBUF_LOADERS
80 # @INTERNAL
81 # @DEFAULT_UNSET
82 # @DESCRIPTION:
83 # List of gdk-pixbuf loaders provided by the package
84
85 DEPEND=">=sys-apps/sed-4"
86
87
88 # @FUNCTION: gnome2_environment_reset
89 # @DESCRIPTION:
90 # Reset various variables inherited from root's evironment to a reasonable
91 # default for ebuilds to help avoid access violations and test failures.
92 gnome2_environment_reset() {
93         xdg_environment_reset
94
95         # Respected by >=glib-2.30.1-r1
96         export G_HOME="${T}"
97
98         # GST_REGISTRY is to work around gst utilities trying to read/write /root
99         export GST_REGISTRY="${T}/registry.xml"
100
101         # Ensure we don't rely on dconf/gconf while building, bug #511946
102         export GSETTINGS_BACKEND="memory"
103
104         if has ${EAPI:-0} 6; then
105                 # Try to cover the packages honoring this variable, bug #508124
106                 export GST_INSPECT="$(type -P true)"
107
108                 # Stop relying on random DISPLAY variable values, bug #534312
109                 unset DISPLAY
110         fi
111 }
112
113 # @FUNCTION: gnome2_gconf_savelist
114 # @DESCRIPTION:
115 # Find the GConf schemas that are about to be installed and save their location
116 # in the GNOME2_ECLASS_SCHEMAS environment variable.
117 # This function should be called from pkg_preinst.
118 gnome2_gconf_savelist() {
119         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
120         pushd "${ED}" > /dev/null || die
121         export GNOME2_ECLASS_SCHEMAS=$(find 'etc/gconf/schemas/' -name '*.schemas' 2> /dev/null)
122         popd > /dev/null || die
123 }
124
125 # @FUNCTION: gnome2_gconf_install
126 # @DESCRIPTION:
127 # Applies any schema files installed by the current ebuild to Gconf's database
128 # using gconftool-2.
129 # This function should be called from pkg_postinst.
130 gnome2_gconf_install() {
131         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
132         local updater="${EROOT}${GCONFTOOL_BIN}"
133
134         if [[ ! -x "${updater}" ]]; then
135                 debug-print "${updater} is not executable"
136                 return
137         fi
138
139         if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
140                 debug-print "No GNOME 2 GConf schemas found"
141                 return
142         fi
143
144         # We are ready to install the GCONF Scheme now
145         unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
146         export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
147
148         einfo "Installing GNOME 2 GConf schemas"
149
150         local F
151         for F in ${GNOME2_ECLASS_SCHEMAS}; do
152                 if [[ -e "${EROOT}${F}" ]]; then
153                         debug-print "Installing schema: ${F}"
154                         "${updater}" --makefile-install-rule "${EROOT}${F}" 1>/dev/null
155                 fi
156         done
157
158         # have gconf reload the new schemas
159         pids=$(pgrep -x gconfd-2)
160         if [[ $? == 0 ]] ; then
161                 ebegin "Reloading GConf schemas"
162                 kill -HUP ${pids}
163                 eend $?
164         fi
165 }
166
167 # @FUNCTION: gnome2_gconf_uninstall
168 # @DESCRIPTION:
169 # Removes schema files previously installed by the current ebuild from Gconf's
170 # database.
171 gnome2_gconf_uninstall() {
172         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
173         local updater="${EROOT}${GCONFTOOL_BIN}"
174
175         if [[ ! -x "${updater}" ]]; then
176                 debug-print "${updater} is not executable"
177                 return
178         fi
179
180         if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
181                 debug-print "No GNOME 2 GConf schemas found"
182                 return
183         fi
184
185         unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
186         export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
187
188         einfo "Uninstalling GNOME 2 GConf schemas"
189
190         local F
191         for F in ${GNOME2_ECLASS_SCHEMAS}; do
192                 if [[ -e "${EROOT}${F}" ]]; then
193                         debug-print "Uninstalling gconf schema: ${F}"
194                         "${updater}" --makefile-uninstall-rule "${EROOT}${F}" 1>/dev/null
195                 fi
196         done
197
198         # have gconf reload the new schemas
199         pids=$(pgrep -x gconfd-2)
200         if [[ $? == 0 ]] ; then
201                 ebegin "Reloading GConf schemas"
202                 kill -HUP ${pids}
203                 eend $?
204         fi
205 }
206
207 # @FUNCTION: gnome2_icon_savelist
208 # @DESCRIPTION:
209 # Find the icons that are about to be installed and save their location
210 # in the GNOME2_ECLASS_ICONS environment variable. This is only
211 # necessary for eclass implementations that call
212 # gnome2_icon_cache_update conditionally.
213 # This function should be called from pkg_preinst.
214 gnome2_icon_savelist() {
215         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
216         pushd "${ED}" > /dev/null || die
217         export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
218         popd > /dev/null || die
219 }
220
221 # @FUNCTION: gnome2_icon_cache_update
222 # @DESCRIPTION:
223 # Updates Gtk+ icon cache files under /usr/share/icons.
224 # This function should be called from pkg_postinst and pkg_postrm.
225 gnome2_icon_cache_update() {
226         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
227         local updater="${EROOT}${GTK_UPDATE_ICON_CACHE}"
228
229         if [[ ! -x "${updater}" ]] ; then
230                 debug-print "${updater} is not executable"
231                 return
232         fi
233
234         ebegin "Updating icons cache"
235
236         local retval=0
237         local fails=( )
238
239         for dir in "${EROOT%/}"/usr/share/icons/*
240         do
241                 if [[ -f "${dir}/index.theme" ]] ; then
242                         local rv=0
243
244                         "${updater}" -qf "${dir}"
245                         rv=$?
246
247                         if [[ ! $rv -eq 0 ]] ; then
248                                 debug-print "Updating cache failed on ${dir}"
249
250                                 # Add to the list of failures
251                                 fails+=( "${dir}" )
252
253                                 retval=2
254                         fi
255                 elif [[ $(ls "${dir}") = "icon-theme.cache" ]]; then
256                         # Clear stale cache files after theme uninstallation
257                         rm "${dir}/icon-theme.cache"
258                 fi
259
260                 if [[ -z $(ls "${dir}") ]]; then
261                         # Clear empty theme directories after theme uninstallation
262                         rmdir "${dir}"
263                 fi
264         done
265
266         eend ${retval}
267
268         for f in "${fails[@]}" ; do
269                 eerror "Failed to update cache with icon $f"
270         done
271 }
272
273 # @FUNCTION: gnome2_omf_fix
274 # @DESCRIPTION:
275 # Workaround applied to Makefile rules in order to remove redundant
276 # calls to scrollkeeper-update and sandbox violations.
277 # This function should be called from src_prepare.
278 gnome2_omf_fix() {
279         local omf_makefiles filename
280
281         omf_makefiles="$@"
282
283         if [[ -f ${S}/omf.make ]] ; then
284                 omf_makefiles="${omf_makefiles} ${S}/omf.make"
285         fi
286
287         if [[ -f ${S}/gnome-doc-utils.make ]] ; then
288                 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
289         fi
290
291         # testing fixing of all makefiles found
292         # The sort is important to ensure .am is listed before the respective .in for
293         # maintainer mode regeneration not kicking in due to .am being newer than .in
294         for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
295                 omf_makefiles="${omf_makefiles} ${filename}"
296         done
297
298         ebegin "Fixing OMF Makefiles"
299
300         local retval=0
301         local fails=( )
302
303         for omf in ${omf_makefiles} ; do
304                 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
305                 retval=$?
306
307                 if [[ $retval -ne 0 ]] ; then
308                         debug-print "updating of ${omf} failed"
309
310                         # Add to the list of failures
311                         fails[$(( ${#fails[@]} + 1 ))]=$omf
312
313                         retval=2
314                 fi
315         done
316
317         eend $retval
318
319         for f in "${fails[@]}" ; do
320                 eerror "Failed to update OMF Makefile $f"
321         done
322 }
323
324 # @FUNCTION: gnome2_scrollkeeper_savelist
325 # @DESCRIPTION:
326 # Find the scrolls that are about to be installed and save their location
327 # in the GNOME2_ECLASS_SCROLLS environment variable.
328 # This function should be called from pkg_preinst.
329 gnome2_scrollkeeper_savelist() {
330         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
331         pushd "${ED}" > /dev/null || die
332         export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null)
333         popd > /dev/null || die
334 }
335
336 # @FUNCTION: gnome2_scrollkeeper_update
337 # @DESCRIPTION:
338 # Updates the global scrollkeeper database.
339 # This function should be called from pkg_postinst and pkg_postrm.
340 gnome2_scrollkeeper_update() {
341         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
342         local updater="${EROOT}${SCROLLKEEPER_UPDATE_BIN}"
343
344         if [[ ! -x "${updater}" ]] ; then
345                 debug-print "${updater} is not executable"
346                 return
347         fi
348
349         if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
350                 debug-print "No scroll cache to update"
351                 return
352         fi
353
354         ebegin "Updating scrollkeeper database ..."
355         "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
356         eend $?
357 }
358
359 # @FUNCTION: gnome2_schemas_savelist
360 # @DESCRIPTION:
361 # Find if there is any GSettings schema to install and save the list in
362 # GNOME2_ECLASS_GLIB_SCHEMAS variable. This is only necessary for eclass
363 # implementations that call gnome2_schemas_update conditionally.
364 # This function should be called from pkg_preinst.
365 gnome2_schemas_savelist() {
366         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
367         pushd "${ED}" > /dev/null || die
368         export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
369         popd > /dev/null || die
370 }
371
372 # @FUNCTION: gnome2_schemas_update
373 # @USAGE: gnome2_schemas_update
374 # @DESCRIPTION:
375 # Updates GSettings schemas.
376 # This function should be called from pkg_postinst and pkg_postrm.
377 gnome2_schemas_update() {
378         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
379         local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}"
380
381         if [[ ! -x ${updater} ]]; then
382                 debug-print "${updater} is not executable"
383                 return
384         fi
385
386         ebegin "Updating GSettings schemas"
387         ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
388         eend $?
389 }
390
391 # @FUNCTION: gnome2_gdk_pixbuf_savelist
392 # @DESCRIPTION:
393 # Find if there is any gdk-pixbuf loader to install and save the list in
394 # GNOME2_ECLASS_GDK_PIXBUF_LOADERS variable.
395 # This function should be called from pkg_preinst.
396 gnome2_gdk_pixbuf_savelist() {
397         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
398         pushd "${ED}" > /dev/null || die
399         export GNOME2_ECLASS_GDK_PIXBUF_LOADERS=$(find usr/lib*/gdk-pixbuf-2.0 -type f 2>/dev/null)
400         popd > /dev/null || die
401 }
402
403 # @FUNCTION: gnome2_gdk_pixbuf_update
404 # @USAGE: gnome2_gdk_pixbuf_update
405 # @DESCRIPTION:
406 # Updates gdk-pixbuf loader cache if GNOME2_ECLASS_GDK_PIXBUF_LOADERS has some.
407 # This function should be called from pkg_postinst and pkg_postrm.
408 gnome2_gdk_pixbuf_update() {
409         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
410         local updater="${EROOT}/usr/bin/${CHOST}-gdk-pixbuf-query-loaders"
411
412         if [[ ! -x ${updater} ]]; then
413                 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
414         fi
415
416         if [[ ! -x ${updater} ]]; then
417                 debug-print "${updater} is not executable"
418                 return
419         fi
420
421         if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
422                 debug-print "gdk-pixbuf loader cache does not need an update"
423                 return
424         fi
425
426         ebegin "Updating gdk-pixbuf loader cache"
427         local tmp_file=$(emktemp)
428         ${updater} 1> "${tmp_file}" &&
429         chmod 0644 "${tmp_file}" &&
430         cp -f "${tmp_file}" "${EROOT}usr/$(get_libdir)/gdk-pixbuf-2.0/2.10.0/loaders.cache" &&
431         rm "${tmp_file}" # don't replace this with mv, required for SELinux support
432         eend $?
433 }
434
435 # @FUNCTION: gnome2_query_immodules_gtk2
436 # @USAGE: gnome2_query_immodules_gtk2
437 # @DESCRIPTION:
438 # Updates gtk2 immodules/gdk-pixbuf loaders listing.
439 gnome2_query_immodules_gtk2() {
440         local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-2.0
441         [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-2.0
442
443         ebegin "Updating gtk2 input method module cache"
444         GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-2.0/2.10.0/immodules.cache" \
445                 "${updater}" --update-cache
446         eend $?
447 }
448
449 # @FUNCTION: gnome2_query_immodules_gtk3
450 # @USAGE: gnome2_query_immodules_gtk3
451 # @DESCRIPTION:
452 # Updates gtk3 immodules/gdk-pixbuf loaders listing.
453 gnome2_query_immodules_gtk3() {
454         local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-3.0
455         [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-3.0
456
457         ebegin "Updating gtk3 input method module cache"
458         GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-3.0/3.0.0/immodules.cache" \
459                 "${updater}" --update-cache
460         eend $?
461 }
462
463 # @FUNCTION: gnome2_giomodule_cache_update
464 # @USAGE: gnome2_giomodule_cache_update
465 # @DESCRIPTION:
466 # Updates glib's gio modules cache.
467 # This function should be called from pkg_postinst and pkg_postrm.
468 gnome2_giomodule_cache_update() {
469         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
470         local updater="${EROOT}/usr/bin/${CHOST}-gio-querymodules"
471
472         if [[ ! -x ${updater} ]]; then
473                 updater="${EROOT}/usr/bin/gio-querymodules"
474         fi
475
476         if [[ ! -x ${updater} ]]; then
477                 debug-print "${updater} is not executable"
478                 return
479         fi
480
481         ebegin "Updating GIO modules cache"
482         ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
483         eend $?
484 }
485
486 # @FUNCTION: gnome2_disable_deprecation_warning
487 # @DESCRIPTION:
488 # Disable deprecation warnings commonly found in glib based packages.
489 # Should be called from src_prepare.
490 gnome2_disable_deprecation_warning() {
491         local retval=0
492         local fails=( )
493         local makefile
494
495         ebegin "Disabling deprecation warnings"
496         # The sort is important to ensure .am is listed before the respective .in for
497         # maintainer mode regeneration not kicking in due to .am being newer than .in
498         while read makefile ; do
499                 if ! grep -qE "(DISABLE_DEPRECATED|GSEAL_ENABLE)" "${makefile}"; then
500                         continue
501                 fi
502
503                 LC_ALL=C sed -r -i \
504                         -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
505                         -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
506                         -i "${makefile}"
507
508                 if [[ $? -ne 0 ]]; then
509                         # Add to the list of failures
510                         fails+=( "${makefile}" )
511                         retval=2
512                 fi
513         done < <(find "${S}" -name "Makefile.in" \
514                 -o -name "Makefile.am" -o -name "Makefile.decl" \
515                 | sort; [[ -f "${S}"/configure ]] && echo configure)
516 # TODO: sedding configure.ac can trigger maintainer mode; bug #439602
517 #               -o -name "configure.ac" -o -name "configure.in" \
518 #               | sort; echo configure)
519         eend ${retval}
520
521         for makefile in "${fails[@]}" ; do
522                 ewarn "Failed to disable deprecation warnings in ${makefile}"
523         done
524 }