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"
106 # @FUNCTION: gnome2_gconf_savelist
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
118 # @FUNCTION: gnome2_gconf_install
120 # Applies any schema files installed by the current ebuild to Gconf's database
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}"
127 if [[ ! -x "${updater}" ]]; then
128 debug-print "${updater} is not executable"
132 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
133 debug-print "No GNOME 2 GConf schemas found"
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};")"
141 einfo "Installing GNOME 2 GConf schemas"
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
151 # have gconf reload the new schemas
152 pids=$(pgrep -x gconfd-2)
153 if [[ $? == 0 ]] ; then
154 ebegin "Reloading GConf schemas"
160 # @FUNCTION: gnome2_gconf_uninstall
162 # Removes schema files previously installed by the current ebuild from Gconf's
164 gnome2_gconf_uninstall() {
165 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
166 local updater="${EROOT}${GCONFTOOL_BIN}"
168 if [[ ! -x "${updater}" ]]; then
169 debug-print "${updater} is not executable"
173 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
174 debug-print "No GNOME 2 GConf schemas found"
178 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
179 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
181 einfo "Uninstalling GNOME 2 GConf schemas"
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
191 # have gconf reload the new schemas
192 pids=$(pgrep -x gconfd-2)
193 if [[ $? == 0 ]] ; then
194 ebegin "Reloading GConf schemas"
200 # @FUNCTION: gnome2_icon_savelist
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
212 # @FUNCTION: gnome2_icon_cache_update
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}"
221 if [[ ! -x "${updater}" ]] ; then
222 debug-print "${updater} is not executable"
226 if [[ -z "${GNOME2_ECLASS_ICONS}" ]]; then
227 debug-print "No icon cache to update"
231 ebegin "Updating icons cache"
236 for dir in ${GNOME2_ECLASS_ICONS}
238 if [[ -f "${EROOT}${dir}/index.theme" ]] ; then
241 "${updater}" -qf "${EROOT}${dir}"
244 if [[ ! $rv -eq 0 ]] ; then
245 debug-print "Updating cache failed on ${EROOT}${dir}"
247 # Add to the list of failures
248 fails[$(( ${#fails[@]} + 1 ))]="${EROOT}${dir}"
252 elif [[ $(ls "${EROOT}${dir}") = "icon-theme.cache" ]]; then
253 # Clear stale cache files after theme uninstallation
254 rm "${EROOT}${dir}/icon-theme.cache"
257 if [[ -z $(ls "${EROOT}${dir}") ]]; then
258 # Clear empty theme directories after theme uninstallation
259 rmdir "${EROOT}${dir}"
265 for f in "${fails[@]}" ; do
266 eerror "Failed to update cache with icon $f"
270 # @FUNCTION: gnome2_omf_fix
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.
276 local omf_makefiles filename
280 if [[ -f ${S}/omf.make ]] ; then
281 omf_makefiles="${omf_makefiles} ${S}/omf.make"
284 if [[ -f ${S}/gnome-doc-utils.make ]] ; then
285 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
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}"
295 ebegin "Fixing OMF Makefiles"
300 for omf in ${omf_makefiles} ; do
301 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
304 if [[ $retval -ne 0 ]] ; then
305 debug-print "updating of ${omf} failed"
307 # Add to the list of failures
308 fails[$(( ${#fails[@]} + 1 ))]=$omf
316 for f in "${fails[@]}" ; do
317 eerror "Failed to update OMF Makefile $f"
321 # @FUNCTION: gnome2_scrollkeeper_savelist
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
333 # @FUNCTION: gnome2_scrollkeeper_update
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}"
341 if [[ ! -x "${updater}" ]] ; then
342 debug-print "${updater} is not executable"
346 if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
347 debug-print "No scroll cache to update"
351 ebegin "Updating scrollkeeper database ..."
352 "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
356 # @FUNCTION: gnome2_schemas_savelist
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
368 # @FUNCTION: gnome2_schemas_update
369 # @USAGE: gnome2_schemas_update
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}"
377 if [[ ! -x ${updater} ]]; then
378 debug-print "${updater} is not executable"
382 if [[ -z ${GNOME2_ECLASS_GLIB_SCHEMAS} ]]; then
383 debug-print "No GSettings schemas to update"
387 ebegin "Updating GSettings schemas"
388 ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
392 # @FUNCTION: gnome2_gdk_pixbuf_savelist
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
404 # @FUNCTION: gnome2_gdk_pixbuf_update
405 # @USAGE: gnome2_gdk_pixbuf_update
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"
413 if [[ ! -x ${updater} ]]; then
414 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
417 if [[ ! -x ${updater} ]]; then
418 debug-print "${updater} is not executable"
422 if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
423 debug-print "gdk-pixbuf loader cache does not need an update"
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
436 # @FUNCTION: gnome2_query_immodules_gtk2
437 # @USAGE: gnome2_query_immodules_gtk2
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
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
450 # @FUNCTION: gnome2_query_immodules_gtk3
451 # @USAGE: gnome2_query_immodules_gtk3
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
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
464 # @FUNCTION: gnome2_giomodule_cache_update
465 # @USAGE: gnome2_giomodule_cache_update
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"
473 if [[ ! -x ${updater} ]]; then
474 updater="${EROOT}/usr/bin/gio-querymodules"
477 if [[ ! -x ${updater} ]]; then
478 debug-print "${updater} is not executable"
482 ebegin "Updating GIO modules cache"
483 ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
487 # @FUNCTION: gnome2_disable_deprecation_warning
489 # Disable deprecation warnings commonly found in glib based packages.
490 # Should be called from src_prepare.
491 gnome2_disable_deprecation_warning() {
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
505 -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
506 -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
509 if [[ $? -ne 0 ]]; then
510 # Add to the list of failures
511 fails+=( "${makefile}" )
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)
522 for makefile in "${fails[@]}" ; do
523 ewarn "Failed to disable deprecation warnings in ${makefile}"