1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: gnome2-utils.eclass
7 # @BLURB: Auxiliary functions commonly used by Gnome packages.
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
17 [[ ${EAPI:-0} == [012345] ]] && inherit multilib
18 inherit eutils xdg-utils
22 *) die "EAPI=${EAPI} is not supported" ;;
25 # @ECLASS-VARIABLE: GCONFTOOL_BIN
29 : ${GCONFTOOL_BIN:="/usr/bin/gconftool-2"}
31 # @ECLASS-VARIABLE: SCROLLKEEPER_DIR
34 # Directory where scrollkeeper-update should do its work
35 : ${SCROLLKEEPER_DIR:="/var/lib/scrollkeeper"}
37 # @ECLASS-VARIABLE: SCROLLKEEPER_UPDATE_BIN
40 # Path to scrollkeeper-update
41 : ${SCROLLKEEPER_UPDATE_BIN:="/usr/bin/scrollkeeper-update"}
43 # @ECLASS-VARIABLE: GTK_UPDATE_ICON_CACHE
46 # Path to gtk-update-icon-cache
47 : ${GTK_UPDATE_ICON_CACHE:="/usr/bin/gtk-update-icon-cache"}
49 # @ECLASS-VARIABLE: GLIB_COMPILE_SCHEMAS
52 # Path to glib-compile-schemas
53 : ${GLIB_COMPILE_SCHEMAS:="/usr/bin/glib-compile-schemas"}
55 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCHEMAS
59 # List of GConf schemas provided by the package
61 # @ECLASS-VARIABLE: GNOME2_ECLASS_ICONS
65 # List of icons provided by the package
67 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCROLLS
71 # List of scrolls (documentation files) provided by the package
73 # @ECLASS-VARIABLE: GNOME2_ECLASS_GLIB_SCHEMAS
77 # List of GSettings schemas provided by the package
79 # @ECLASS-VARIABLE: GNOME2_ECLASS_GDK_PIXBUF_LOADERS
83 # List of gdk-pixbuf loaders provided by the package
85 DEPEND=">=sys-apps/sed-4"
88 # @FUNCTION: gnome2_environment_reset
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() {
95 # Respected by >=glib-2.30.1-r1
98 # GST_REGISTRY is to work around gst utilities trying to read/write /root
99 export GST_REGISTRY="${T}/registry.xml"
101 # Ensure we don't rely on dconf/gconf while building, bug #511946
102 export GSETTINGS_BACKEND="memory"
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)"
108 # Stop relying on random DISPLAY variable values, bug #534312
113 # @FUNCTION: gnome2_gconf_savelist
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
125 # @FUNCTION: gnome2_gconf_install
127 # Applies any schema files installed by the current ebuild to Gconf's database
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}"
134 if [[ ! -x "${updater}" ]]; then
135 debug-print "${updater} is not executable"
139 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
140 debug-print "No GNOME 2 GConf schemas found"
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};")"
148 einfo "Installing GNOME 2 GConf schemas"
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
158 # have gconf reload the new schemas
159 pids=$(pgrep -x gconfd-2)
160 if [[ $? == 0 ]] ; then
161 ebegin "Reloading GConf schemas"
167 # @FUNCTION: gnome2_gconf_uninstall
169 # Removes schema files previously installed by the current ebuild from Gconf's
171 gnome2_gconf_uninstall() {
172 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
173 local updater="${EROOT}${GCONFTOOL_BIN}"
175 if [[ ! -x "${updater}" ]]; then
176 debug-print "${updater} is not executable"
180 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
181 debug-print "No GNOME 2 GConf schemas found"
185 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
186 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
188 einfo "Uninstalling GNOME 2 GConf schemas"
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
198 # have gconf reload the new schemas
199 pids=$(pgrep -x gconfd-2)
200 if [[ $? == 0 ]] ; then
201 ebegin "Reloading GConf schemas"
207 # @FUNCTION: gnome2_icon_savelist
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
219 # @FUNCTION: gnome2_icon_cache_update
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}"
228 if [[ ! -x "${updater}" ]] ; then
229 debug-print "${updater} is not executable"
233 ebegin "Updating icons cache"
238 for dir in "${EROOT%/}"/usr/share/icons/*
240 if [[ -f "${dir}/index.theme" ]] ; then
243 "${updater}" -qf "${dir}"
246 if [[ ! $rv -eq 0 ]] ; then
247 debug-print "Updating cache failed on ${dir}"
249 # Add to the list of failures
254 elif [[ $(ls "${dir}") = "icon-theme.cache" ]]; then
255 # Clear stale cache files after theme uninstallation
256 rm "${dir}/icon-theme.cache"
259 if [[ -z $(ls "${dir}") ]]; then
260 # Clear empty theme directories after theme uninstallation
267 for f in "${fails[@]}" ; do
268 eerror "Failed to update cache with icon $f"
272 # @FUNCTION: gnome2_omf_fix
274 # Workaround applied to Makefile rules in order to remove redundant
275 # calls to scrollkeeper-update and sandbox violations.
276 # This function should be called from src_prepare.
278 local omf_makefiles filename
282 if [[ -f ${S}/omf.make ]] ; then
283 omf_makefiles="${omf_makefiles} ${S}/omf.make"
286 if [[ -f ${S}/gnome-doc-utils.make ]] ; then
287 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
290 # testing fixing of all makefiles found
291 # The sort is important to ensure .am is listed before the respective .in for
292 # maintainer mode regeneration not kicking in due to .am being newer than .in
293 for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
294 omf_makefiles="${omf_makefiles} ${filename}"
297 ebegin "Fixing OMF Makefiles"
302 for omf in ${omf_makefiles} ; do
303 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
306 if [[ $retval -ne 0 ]] ; then
307 debug-print "updating of ${omf} failed"
309 # Add to the list of failures
310 fails[$(( ${#fails[@]} + 1 ))]=$omf
318 for f in "${fails[@]}" ; do
319 eerror "Failed to update OMF Makefile $f"
323 # @FUNCTION: gnome2_scrollkeeper_savelist
325 # Find the scrolls that are about to be installed and save their location
326 # in the GNOME2_ECLASS_SCROLLS environment variable.
327 # This function should be called from pkg_preinst.
328 gnome2_scrollkeeper_savelist() {
329 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
330 pushd "${ED}" > /dev/null || die
331 export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null)
332 popd > /dev/null || die
335 # @FUNCTION: gnome2_scrollkeeper_update
337 # Updates the global scrollkeeper database.
338 # This function should be called from pkg_postinst and pkg_postrm.
339 gnome2_scrollkeeper_update() {
340 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
341 local updater="${EROOT}${SCROLLKEEPER_UPDATE_BIN}"
343 if [[ ! -x "${updater}" ]] ; then
344 debug-print "${updater} is not executable"
348 if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
349 debug-print "No scroll cache to update"
353 ebegin "Updating scrollkeeper database ..."
354 "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
358 # @FUNCTION: gnome2_schemas_savelist
360 # Find if there is any GSettings schema to install and save the list in
361 # GNOME2_ECLASS_GLIB_SCHEMAS variable.
362 # This function should be called from pkg_preinst.
363 gnome2_schemas_savelist() {
364 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
365 pushd "${ED}" > /dev/null || die
366 export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
367 popd > /dev/null || die
370 # @FUNCTION: gnome2_schemas_update
371 # @USAGE: gnome2_schemas_update
373 # Updates GSettings schemas if GNOME2_ECLASS_GLIB_SCHEMAS has some.
374 # This function should be called from pkg_postinst and pkg_postrm.
375 gnome2_schemas_update() {
376 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
377 local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}"
379 if [[ ! -x ${updater} ]]; then
380 debug-print "${updater} is not executable"
384 ebegin "Updating GSettings schemas"
385 ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
389 # @FUNCTION: gnome2_gdk_pixbuf_savelist
391 # Find if there is any gdk-pixbuf loader to install and save the list in
392 # GNOME2_ECLASS_GDK_PIXBUF_LOADERS variable.
393 # This function should be called from pkg_preinst.
394 gnome2_gdk_pixbuf_savelist() {
395 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
396 pushd "${ED}" > /dev/null || die
397 export GNOME2_ECLASS_GDK_PIXBUF_LOADERS=$(find usr/lib*/gdk-pixbuf-2.0 -type f 2>/dev/null)
398 popd > /dev/null || die
401 # @FUNCTION: gnome2_gdk_pixbuf_update
402 # @USAGE: gnome2_gdk_pixbuf_update
404 # Updates gdk-pixbuf loader cache if GNOME2_ECLASS_GDK_PIXBUF_LOADERS has some.
405 # This function should be called from pkg_postinst and pkg_postrm.
406 gnome2_gdk_pixbuf_update() {
407 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
408 local updater="${EROOT}/usr/bin/${CHOST}-gdk-pixbuf-query-loaders"
410 if [[ ! -x ${updater} ]]; then
411 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
414 if [[ ! -x ${updater} ]]; then
415 debug-print "${updater} is not executable"
419 if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
420 debug-print "gdk-pixbuf loader cache does not need an update"
424 ebegin "Updating gdk-pixbuf loader cache"
425 local tmp_file=$(emktemp)
426 ${updater} 1> "${tmp_file}" &&
427 chmod 0644 "${tmp_file}" &&
428 cp -f "${tmp_file}" "${EROOT}usr/$(get_libdir)/gdk-pixbuf-2.0/2.10.0/loaders.cache" &&
429 rm "${tmp_file}" # don't replace this with mv, required for SELinux support
433 # @FUNCTION: gnome2_query_immodules_gtk2
434 # @USAGE: gnome2_query_immodules_gtk2
436 # Updates gtk2 immodules/gdk-pixbuf loaders listing.
437 gnome2_query_immodules_gtk2() {
438 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-2.0
439 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-2.0
441 ebegin "Updating gtk2 input method module cache"
442 GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-2.0/2.10.0/immodules.cache" \
443 "${updater}" --update-cache
447 # @FUNCTION: gnome2_query_immodules_gtk3
448 # @USAGE: gnome2_query_immodules_gtk3
450 # Updates gtk3 immodules/gdk-pixbuf loaders listing.
451 gnome2_query_immodules_gtk3() {
452 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-3.0
453 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-3.0
455 ebegin "Updating gtk3 input method module cache"
456 GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-3.0/3.0.0/immodules.cache" \
457 "${updater}" --update-cache
461 # @FUNCTION: gnome2_giomodule_cache_update
462 # @USAGE: gnome2_giomodule_cache_update
464 # Updates glib's gio modules cache.
465 # This function should be called from pkg_postinst and pkg_postrm.
466 gnome2_giomodule_cache_update() {
467 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
468 local updater="${EROOT}/usr/bin/${CHOST}-gio-querymodules"
470 if [[ ! -x ${updater} ]]; then
471 updater="${EROOT}/usr/bin/gio-querymodules"
474 if [[ ! -x ${updater} ]]; then
475 debug-print "${updater} is not executable"
479 ebegin "Updating GIO modules cache"
480 ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
484 # @FUNCTION: gnome2_disable_deprecation_warning
486 # Disable deprecation warnings commonly found in glib based packages.
487 # Should be called from src_prepare.
488 gnome2_disable_deprecation_warning() {
493 ebegin "Disabling deprecation warnings"
494 # The sort is important to ensure .am is listed before the respective .in for
495 # maintainer mode regeneration not kicking in due to .am being newer than .in
496 while read makefile ; do
497 if ! grep -qE "(DISABLE_DEPRECATED|GSEAL_ENABLE)" "${makefile}"; then
502 -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
503 -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
506 if [[ $? -ne 0 ]]; then
507 # Add to the list of failures
508 fails+=( "${makefile}" )
511 done < <(find "${S}" -name "Makefile.in" \
512 -o -name "Makefile.am" -o -name "Makefile.decl" \
513 | sort; [[ -f "${S}"/configure ]] && echo configure)
514 # TODO: sedding configure.ac can trigger maintainer mode; bug #439602
515 # -o -name "configure.ac" -o -name "configure.in" \
516 # | sort; echo configure)
519 for makefile in "${fails[@]}" ; do
520 ewarn "Failed to disable deprecation warnings in ${makefile}"