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. This is only
211 # necessary for eclass implementations that call
212 # gnome2_icon_cache_update conditionally.
213 # This function should be called from pkg_preinst.
214 gnome2_icon_savelist() {
215 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
216 pushd "${ED}" > /dev/null || die
217 export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
218 popd > /dev/null || die
221 # @FUNCTION: gnome2_icon_cache_update
223 # Updates Gtk+ icon cache files under /usr/share/icons.
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 ebegin "Updating icons cache"
239 for dir in "${EROOT%/}"/usr/share/icons/*
241 if [[ -f "${dir}/index.theme" ]] ; then
244 "${updater}" -qf "${dir}"
247 if [[ ! $rv -eq 0 ]] ; then
248 debug-print "Updating cache failed on ${dir}"
250 # Add to the list of failures
255 elif [[ $(ls "${dir}") = "icon-theme.cache" ]]; then
256 # Clear stale cache files after theme uninstallation
257 rm "${dir}/icon-theme.cache"
260 if [[ -z $(ls "${dir}") ]]; then
261 # Clear empty theme directories after theme uninstallation
268 for f in "${fails[@]}" ; do
269 eerror "Failed to update cache with icon $f"
273 # @FUNCTION: gnome2_omf_fix
275 # Workaround applied to Makefile rules in order to remove redundant
276 # calls to scrollkeeper-update and sandbox violations.
277 # This function should be called from src_prepare.
279 local omf_makefiles filename
283 if [[ -f ${S}/omf.make ]] ; then
284 omf_makefiles="${omf_makefiles} ${S}/omf.make"
287 if [[ -f ${S}/gnome-doc-utils.make ]] ; then
288 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
291 # testing fixing of all makefiles found
292 # The sort is important to ensure .am is listed before the respective .in for
293 # maintainer mode regeneration not kicking in due to .am being newer than .in
294 for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
295 omf_makefiles="${omf_makefiles} ${filename}"
298 ebegin "Fixing OMF Makefiles"
303 for omf in ${omf_makefiles} ; do
304 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
307 if [[ $retval -ne 0 ]] ; then
308 debug-print "updating of ${omf} failed"
310 # Add to the list of failures
311 fails[$(( ${#fails[@]} + 1 ))]=$omf
319 for f in "${fails[@]}" ; do
320 eerror "Failed to update OMF Makefile $f"
324 # @FUNCTION: gnome2_scrollkeeper_savelist
326 # Find the scrolls that are about to be installed and save their location
327 # in the GNOME2_ECLASS_SCROLLS environment variable.
328 # This function should be called from pkg_preinst.
329 gnome2_scrollkeeper_savelist() {
330 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
331 pushd "${ED}" > /dev/null || die
332 export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null)
333 popd > /dev/null || die
336 # @FUNCTION: gnome2_scrollkeeper_update
338 # Updates the global scrollkeeper database.
339 # This function should be called from pkg_postinst and pkg_postrm.
340 gnome2_scrollkeeper_update() {
341 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
342 local updater="${EROOT}${SCROLLKEEPER_UPDATE_BIN}"
344 if [[ ! -x "${updater}" ]] ; then
345 debug-print "${updater} is not executable"
349 if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
350 debug-print "No scroll cache to update"
354 ebegin "Updating scrollkeeper database ..."
355 "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
359 # @FUNCTION: gnome2_schemas_savelist
361 # Find if there is any GSettings schema to install and save the list in
362 # GNOME2_ECLASS_GLIB_SCHEMAS variable. This is only necessary for eclass
363 # implementations that call gnome2_schemas_update conditionally.
364 # This function should be called from pkg_preinst.
365 gnome2_schemas_savelist() {
366 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
367 pushd "${ED}" > /dev/null || die
368 export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
369 popd > /dev/null || die
372 # @FUNCTION: gnome2_schemas_update
373 # @USAGE: gnome2_schemas_update
375 # Updates GSettings schemas.
376 # This function should be called from pkg_postinst and pkg_postrm.
377 gnome2_schemas_update() {
378 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
379 local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}"
381 if [[ ! -x ${updater} ]]; then
382 debug-print "${updater} is not executable"
386 ebegin "Updating GSettings schemas"
387 ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
391 # @FUNCTION: gnome2_gdk_pixbuf_savelist
393 # Find if there is any gdk-pixbuf loader to install and save the list in
394 # GNOME2_ECLASS_GDK_PIXBUF_LOADERS variable.
395 # This function should be called from pkg_preinst.
396 gnome2_gdk_pixbuf_savelist() {
397 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
398 pushd "${ED}" > /dev/null || die
399 export GNOME2_ECLASS_GDK_PIXBUF_LOADERS=$(find usr/lib*/gdk-pixbuf-2.0 -type f 2>/dev/null)
400 popd > /dev/null || die
403 # @FUNCTION: gnome2_gdk_pixbuf_update
404 # @USAGE: gnome2_gdk_pixbuf_update
406 # Updates gdk-pixbuf loader cache if GNOME2_ECLASS_GDK_PIXBUF_LOADERS has some.
407 # This function should be called from pkg_postinst and pkg_postrm.
408 gnome2_gdk_pixbuf_update() {
409 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
410 local updater="${EROOT}/usr/bin/${CHOST}-gdk-pixbuf-query-loaders"
412 if [[ ! -x ${updater} ]]; then
413 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
416 if [[ ! -x ${updater} ]]; then
417 debug-print "${updater} is not executable"
421 if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
422 debug-print "gdk-pixbuf loader cache does not need an update"
426 ebegin "Updating gdk-pixbuf loader cache"
427 local tmp_file=$(emktemp)
428 ${updater} 1> "${tmp_file}" &&
429 chmod 0644 "${tmp_file}" &&
430 cp -f "${tmp_file}" "${EROOT}usr/$(get_libdir)/gdk-pixbuf-2.0/2.10.0/loaders.cache" &&
431 rm "${tmp_file}" # don't replace this with mv, required for SELinux support
435 # @FUNCTION: gnome2_query_immodules_gtk2
436 # @USAGE: gnome2_query_immodules_gtk2
438 # Updates gtk2 immodules/gdk-pixbuf loaders listing.
439 gnome2_query_immodules_gtk2() {
440 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-2.0
441 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-2.0
443 ebegin "Updating gtk2 input method module cache"
444 GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-2.0/2.10.0/immodules.cache" \
445 "${updater}" --update-cache
449 # @FUNCTION: gnome2_query_immodules_gtk3
450 # @USAGE: gnome2_query_immodules_gtk3
452 # Updates gtk3 immodules/gdk-pixbuf loaders listing.
453 gnome2_query_immodules_gtk3() {
454 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-3.0
455 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-3.0
457 ebegin "Updating gtk3 input method module cache"
458 GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-3.0/3.0.0/immodules.cache" \
459 "${updater}" --update-cache
463 # @FUNCTION: gnome2_giomodule_cache_update
464 # @USAGE: gnome2_giomodule_cache_update
466 # Updates glib's gio modules cache.
467 # This function should be called from pkg_postinst and pkg_postrm.
468 gnome2_giomodule_cache_update() {
469 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
470 local updater="${EROOT}/usr/bin/${CHOST}-gio-querymodules"
472 if [[ ! -x ${updater} ]]; then
473 updater="${EROOT}/usr/bin/gio-querymodules"
476 if [[ ! -x ${updater} ]]; then
477 debug-print "${updater} is not executable"
481 ebegin "Updating GIO modules cache"
482 ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
486 # @FUNCTION: gnome2_disable_deprecation_warning
488 # Disable deprecation warnings commonly found in glib based packages.
489 # Should be called from src_prepare.
490 gnome2_disable_deprecation_warning() {
495 ebegin "Disabling deprecation warnings"
496 # The sort is important to ensure .am is listed before the respective .in for
497 # maintainer mode regeneration not kicking in due to .am being newer than .in
498 while read makefile ; do
499 if ! grep -qE "(DISABLE_DEPRECATED|GSEAL_ENABLE)" "${makefile}"; then
504 -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
505 -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
508 if [[ $? -ne 0 ]]; then
509 # Add to the list of failures
510 fails+=( "${makefile}" )
513 done < <(find "${S}" -name "Makefile.in" \
514 -o -name "Makefile.am" -o -name "Makefile.decl" \
515 | sort; [[ -f "${S}"/configure ]] && echo configure)
516 # TODO: sedding configure.ac can trigger maintainer mode; bug #439602
517 # -o -name "configure.ac" -o -name "configure.in" \
518 # | sort; echo configure)
521 for makefile in "${fails[@]}" ; do
522 ewarn "Failed to disable deprecation warnings in ${makefile}"