1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: gnome2-utils.eclass
8 # @BLURB: Auxiliary functions commonly used by Gnome packages.
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
18 [[ ${EAPI:-0} == [012345] ]] && inherit multilib
19 inherit eutils xdg-utils
23 *) die "EAPI=${EAPI} is not supported" ;;
26 # @ECLASS-VARIABLE: GCONFTOOL_BIN
30 : ${GCONFTOOL_BIN:="/usr/bin/gconftool-2"}
32 # @ECLASS-VARIABLE: SCROLLKEEPER_DIR
35 # Directory where scrollkeeper-update should do its work
36 : ${SCROLLKEEPER_DIR:="/var/lib/scrollkeeper"}
38 # @ECLASS-VARIABLE: SCROLLKEEPER_UPDATE_BIN
41 # Path to scrollkeeper-update
42 : ${SCROLLKEEPER_UPDATE_BIN:="/usr/bin/scrollkeeper-update"}
44 # @ECLASS-VARIABLE: GTK_UPDATE_ICON_CACHE
47 # Path to gtk-update-icon-cache
48 : ${GTK_UPDATE_ICON_CACHE:="/usr/bin/gtk-update-icon-cache"}
50 # @ECLASS-VARIABLE: GLIB_COMPILE_SCHEMAS
53 # Path to glib-compile-schemas
54 : ${GLIB_COMPILE_SCHEMAS:="/usr/bin/glib-compile-schemas"}
56 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCHEMAS
60 # List of GConf schemas provided by the package
62 # @ECLASS-VARIABLE: GNOME2_ECLASS_ICONS
66 # List of icons provided by the package
68 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCROLLS
72 # List of scrolls (documentation files) provided by the package
74 # @ECLASS-VARIABLE: GNOME2_ECLASS_GLIB_SCHEMAS
78 # List of GSettings schemas provided by the package
80 # @ECLASS-VARIABLE: GNOME2_ECLASS_GDK_PIXBUF_LOADERS
84 # List of gdk-pixbuf loaders provided by the package
86 DEPEND=">=sys-apps/sed-4"
89 # @FUNCTION: gnome2_environment_reset
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() {
96 # Respected by >=glib-2.30.1-r1
99 # GST_REGISTRY is to work around gst utilities trying to read/write /root
100 export GST_REGISTRY="${T}/registry.xml"
102 # Ensure we don't rely on dconf/gconf while building, bug #511946
103 export GSETTINGS_BACKEND="memory"
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)"
109 # Stop relying on random DISPLAY variable values, bug #534312
114 # @FUNCTION: gnome2_gconf_savelist
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
126 # @FUNCTION: gnome2_gconf_install
128 # Applies any schema files installed by the current ebuild to Gconf's database
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}"
135 if [[ ! -x "${updater}" ]]; then
136 debug-print "${updater} is not executable"
140 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
141 debug-print "No GNOME 2 GConf schemas found"
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};")"
149 einfo "Installing GNOME 2 GConf schemas"
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
159 # have gconf reload the new schemas
160 pids=$(pgrep -x gconfd-2)
161 if [[ $? == 0 ]] ; then
162 ebegin "Reloading GConf schemas"
168 # @FUNCTION: gnome2_gconf_uninstall
170 # Removes schema files previously installed by the current ebuild from Gconf's
172 gnome2_gconf_uninstall() {
173 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
174 local updater="${EROOT}${GCONFTOOL_BIN}"
176 if [[ ! -x "${updater}" ]]; then
177 debug-print "${updater} is not executable"
181 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
182 debug-print "No GNOME 2 GConf schemas found"
186 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
187 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
189 einfo "Uninstalling GNOME 2 GConf schemas"
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
199 # have gconf reload the new schemas
200 pids=$(pgrep -x gconfd-2)
201 if [[ $? == 0 ]] ; then
202 ebegin "Reloading GConf schemas"
208 # @FUNCTION: gnome2_icon_savelist
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
220 # @FUNCTION: gnome2_icon_cache_update
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}"
229 if [[ ! -x "${updater}" ]] ; then
230 debug-print "${updater} is not executable"
234 if [[ -z "${GNOME2_ECLASS_ICONS}" ]]; then
235 debug-print "No icon cache to update"
239 ebegin "Updating icons cache"
244 for dir in ${GNOME2_ECLASS_ICONS}
246 if [[ -f "${EROOT}${dir}/index.theme" ]] ; then
249 "${updater}" -qf "${EROOT}${dir}"
252 if [[ ! $rv -eq 0 ]] ; then
253 debug-print "Updating cache failed on ${EROOT}${dir}"
255 # Add to the list of failures
256 fails[$(( ${#fails[@]} + 1 ))]="${EROOT}${dir}"
260 elif [[ $(ls "${EROOT}${dir}") = "icon-theme.cache" ]]; then
261 # Clear stale cache files after theme uninstallation
262 rm "${EROOT}${dir}/icon-theme.cache"
265 if [[ -z $(ls "${EROOT}${dir}") ]]; then
266 # Clear empty theme directories after theme uninstallation
267 rmdir "${EROOT}${dir}"
273 for f in "${fails[@]}" ; do
274 eerror "Failed to update cache with icon $f"
278 # @FUNCTION: gnome2_omf_fix
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.
284 local omf_makefiles filename
288 if [[ -f ${S}/omf.make ]] ; then
289 omf_makefiles="${omf_makefiles} ${S}/omf.make"
292 if [[ -f ${S}/gnome-doc-utils.make ]] ; then
293 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
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}"
303 ebegin "Fixing OMF Makefiles"
308 for omf in ${omf_makefiles} ; do
309 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
312 if [[ $retval -ne 0 ]] ; then
313 debug-print "updating of ${omf} failed"
315 # Add to the list of failures
316 fails[$(( ${#fails[@]} + 1 ))]=$omf
324 for f in "${fails[@]}" ; do
325 eerror "Failed to update OMF Makefile $f"
329 # @FUNCTION: gnome2_scrollkeeper_savelist
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
341 # @FUNCTION: gnome2_scrollkeeper_update
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}"
349 if [[ ! -x "${updater}" ]] ; then
350 debug-print "${updater} is not executable"
354 if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
355 debug-print "No scroll cache to update"
359 ebegin "Updating scrollkeeper database ..."
360 "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
364 # @FUNCTION: gnome2_schemas_savelist
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
376 # @FUNCTION: gnome2_schemas_update
377 # @USAGE: gnome2_schemas_update
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}"
385 if [[ ! -x ${updater} ]]; then
386 debug-print "${updater} is not executable"
390 if [[ -z ${GNOME2_ECLASS_GLIB_SCHEMAS} ]]; then
391 debug-print "No GSettings schemas to update"
395 ebegin "Updating GSettings schemas"
396 ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
400 # @FUNCTION: gnome2_gdk_pixbuf_savelist
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
412 # @FUNCTION: gnome2_gdk_pixbuf_update
413 # @USAGE: gnome2_gdk_pixbuf_update
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"
421 if [[ ! -x ${updater} ]]; then
422 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
425 if [[ ! -x ${updater} ]]; then
426 debug-print "${updater} is not executable"
430 if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
431 debug-print "gdk-pixbuf loader cache does not need an update"
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
444 # @FUNCTION: gnome2_query_immodules_gtk2
445 # @USAGE: gnome2_query_immodules_gtk2
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
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
458 # @FUNCTION: gnome2_query_immodules_gtk3
459 # @USAGE: gnome2_query_immodules_gtk3
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
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
472 # @FUNCTION: gnome2_giomodule_cache_update
473 # @USAGE: gnome2_giomodule_cache_update
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"
481 if [[ ! -x ${updater} ]]; then
482 updater="${EROOT}/usr/bin/gio-querymodules"
485 if [[ ! -x ${updater} ]]; then
486 debug-print "${updater} is not executable"
490 ebegin "Updating GIO modules cache"
491 ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
495 # @FUNCTION: gnome2_disable_deprecation_warning
497 # Disable deprecation warnings commonly found in glib based packages.
498 # Should be called from src_prepare.
499 gnome2_disable_deprecation_warning() {
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
513 -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
514 -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
517 if [[ $? -ne 0 ]]; then
518 # Add to the list of failures
519 fails+=( "${makefile}" )
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)
530 for makefile in "${fails[@]}" ; do
531 ewarn "Failed to disable deprecation warnings in ${makefile}"