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