1 # Copyright 1999-2014 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
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() {
93 # Respected by >=glib-2.30.1-r1
96 # GST_REGISTRY is to work around gst utilities trying to read/write /root
97 export GST_REGISTRY="${T}/registry.xml"
99 # XXX: code for resetting XDG_* directories should probably be moved into
100 # a separate function in a non-gnome eclass
101 export XDG_DATA_HOME="${T}/.local/share"
102 export XDG_CONFIG_HOME="${T}/.config"
103 export XDG_CACHE_HOME="${T}/.cache"
104 export XDG_RUNTIME_DIR="${T}/run"
105 mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" \
107 # This directory needs to be owned by the user, and chmod 0700
108 # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
109 chmod 0700 "${XDG_RUNTIME_DIR}"
112 # @FUNCTION: gnome2_gconf_savelist
114 # Find the GConf schemas that are about to be installed and save their location
115 # in the GNOME2_ECLASS_SCHEMAS environment variable.
116 # This function should be called from pkg_preinst.
117 gnome2_gconf_savelist() {
118 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
119 pushd "${ED}" &> /dev/null
120 export GNOME2_ECLASS_SCHEMAS=$(find 'etc/gconf/schemas/' -name '*.schemas' 2> /dev/null)
124 # @FUNCTION: gnome2_gconf_install
126 # Applies any schema files installed by the current ebuild to Gconf's database
128 # This function should be called from pkg_postinst.
129 gnome2_gconf_install() {
130 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
131 local updater="${EROOT}${GCONFTOOL_BIN}"
133 if [[ ! -x "${updater}" ]]; then
134 debug-print "${updater} is not executable"
138 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
139 debug-print "No GNOME 2 GConf schemas found"
143 # We are ready to install the GCONF Scheme now
144 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
145 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
147 einfo "Installing GNOME 2 GConf schemas"
150 for F in ${GNOME2_ECLASS_SCHEMAS}; do
151 if [[ -e "${EROOT}${F}" ]]; then
152 debug-print "Installing schema: ${F}"
153 "${updater}" --makefile-install-rule "${EROOT}${F}" 1>/dev/null
157 # have gconf reload the new schemas
158 pids=$(pgrep -x gconfd-2)
159 if [[ $? == 0 ]] ; then
160 ebegin "Reloading GConf schemas"
166 # @FUNCTION: gnome2_gconf_uninstall
168 # Removes schema files previously installed by the current ebuild from Gconf's
170 gnome2_gconf_uninstall() {
171 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
172 local updater="${EROOT}${GCONFTOOL_BIN}"
174 if [[ ! -x "${updater}" ]]; then
175 debug-print "${updater} is not executable"
179 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
180 debug-print "No GNOME 2 GConf schemas found"
184 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
185 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
187 einfo "Uninstalling GNOME 2 GConf schemas"
190 for F in ${GNOME2_ECLASS_SCHEMAS}; do
191 if [[ -e "${EROOT}${F}" ]]; then
192 debug-print "Uninstalling gconf schema: ${F}"
193 "${updater}" --makefile-uninstall-rule "${EROOT}${F}" 1>/dev/null
197 # have gconf reload the new schemas
198 pids=$(pgrep -x gconfd-2)
199 if [[ $? == 0 ]] ; then
200 ebegin "Reloading GConf schemas"
206 # @FUNCTION: gnome2_icon_savelist
208 # Find the icons that are about to be installed and save their location
209 # in the GNOME2_ECLASS_ICONS environment variable.
210 # This function should be called from pkg_preinst.
211 gnome2_icon_savelist() {
212 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
213 pushd "${ED}" &> /dev/null
214 export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
218 # @FUNCTION: gnome2_icon_cache_update
220 # Updates Gtk+ icon cache files under /usr/share/icons if the current ebuild
221 # have installed anything under that location.
222 # This function should be called from pkg_postinst and pkg_postrm.
223 gnome2_icon_cache_update() {
224 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
225 local updater="${EROOT}${GTK_UPDATE_ICON_CACHE}"
227 if [[ ! -x "${updater}" ]] ; then
228 debug-print "${updater} is not executable"
232 if [[ -z "${GNOME2_ECLASS_ICONS}" ]]; then
233 debug-print "No icon cache to update"
237 ebegin "Updating icons cache"
242 for dir in ${GNOME2_ECLASS_ICONS}
244 if [[ -f "${EROOT}${dir}/index.theme" ]] ; then
247 "${updater}" -qf "${EROOT}${dir}"
250 if [[ ! $rv -eq 0 ]] ; then
251 debug-print "Updating cache failed on ${EROOT}${dir}"
253 # Add to the list of failures
254 fails[$(( ${#fails[@]} + 1 ))]="${EROOT}${dir}"
258 elif [[ $(ls "${EROOT}${dir}") = "icon-theme.cache" ]]; then
259 # Clear stale cache files after theme uninstallation
260 rm "${EROOT}${dir}/icon-theme.cache"
263 if [[ -z $(ls "${EROOT}${dir}") ]]; then
264 # Clear empty theme directories after theme uninstallation
265 rmdir "${EROOT}${dir}"
271 for f in "${fails[@]}" ; do
272 eerror "Failed to update cache with icon $f"
276 # @FUNCTION: gnome2_omf_fix
278 # Workaround applied to Makefile rules in order to remove redundant
279 # calls to scrollkeeper-update and sandbox violations.
280 # This function should be called from src_prepare.
282 local omf_makefiles filename
286 if [[ -f ${S}/omf.make ]] ; then
287 omf_makefiles="${omf_makefiles} ${S}/omf.make"
290 if [[ -f ${S}/gnome-doc-utils.make ]] ; then
291 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
294 # testing fixing of all makefiles found
295 # The sort is important to ensure .am is listed before the respective .in for
296 # maintainer mode regeneration not kicking in due to .am being newer than .in
297 for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
298 omf_makefiles="${omf_makefiles} ${filename}"
301 ebegin "Fixing OMF Makefiles"
306 for omf in ${omf_makefiles} ; do
307 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
310 if [[ $retval -ne 0 ]] ; then
311 debug-print "updating of ${omf} failed"
313 # Add to the list of failures
314 fails[$(( ${#fails[@]} + 1 ))]=$omf
322 for f in "${fails[@]}" ; do
323 eerror "Failed to update OMF Makefile $f"
327 # @FUNCTION: gnome2_scrollkeeper_savelist
329 # Find the scrolls that are about to be installed and save their location
330 # in the GNOME2_ECLASS_SCROLLS environment variable.
331 # This function should be called from pkg_preinst.
332 gnome2_scrollkeeper_savelist() {
333 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
334 pushd "${ED}" &> /dev/null
335 export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null)
339 # @FUNCTION: gnome2_scrollkeeper_update
341 # Updates the global scrollkeeper database.
342 # This function should be called from pkg_postinst and pkg_postrm.
343 gnome2_scrollkeeper_update() {
344 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
345 local updater="${EROOT}${SCROLLKEEPER_UPDATE_BIN}"
347 if [[ ! -x "${updater}" ]] ; then
348 debug-print "${updater} is not executable"
352 if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
353 debug-print "No scroll cache to update"
357 ebegin "Updating scrollkeeper database ..."
358 "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
362 # @FUNCTION: gnome2_schemas_savelist
364 # Find if there is any GSettings schema to install and save the list in
365 # GNOME2_ECLASS_GLIB_SCHEMAS variable.
366 # This function should be called from pkg_preinst.
367 gnome2_schemas_savelist() {
368 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
369 pushd "${ED}" &>/dev/null
370 export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
374 # @FUNCTION: gnome2_schemas_update
375 # @USAGE: gnome2_schemas_update
377 # Updates GSettings schemas if GNOME2_ECLASS_GLIB_SCHEMAS has some.
378 # This function should be called from pkg_postinst and pkg_postrm.
379 gnome2_schemas_update() {
380 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
381 local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}"
383 if [[ ! -x ${updater} ]]; then
384 debug-print "${updater} is not executable"
388 if [[ -z ${GNOME2_ECLASS_GLIB_SCHEMAS} ]]; then
389 debug-print "No GSettings schemas to update"
393 ebegin "Updating GSettings schemas"
394 ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
398 # @FUNCTION: gnome2_gdk_pixbuf_savelist
400 # Find if there is any gdk-pixbuf loader to install and save the list in
401 # GNOME2_ECLASS_GDK_PIXBUF_LOADERS variable.
402 # This function should be called from pkg_preinst.
403 gnome2_gdk_pixbuf_savelist() {
404 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
405 pushd "${ED}" 1>/dev/null
406 export GNOME2_ECLASS_GDK_PIXBUF_LOADERS=$(find usr/lib*/gdk-pixbuf-2.0 -type f 2>/dev/null)
410 # @FUNCTION: gnome2_gdk_pixbuf_update
411 # @USAGE: gnome2_gdk_pixbuf_update
413 # Updates gdk-pixbuf loader cache if GNOME2_ECLASS_GDK_PIXBUF_LOADERS has some.
414 # This function should be called from pkg_postinst and pkg_postrm.
415 gnome2_gdk_pixbuf_update() {
416 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
417 local updater="${EROOT}/usr/bin/${CHOST}-gdk-pixbuf-query-loaders"
419 if [[ ! -x ${updater} ]]; then
420 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
423 if [[ ! -x ${updater} ]]; then
424 debug-print "${updater} is not executable"
428 if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
429 debug-print "gdk-pixbuf loader cache does not need an update"
433 ebegin "Updating gdk-pixbuf loader cache"
434 local tmp_file=$(mktemp -t tmp.XXXXXXXXXX_gdkpixbuf)
435 ${updater} 1> "${tmp_file}" &&
436 chmod 0644 "${tmp_file}" &&
437 cp -f "${tmp_file}" "${EROOT}usr/$(get_libdir)/gdk-pixbuf-2.0/2.10.0/loaders.cache" &&
438 rm "${tmp_file}" # don't replace this with mv, required for SELinux support
442 # @FUNCTION: gnome2_query_immodules_gtk2
443 # @USAGE: gnome2_query_immodules_gtk2
445 # Updates gtk2 immodules/gdk-pixbuf loaders listing.
446 gnome2_query_immodules_gtk2() {
447 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-2.0
448 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-2.0
450 ebegin "Updating gtk2 input method module cache"
451 GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-2.0/2.10.0/immodules.cache" \
452 "${updater}" --update-cache
456 # @FUNCTION: gnome2_query_immodules_gtk3
457 # @USAGE: gnome2_query_immodules_gtk3
459 # Updates gtk3 immodules/gdk-pixbuf loaders listing.
460 gnome2_query_immodules_gtk3() {
461 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-3.0
462 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-3.0
464 ebegin "Updating gtk3 input method module cache"
465 GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-3.0/3.0.0/immodules.cache" \
466 "${updater}" --update-cache
470 # @FUNCTION: gnome2_disable_deprecation_warning
472 # Disable deprecation warnings commonly found in glib based packages.
473 # Should be called from src_prepare.
474 gnome2_disable_deprecation_warning() {
479 ebegin "Disabling deprecation warnings"
480 # The sort is important to ensure .am is listed before the respective .in for
481 # maintainer mode regeneration not kicking in due to .am being newer than .in
482 while read makefile ; do
483 if ! grep -qE "(DISABLE_DEPRECATED|GSEAL_ENABLE)" "${makefile}"; then
488 -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(NULL):g' \
489 -e 's:-DGSEAL_ENABLE+[A-Z_]:$(NULL):g' \
492 if [[ $? -ne 0 ]]; then
493 # Add to the list of failures
494 fails+=( "${makefile}" )
497 done < <(find "${S}" -name "Makefile.in" \
498 -o -name "Makefile.am" -o -name "Makefile.decl" \
499 | sort; echo configure)
500 # TODO: sedding configure.ac can trigger maintainer mode; bug #439602
501 # -o -name "configure.ac" -o -name "configure.in" \
502 # | sort; echo configure)
505 for makefile in "${fails[@]}" ; do
506 ewarn "Failed to disable deprecation warnings in ${makefile}"