nvidia-driver.eclass: Use next gen version of readme.gentoo eclass
[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
106 # @FUNCTION: gnome2_gconf_savelist
107 # @DESCRIPTION:
108 # Find the GConf schemas that are about to be installed and save their location
109 # in the GNOME2_ECLASS_SCHEMAS environment variable.
110 # This function should be called from pkg_preinst.
111 gnome2_gconf_savelist() {
112         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
113         pushd "${ED}" > /dev/null || die
114         export GNOME2_ECLASS_SCHEMAS=$(find 'etc/gconf/schemas/' -name '*.schemas' 2> /dev/null)
115         popd > /dev/null || die
116 }
117
118 # @FUNCTION: gnome2_gconf_install
119 # @DESCRIPTION:
120 # Applies any schema files installed by the current ebuild to Gconf's database
121 # using gconftool-2.
122 # This function should be called from pkg_postinst.
123 gnome2_gconf_install() {
124         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
125         local updater="${EROOT}${GCONFTOOL_BIN}"
126
127         if [[ ! -x "${updater}" ]]; then
128                 debug-print "${updater} is not executable"
129                 return
130         fi
131
132         if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
133                 debug-print "No GNOME 2 GConf schemas found"
134                 return
135         fi
136
137         # We are ready to install the GCONF Scheme now
138         unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
139         export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
140
141         einfo "Installing GNOME 2 GConf schemas"
142
143         local F
144         for F in ${GNOME2_ECLASS_SCHEMAS}; do
145                 if [[ -e "${EROOT}${F}" ]]; then
146                         debug-print "Installing schema: ${F}"
147                         "${updater}" --makefile-install-rule "${EROOT}${F}" 1>/dev/null
148                 fi
149         done
150
151         # have gconf reload the new schemas
152         pids=$(pgrep -x gconfd-2)
153         if [[ $? == 0 ]] ; then
154                 ebegin "Reloading GConf schemas"
155                 kill -HUP ${pids}
156                 eend $?
157         fi
158 }
159
160 # @FUNCTION: gnome2_gconf_uninstall
161 # @DESCRIPTION:
162 # Removes schema files previously installed by the current ebuild from Gconf's
163 # database.
164 gnome2_gconf_uninstall() {
165         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
166         local updater="${EROOT}${GCONFTOOL_BIN}"
167
168         if [[ ! -x "${updater}" ]]; then
169                 debug-print "${updater} is not executable"
170                 return
171         fi
172
173         if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
174                 debug-print "No GNOME 2 GConf schemas found"
175                 return
176         fi
177
178         unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
179         export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
180
181         einfo "Uninstalling GNOME 2 GConf schemas"
182
183         local F
184         for F in ${GNOME2_ECLASS_SCHEMAS}; do
185                 if [[ -e "${EROOT}${F}" ]]; then
186                         debug-print "Uninstalling gconf schema: ${F}"
187                         "${updater}" --makefile-uninstall-rule "${EROOT}${F}" 1>/dev/null
188                 fi
189         done
190
191         # have gconf reload the new schemas
192         pids=$(pgrep -x gconfd-2)
193         if [[ $? == 0 ]] ; then
194                 ebegin "Reloading GConf schemas"
195                 kill -HUP ${pids}
196                 eend $?
197         fi
198 }
199
200 # @FUNCTION: gnome2_icon_savelist
201 # @DESCRIPTION:
202 # Find the icons that are about to be installed and save their location
203 # in the GNOME2_ECLASS_ICONS environment variable.
204 # This function should be called from pkg_preinst.
205 gnome2_icon_savelist() {
206         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
207         pushd "${ED}" > /dev/null || die
208         export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
209         popd > /dev/null || die
210 }
211
212 # @FUNCTION: gnome2_icon_cache_update
213 # @DESCRIPTION:
214 # Updates Gtk+ icon cache files under /usr/share/icons if the current ebuild
215 # have installed anything under that location.
216 # This function should be called from pkg_postinst and pkg_postrm.
217 gnome2_icon_cache_update() {
218         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
219         local updater="${EROOT}${GTK_UPDATE_ICON_CACHE}"
220
221         if [[ ! -x "${updater}" ]] ; then
222                 debug-print "${updater} is not executable"
223                 return
224         fi
225
226         if [[ -z "${GNOME2_ECLASS_ICONS}" ]]; then
227                 debug-print "No icon cache to update"
228                 return
229         fi
230
231         ebegin "Updating icons cache"
232
233         local retval=0
234         local fails=( )
235
236         for dir in ${GNOME2_ECLASS_ICONS}
237         do
238                 if [[ -f "${EROOT}${dir}/index.theme" ]] ; then
239                         local rv=0
240
241                         "${updater}" -qf "${EROOT}${dir}"
242                         rv=$?
243
244                         if [[ ! $rv -eq 0 ]] ; then
245                                 debug-print "Updating cache failed on ${EROOT}${dir}"
246
247                                 # Add to the list of failures
248                                 fails[$(( ${#fails[@]} + 1 ))]="${EROOT}${dir}"
249
250                                 retval=2
251                         fi
252                 elif [[ $(ls "${EROOT}${dir}") = "icon-theme.cache" ]]; then
253                         # Clear stale cache files after theme uninstallation
254                         rm "${EROOT}${dir}/icon-theme.cache"
255                 fi
256
257                 if [[ -z $(ls "${EROOT}${dir}") ]]; then
258                         # Clear empty theme directories after theme uninstallation
259                         rmdir "${EROOT}${dir}"
260                 fi
261         done
262
263         eend ${retval}
264
265         for f in "${fails[@]}" ; do
266                 eerror "Failed to update cache with icon $f"
267         done
268 }
269
270 # @FUNCTION: gnome2_omf_fix
271 # @DESCRIPTION:
272 # Workaround applied to Makefile rules in order to remove redundant
273 # calls to scrollkeeper-update and sandbox violations.
274 # This function should be called from src_prepare.
275 gnome2_omf_fix() {
276         local omf_makefiles filename
277
278         omf_makefiles="$@"
279
280         if [[ -f ${S}/omf.make ]] ; then
281                 omf_makefiles="${omf_makefiles} ${S}/omf.make"
282         fi
283
284         if [[ -f ${S}/gnome-doc-utils.make ]] ; then
285                 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
286         fi
287
288         # testing fixing of all makefiles found
289         # The sort is important to ensure .am is listed before the respective .in for
290         # maintainer mode regeneration not kicking in due to .am being newer than .in
291         for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
292                 omf_makefiles="${omf_makefiles} ${filename}"
293         done
294
295         ebegin "Fixing OMF Makefiles"
296
297         local retval=0
298         local fails=( )
299
300         for omf in ${omf_makefiles} ; do
301                 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
302                 retval=$?
303
304                 if [[ $retval -ne 0 ]] ; then
305                         debug-print "updating of ${omf} failed"
306
307                         # Add to the list of failures
308                         fails[$(( ${#fails[@]} + 1 ))]=$omf
309
310                         retval=2
311                 fi
312         done
313
314         eend $retval
315
316         for f in "${fails[@]}" ; do
317                 eerror "Failed to update OMF Makefile $f"
318         done
319 }
320
321 # @FUNCTION: gnome2_scrollkeeper_savelist
322 # @DESCRIPTION:
323 # Find the scrolls that are about to be installed and save their location
324 # in the GNOME2_ECLASS_SCROLLS environment variable.
325 # This function should be called from pkg_preinst.
326 gnome2_scrollkeeper_savelist() {
327         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
328         pushd "${ED}" > /dev/null || die
329         export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null)
330         popd > /dev/null || die
331 }
332
333 # @FUNCTION: gnome2_scrollkeeper_update
334 # @DESCRIPTION:
335 # Updates the global scrollkeeper database.
336 # This function should be called from pkg_postinst and pkg_postrm.
337 gnome2_scrollkeeper_update() {
338         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
339         local updater="${EROOT}${SCROLLKEEPER_UPDATE_BIN}"
340
341         if [[ ! -x "${updater}" ]] ; then
342                 debug-print "${updater} is not executable"
343                 return
344         fi
345
346         if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
347                 debug-print "No scroll cache to update"
348                 return
349         fi
350
351         ebegin "Updating scrollkeeper database ..."
352         "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
353         eend $?
354 }
355
356 # @FUNCTION: gnome2_schemas_savelist
357 # @DESCRIPTION:
358 # Find if there is any GSettings schema to install and save the list in
359 # GNOME2_ECLASS_GLIB_SCHEMAS variable.
360 # This function should be called from pkg_preinst.
361 gnome2_schemas_savelist() {
362         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
363         pushd "${ED}" > /dev/null || die
364         export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
365         popd > /dev/null || die
366 }
367
368 # @FUNCTION: gnome2_schemas_update
369 # @USAGE: gnome2_schemas_update
370 # @DESCRIPTION:
371 # Updates GSettings schemas if GNOME2_ECLASS_GLIB_SCHEMAS has some.
372 # This function should be called from pkg_postinst and pkg_postrm.
373 gnome2_schemas_update() {
374         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
375         local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}"
376
377         if [[ ! -x ${updater} ]]; then
378                 debug-print "${updater} is not executable"
379                 return
380         fi
381
382         if [[ -z ${GNOME2_ECLASS_GLIB_SCHEMAS} ]]; then
383                 debug-print "No GSettings schemas to update"
384                 return
385         fi
386
387         ebegin "Updating GSettings schemas"
388         ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
389         eend $?
390 }
391
392 # @FUNCTION: gnome2_gdk_pixbuf_savelist
393 # @DESCRIPTION:
394 # Find if there is any gdk-pixbuf loader to install and save the list in
395 # GNOME2_ECLASS_GDK_PIXBUF_LOADERS variable.
396 # This function should be called from pkg_preinst.
397 gnome2_gdk_pixbuf_savelist() {
398         has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
399         pushd "${ED}" > /dev/null || die
400         export GNOME2_ECLASS_GDK_PIXBUF_LOADERS=$(find usr/lib*/gdk-pixbuf-2.0 -type f 2>/dev/null)
401         popd > /dev/null || die
402 }
403
404 # @FUNCTION: gnome2_gdk_pixbuf_update
405 # @USAGE: gnome2_gdk_pixbuf_update
406 # @DESCRIPTION:
407 # Updates gdk-pixbuf loader cache if GNOME2_ECLASS_GDK_PIXBUF_LOADERS has some.
408 # This function should be called from pkg_postinst and pkg_postrm.
409 gnome2_gdk_pixbuf_update() {
410         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
411         local updater="${EROOT}/usr/bin/${CHOST}-gdk-pixbuf-query-loaders"
412
413         if [[ ! -x ${updater} ]]; then
414                 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
415         fi
416
417         if [[ ! -x ${updater} ]]; then
418                 debug-print "${updater} is not executable"
419                 return
420         fi
421
422         if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
423                 debug-print "gdk-pixbuf loader cache does not need an update"
424                 return
425         fi
426
427         ebegin "Updating gdk-pixbuf loader cache"
428         local tmp_file=$(emktemp)
429         ${updater} 1> "${tmp_file}" &&
430         chmod 0644 "${tmp_file}" &&
431         cp -f "${tmp_file}" "${EROOT}usr/$(get_libdir)/gdk-pixbuf-2.0/2.10.0/loaders.cache" &&
432         rm "${tmp_file}" # don't replace this with mv, required for SELinux support
433         eend $?
434 }
435
436 # @FUNCTION: gnome2_query_immodules_gtk2
437 # @USAGE: gnome2_query_immodules_gtk2
438 # @DESCRIPTION:
439 # Updates gtk2 immodules/gdk-pixbuf loaders listing.
440 gnome2_query_immodules_gtk2() {
441         local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-2.0
442         [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-2.0
443
444         ebegin "Updating gtk2 input method module cache"
445         GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-2.0/2.10.0/immodules.cache" \
446                 "${updater}" --update-cache
447         eend $?
448 }
449
450 # @FUNCTION: gnome2_query_immodules_gtk3
451 # @USAGE: gnome2_query_immodules_gtk3
452 # @DESCRIPTION:
453 # Updates gtk3 immodules/gdk-pixbuf loaders listing.
454 gnome2_query_immodules_gtk3() {
455         local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-3.0
456         [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-3.0
457
458         ebegin "Updating gtk3 input method module cache"
459         GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-3.0/3.0.0/immodules.cache" \
460                 "${updater}" --update-cache
461         eend $?
462 }
463
464 # @FUNCTION: gnome2_giomodule_cache_update
465 # @USAGE: gnome2_giomodule_cache_update
466 # @DESCRIPTION:
467 # Updates glib's gio modules cache.
468 # This function should be called from pkg_postinst and pkg_postrm.
469 gnome2_giomodule_cache_update() {
470         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
471         local updater="${EROOT}/usr/bin/${CHOST}-gio-querymodules"
472
473         if [[ ! -x ${updater} ]]; then
474                 updater="${EROOT}/usr/bin/gio-querymodules"
475         fi
476
477         if [[ ! -x ${updater} ]]; then
478                 debug-print "${updater} is not executable"
479                 return
480         fi
481
482         ebegin "Updating GIO modules cache"
483         ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
484         eend $?
485 }
486
487 # @FUNCTION: gnome2_disable_deprecation_warning
488 # @DESCRIPTION:
489 # Disable deprecation warnings commonly found in glib based packages.
490 # Should be called from src_prepare.
491 gnome2_disable_deprecation_warning() {
492         local retval=0
493         local fails=( )
494         local makefile
495
496         ebegin "Disabling deprecation warnings"
497         # The sort is important to ensure .am is listed before the respective .in for
498         # maintainer mode regeneration not kicking in due to .am being newer than .in
499         while read makefile ; do
500                 if ! grep -qE "(DISABLE_DEPRECATED|GSEAL_ENABLE)" "${makefile}"; then
501                         continue
502                 fi
503
504                 LC_ALL=C sed -r -i \
505                         -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
506                         -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
507                         -i "${makefile}"
508
509                 if [[ $? -ne 0 ]]; then
510                         # Add to the list of failures
511                         fails+=( "${makefile}" )
512                         retval=2
513                 fi
514         done < <(find "${S}" -name "Makefile.in" \
515                 -o -name "Makefile.am" -o -name "Makefile.decl" \
516                 | sort; [[ -f "${S}"/configure ]] && echo configure)
517 # TODO: sedding configure.ac can trigger maintainer mode; bug #439602
518 #               -o -name "configure.ac" -o -name "configure.in" \
519 #               | sort; echo configure)
520         eend ${retval}
521
522         for makefile in "${fails[@]}" ; do
523                 ewarn "Failed to disable deprecation warnings in ${makefile}"
524         done
525 }