kde-plasma/breeze-gtk: x86 stable wrt bug #613144
[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.
211 # This function should be called from pkg_preinst.
212 gnome2_icon_savelist() {
213         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
214         pushd "${ED}" > /dev/null || die
215         export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
216         popd > /dev/null || die
217 }
218
219 # @FUNCTION: gnome2_icon_cache_update
220 # @DESCRIPTION:
221 # Updates Gtk+ icon cache files under /usr/share/icons if the current ebuild
222 # have installed anything under that location.
223 # This function should be called from pkg_postinst and pkg_postrm.
224 gnome2_icon_cache_update() {
225         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
226         local updater="${EROOT}${GTK_UPDATE_ICON_CACHE}"
227
228         if [[ ! -x "${updater}" ]] ; then
229                 debug-print "${updater} is not executable"
230                 return
231         fi
232
233         if [[ -z "${GNOME2_ECLASS_ICONS}" ]]; then
234                 debug-print "No icon cache to update"
235                 return
236         fi
237
238         ebegin "Updating icons cache"
239
240         local retval=0
241         local fails=( )
242
243         for dir in ${GNOME2_ECLASS_ICONS}
244         do
245                 if [[ -f "${EROOT}${dir}/index.theme" ]] ; then
246                         local rv=0
247
248                         "${updater}" -qf "${EROOT}${dir}"
249                         rv=$?
250
251                         if [[ ! $rv -eq 0 ]] ; then
252                                 debug-print "Updating cache failed on ${EROOT}${dir}"
253
254                                 # Add to the list of failures
255                                 fails[$(( ${#fails[@]} + 1 ))]="${EROOT}${dir}"
256
257                                 retval=2
258                         fi
259                 elif [[ $(ls "${EROOT}${dir}") = "icon-theme.cache" ]]; then
260                         # Clear stale cache files after theme uninstallation
261                         rm "${EROOT}${dir}/icon-theme.cache"
262                 fi
263
264                 if [[ -z $(ls "${EROOT}${dir}") ]]; then
265                         # Clear empty theme directories after theme uninstallation
266                         rmdir "${EROOT}${dir}"
267                 fi
268         done
269
270         eend ${retval}
271
272         for f in "${fails[@]}" ; do
273                 eerror "Failed to update cache with icon $f"
274         done
275 }
276
277 # @FUNCTION: gnome2_omf_fix
278 # @DESCRIPTION:
279 # Workaround applied to Makefile rules in order to remove redundant
280 # calls to scrollkeeper-update and sandbox violations.
281 # This function should be called from src_prepare.
282 gnome2_omf_fix() {
283         local omf_makefiles filename
284
285         omf_makefiles="$@"
286
287         if [[ -f ${S}/omf.make ]] ; then
288                 omf_makefiles="${omf_makefiles} ${S}/omf.make"
289         fi
290
291         if [[ -f ${S}/gnome-doc-utils.make ]] ; then
292                 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
293         fi
294
295         # testing fixing of all makefiles found
296         # The sort is important to ensure .am is listed before the respective .in for
297         # maintainer mode regeneration not kicking in due to .am being newer than .in
298         for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
299                 omf_makefiles="${omf_makefiles} ${filename}"
300         done
301
302         ebegin "Fixing OMF Makefiles"
303
304         local retval=0
305         local fails=( )
306
307         for omf in ${omf_makefiles} ; do
308                 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
309                 retval=$?
310
311                 if [[ $retval -ne 0 ]] ; then
312                         debug-print "updating of ${omf} failed"
313
314                         # Add to the list of failures
315                         fails[$(( ${#fails[@]} + 1 ))]=$omf
316
317                         retval=2
318                 fi
319         done
320
321         eend $retval
322
323         for f in "${fails[@]}" ; do
324                 eerror "Failed to update OMF Makefile $f"
325         done
326 }
327
328 # @FUNCTION: gnome2_scrollkeeper_savelist
329 # @DESCRIPTION:
330 # Find the scrolls that are about to be installed and save their location
331 # in the GNOME2_ECLASS_SCROLLS environment variable.
332 # This function should be called from pkg_preinst.
333 gnome2_scrollkeeper_savelist() {
334         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
335         pushd "${ED}" > /dev/null || die
336         export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null)
337         popd > /dev/null || die
338 }
339
340 # @FUNCTION: gnome2_scrollkeeper_update
341 # @DESCRIPTION:
342 # Updates the global scrollkeeper database.
343 # This function should be called from pkg_postinst and pkg_postrm.
344 gnome2_scrollkeeper_update() {
345         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
346         local updater="${EROOT}${SCROLLKEEPER_UPDATE_BIN}"
347
348         if [[ ! -x "${updater}" ]] ; then
349                 debug-print "${updater} is not executable"
350                 return
351         fi
352
353         if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
354                 debug-print "No scroll cache to update"
355                 return
356         fi
357
358         ebegin "Updating scrollkeeper database ..."
359         "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
360         eend $?
361 }
362
363 # @FUNCTION: gnome2_schemas_savelist
364 # @DESCRIPTION:
365 # Find if there is any GSettings schema to install and save the list in
366 # GNOME2_ECLASS_GLIB_SCHEMAS variable.
367 # This function should be called from pkg_preinst.
368 gnome2_schemas_savelist() {
369         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
370         pushd "${ED}" > /dev/null || die
371         export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
372         popd > /dev/null || die
373 }
374
375 # @FUNCTION: gnome2_schemas_update
376 # @USAGE: gnome2_schemas_update
377 # @DESCRIPTION:
378 # Updates GSettings schemas if GNOME2_ECLASS_GLIB_SCHEMAS has some.
379 # This function should be called from pkg_postinst and pkg_postrm.
380 gnome2_schemas_update() {
381         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
382         local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}"
383
384         if [[ ! -x ${updater} ]]; then
385                 debug-print "${updater} is not executable"
386                 return
387         fi
388
389         if [[ -z ${GNOME2_ECLASS_GLIB_SCHEMAS} ]]; then
390                 debug-print "No GSettings schemas to update"
391                 return
392         fi
393
394         ebegin "Updating GSettings schemas"
395         ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
396         eend $?
397 }
398
399 # @FUNCTION: gnome2_gdk_pixbuf_savelist
400 # @DESCRIPTION:
401 # Find if there is any gdk-pixbuf loader to install and save the list in
402 # GNOME2_ECLASS_GDK_PIXBUF_LOADERS variable.
403 # This function should be called from pkg_preinst.
404 gnome2_gdk_pixbuf_savelist() {
405         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
406         pushd "${ED}" > /dev/null || die
407         export GNOME2_ECLASS_GDK_PIXBUF_LOADERS=$(find usr/lib*/gdk-pixbuf-2.0 -type f 2>/dev/null)
408         popd > /dev/null || die
409 }
410
411 # @FUNCTION: gnome2_gdk_pixbuf_update
412 # @USAGE: gnome2_gdk_pixbuf_update
413 # @DESCRIPTION:
414 # Updates gdk-pixbuf loader cache if GNOME2_ECLASS_GDK_PIXBUF_LOADERS has some.
415 # This function should be called from pkg_postinst and pkg_postrm.
416 gnome2_gdk_pixbuf_update() {
417         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
418         local updater="${EROOT}/usr/bin/${CHOST}-gdk-pixbuf-query-loaders"
419
420         if [[ ! -x ${updater} ]]; then
421                 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
422         fi
423
424         if [[ ! -x ${updater} ]]; then
425                 debug-print "${updater} is not executable"
426                 return
427         fi
428
429         if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
430                 debug-print "gdk-pixbuf loader cache does not need an update"
431                 return
432         fi
433
434         ebegin "Updating gdk-pixbuf loader cache"
435         local tmp_file=$(emktemp)
436         ${updater} 1> "${tmp_file}" &&
437         chmod 0644 "${tmp_file}" &&
438         cp -f "${tmp_file}" "${EROOT}usr/$(get_libdir)/gdk-pixbuf-2.0/2.10.0/loaders.cache" &&
439         rm "${tmp_file}" # don't replace this with mv, required for SELinux support
440         eend $?
441 }
442
443 # @FUNCTION: gnome2_query_immodules_gtk2
444 # @USAGE: gnome2_query_immodules_gtk2
445 # @DESCRIPTION:
446 # Updates gtk2 immodules/gdk-pixbuf loaders listing.
447 gnome2_query_immodules_gtk2() {
448         local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-2.0
449         [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-2.0
450
451         ebegin "Updating gtk2 input method module cache"
452         GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-2.0/2.10.0/immodules.cache" \
453                 "${updater}" --update-cache
454         eend $?
455 }
456
457 # @FUNCTION: gnome2_query_immodules_gtk3
458 # @USAGE: gnome2_query_immodules_gtk3
459 # @DESCRIPTION:
460 # Updates gtk3 immodules/gdk-pixbuf loaders listing.
461 gnome2_query_immodules_gtk3() {
462         local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-3.0
463         [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-3.0
464
465         ebegin "Updating gtk3 input method module cache"
466         GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-3.0/3.0.0/immodules.cache" \
467                 "${updater}" --update-cache
468         eend $?
469 }
470
471 # @FUNCTION: gnome2_giomodule_cache_update
472 # @USAGE: gnome2_giomodule_cache_update
473 # @DESCRIPTION:
474 # Updates glib's gio modules cache.
475 # This function should be called from pkg_postinst and pkg_postrm.
476 gnome2_giomodule_cache_update() {
477         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
478         local updater="${EROOT}/usr/bin/${CHOST}-gio-querymodules"
479
480         if [[ ! -x ${updater} ]]; then
481                 updater="${EROOT}/usr/bin/gio-querymodules"
482         fi
483
484         if [[ ! -x ${updater} ]]; then
485                 debug-print "${updater} is not executable"
486                 return
487         fi
488
489         ebegin "Updating GIO modules cache"
490         ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
491         eend $?
492 }
493
494 # @FUNCTION: gnome2_disable_deprecation_warning
495 # @DESCRIPTION:
496 # Disable deprecation warnings commonly found in glib based packages.
497 # Should be called from src_prepare.
498 gnome2_disable_deprecation_warning() {
499         local retval=0
500         local fails=( )
501         local makefile
502
503         ebegin "Disabling deprecation warnings"
504         # The sort is important to ensure .am is listed before the respective .in for
505         # maintainer mode regeneration not kicking in due to .am being newer than .in
506         while read makefile ; do
507                 if ! grep -qE "(DISABLE_DEPRECATED|GSEAL_ENABLE)" "${makefile}"; then
508                         continue
509                 fi
510
511                 LC_ALL=C sed -r -i \
512                         -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
513                         -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
514                         -i "${makefile}"
515
516                 if [[ $? -ne 0 ]]; then
517                         # Add to the list of failures
518                         fails+=( "${makefile}" )
519                         retval=2
520                 fi
521         done < <(find "${S}" -name "Makefile.in" \
522                 -o -name "Makefile.am" -o -name "Makefile.decl" \
523                 | sort; [[ -f "${S}"/configure ]] && echo configure)
524 # TODO: sedding configure.ac can trigger maintainer mode; bug #439602
525 #               -o -name "configure.ac" -o -name "configure.in" \
526 #               | sort; echo configure)
527         eend ${retval}
528
529         for makefile in "${fails[@]}" ; do
530                 ewarn "Failed to disable deprecation warnings in ${makefile}"
531         done
532 }