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 inherit eutils multilib 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"
102 # @FUNCTION: gnome2_gconf_savelist
104 # Find the GConf schemas that are about to be installed and save their location
105 # in the GNOME2_ECLASS_SCHEMAS environment variable.
106 # This function should be called from pkg_preinst.
107 gnome2_gconf_savelist() {
108 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
109 pushd "${ED}" > /dev/null || die
110 export GNOME2_ECLASS_SCHEMAS=$(find 'etc/gconf/schemas/' -name '*.schemas' 2> /dev/null)
111 popd > /dev/null || die
114 # @FUNCTION: gnome2_gconf_install
116 # Applies any schema files installed by the current ebuild to Gconf's database
118 # This function should be called from pkg_postinst.
119 gnome2_gconf_install() {
120 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
121 local updater="${EROOT}${GCONFTOOL_BIN}"
123 if [[ ! -x "${updater}" ]]; then
124 debug-print "${updater} is not executable"
128 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
129 debug-print "No GNOME 2 GConf schemas found"
133 # We are ready to install the GCONF Scheme now
134 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
135 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
137 einfo "Installing GNOME 2 GConf schemas"
140 for F in ${GNOME2_ECLASS_SCHEMAS}; do
141 if [[ -e "${EROOT}${F}" ]]; then
142 debug-print "Installing schema: ${F}"
143 "${updater}" --makefile-install-rule "${EROOT}${F}" 1>/dev/null
147 # have gconf reload the new schemas
148 pids=$(pgrep -x gconfd-2)
149 if [[ $? == 0 ]] ; then
150 ebegin "Reloading GConf schemas"
156 # @FUNCTION: gnome2_gconf_uninstall
158 # Removes schema files previously installed by the current ebuild from Gconf's
160 gnome2_gconf_uninstall() {
161 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
162 local updater="${EROOT}${GCONFTOOL_BIN}"
164 if [[ ! -x "${updater}" ]]; then
165 debug-print "${updater} is not executable"
169 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
170 debug-print "No GNOME 2 GConf schemas found"
174 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
175 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
177 einfo "Uninstalling GNOME 2 GConf schemas"
180 for F in ${GNOME2_ECLASS_SCHEMAS}; do
181 if [[ -e "${EROOT}${F}" ]]; then
182 debug-print "Uninstalling gconf schema: ${F}"
183 "${updater}" --makefile-uninstall-rule "${EROOT}${F}" 1>/dev/null
187 # have gconf reload the new schemas
188 pids=$(pgrep -x gconfd-2)
189 if [[ $? == 0 ]] ; then
190 ebegin "Reloading GConf schemas"
196 # @FUNCTION: gnome2_icon_savelist
198 # Find the icons that are about to be installed and save their location
199 # in the GNOME2_ECLASS_ICONS environment variable.
200 # This function should be called from pkg_preinst.
201 gnome2_icon_savelist() {
202 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
203 pushd "${ED}" > /dev/null || die
204 export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
205 popd > /dev/null || die
208 # @FUNCTION: gnome2_icon_cache_update
210 # Updates Gtk+ icon cache files under /usr/share/icons if the current ebuild
211 # have installed anything under that location.
212 # This function should be called from pkg_postinst and pkg_postrm.
213 gnome2_icon_cache_update() {
214 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
215 local updater="${EROOT}${GTK_UPDATE_ICON_CACHE}"
217 if [[ ! -x "${updater}" ]] ; then
218 debug-print "${updater} is not executable"
222 if [[ -z "${GNOME2_ECLASS_ICONS}" ]]; then
223 debug-print "No icon cache to update"
227 ebegin "Updating icons cache"
232 for dir in ${GNOME2_ECLASS_ICONS}
234 if [[ -f "${EROOT}${dir}/index.theme" ]] ; then
237 "${updater}" -qf "${EROOT}${dir}"
240 if [[ ! $rv -eq 0 ]] ; then
241 debug-print "Updating cache failed on ${EROOT}${dir}"
243 # Add to the list of failures
244 fails[$(( ${#fails[@]} + 1 ))]="${EROOT}${dir}"
248 elif [[ $(ls "${EROOT}${dir}") = "icon-theme.cache" ]]; then
249 # Clear stale cache files after theme uninstallation
250 rm "${EROOT}${dir}/icon-theme.cache"
253 if [[ -z $(ls "${EROOT}${dir}") ]]; then
254 # Clear empty theme directories after theme uninstallation
255 rmdir "${EROOT}${dir}"
261 for f in "${fails[@]}" ; do
262 eerror "Failed to update cache with icon $f"
266 # @FUNCTION: gnome2_omf_fix
268 # Workaround applied to Makefile rules in order to remove redundant
269 # calls to scrollkeeper-update and sandbox violations.
270 # This function should be called from src_prepare.
272 local omf_makefiles filename
276 if [[ -f ${S}/omf.make ]] ; then
277 omf_makefiles="${omf_makefiles} ${S}/omf.make"
280 if [[ -f ${S}/gnome-doc-utils.make ]] ; then
281 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
284 # testing fixing of all makefiles found
285 # The sort is important to ensure .am is listed before the respective .in for
286 # maintainer mode regeneration not kicking in due to .am being newer than .in
287 for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
288 omf_makefiles="${omf_makefiles} ${filename}"
291 ebegin "Fixing OMF Makefiles"
296 for omf in ${omf_makefiles} ; do
297 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
300 if [[ $retval -ne 0 ]] ; then
301 debug-print "updating of ${omf} failed"
303 # Add to the list of failures
304 fails[$(( ${#fails[@]} + 1 ))]=$omf
312 for f in "${fails[@]}" ; do
313 eerror "Failed to update OMF Makefile $f"
317 # @FUNCTION: gnome2_scrollkeeper_savelist
319 # Find the scrolls that are about to be installed and save their location
320 # in the GNOME2_ECLASS_SCROLLS environment variable.
321 # This function should be called from pkg_preinst.
322 gnome2_scrollkeeper_savelist() {
323 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
324 pushd "${ED}" > /dev/null || die
325 export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null)
326 popd > /dev/null || die
329 # @FUNCTION: gnome2_scrollkeeper_update
331 # Updates the global scrollkeeper database.
332 # This function should be called from pkg_postinst and pkg_postrm.
333 gnome2_scrollkeeper_update() {
334 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
335 local updater="${EROOT}${SCROLLKEEPER_UPDATE_BIN}"
337 if [[ ! -x "${updater}" ]] ; then
338 debug-print "${updater} is not executable"
342 if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
343 debug-print "No scroll cache to update"
347 ebegin "Updating scrollkeeper database ..."
348 "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
352 # @FUNCTION: gnome2_schemas_savelist
354 # Find if there is any GSettings schema to install and save the list in
355 # GNOME2_ECLASS_GLIB_SCHEMAS variable.
356 # This function should be called from pkg_preinst.
357 gnome2_schemas_savelist() {
358 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
359 pushd "${ED}" > /dev/null || die
360 export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
361 popd > /dev/null || die
364 # @FUNCTION: gnome2_schemas_update
365 # @USAGE: gnome2_schemas_update
367 # Updates GSettings schemas if GNOME2_ECLASS_GLIB_SCHEMAS has some.
368 # This function should be called from pkg_postinst and pkg_postrm.
369 gnome2_schemas_update() {
370 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
371 local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}"
373 if [[ ! -x ${updater} ]]; then
374 debug-print "${updater} is not executable"
378 if [[ -z ${GNOME2_ECLASS_GLIB_SCHEMAS} ]]; then
379 debug-print "No GSettings schemas to update"
383 ebegin "Updating GSettings schemas"
384 ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
388 # @FUNCTION: gnome2_gdk_pixbuf_savelist
390 # Find if there is any gdk-pixbuf loader to install and save the list in
391 # GNOME2_ECLASS_GDK_PIXBUF_LOADERS variable.
392 # This function should be called from pkg_preinst.
393 gnome2_gdk_pixbuf_savelist() {
394 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
395 pushd "${ED}" > /dev/null || die
396 export GNOME2_ECLASS_GDK_PIXBUF_LOADERS=$(find usr/lib*/gdk-pixbuf-2.0 -type f 2>/dev/null)
397 popd > /dev/null || die
400 # @FUNCTION: gnome2_gdk_pixbuf_update
401 # @USAGE: gnome2_gdk_pixbuf_update
403 # Updates gdk-pixbuf loader cache if GNOME2_ECLASS_GDK_PIXBUF_LOADERS has some.
404 # This function should be called from pkg_postinst and pkg_postrm.
405 gnome2_gdk_pixbuf_update() {
406 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
407 local updater="${EROOT}/usr/bin/${CHOST}-gdk-pixbuf-query-loaders"
409 if [[ ! -x ${updater} ]]; then
410 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
413 if [[ ! -x ${updater} ]]; then
414 debug-print "${updater} is not executable"
418 if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
419 debug-print "gdk-pixbuf loader cache does not need an update"
423 ebegin "Updating gdk-pixbuf loader cache"
424 local tmp_file=$(emktemp)
425 ${updater} 1> "${tmp_file}" &&
426 chmod 0644 "${tmp_file}" &&
427 cp -f "${tmp_file}" "${EROOT}usr/$(get_libdir)/gdk-pixbuf-2.0/2.10.0/loaders.cache" &&
428 rm "${tmp_file}" # don't replace this with mv, required for SELinux support
432 # @FUNCTION: gnome2_query_immodules_gtk2
433 # @USAGE: gnome2_query_immodules_gtk2
435 # Updates gtk2 immodules/gdk-pixbuf loaders listing.
436 gnome2_query_immodules_gtk2() {
437 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-2.0
438 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-2.0
440 ebegin "Updating gtk2 input method module cache"
441 GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-2.0/2.10.0/immodules.cache" \
442 "${updater}" --update-cache
446 # @FUNCTION: gnome2_query_immodules_gtk3
447 # @USAGE: gnome2_query_immodules_gtk3
449 # Updates gtk3 immodules/gdk-pixbuf loaders listing.
450 gnome2_query_immodules_gtk3() {
451 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-3.0
452 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-3.0
454 ebegin "Updating gtk3 input method module cache"
455 GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-3.0/3.0.0/immodules.cache" \
456 "${updater}" --update-cache
460 # @FUNCTION: gnome2_disable_deprecation_warning
462 # Disable deprecation warnings commonly found in glib based packages.
463 # Should be called from src_prepare.
464 gnome2_disable_deprecation_warning() {
469 ebegin "Disabling deprecation warnings"
470 # The sort is important to ensure .am is listed before the respective .in for
471 # maintainer mode regeneration not kicking in due to .am being newer than .in
472 while read makefile ; do
473 if ! grep -qE "(DISABLE_DEPRECATED|GSEAL_ENABLE)" "${makefile}"; then
478 -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(NULL):g' \
479 -e 's:-DGSEAL_ENABLE+[A-Z_]:$(NULL):g' \
482 if [[ $? -ne 0 ]]; then
483 # Add to the list of failures
484 fails+=( "${makefile}" )
487 done < <(find "${S}" -name "Makefile.in" \
488 -o -name "Makefile.am" -o -name "Makefile.decl" \
489 | sort; [[ -f "${S}"/configure ]] && echo configure)
490 # TODO: sedding configure.ac can trigger maintainer mode; bug #439602
491 # -o -name "configure.ac" -o -name "configure.in" \
492 # | sort; echo configure)
495 for makefile in "${fails[@]}" ; do
496 ewarn "Failed to disable deprecation warnings in ${makefile}"