1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: gnome2-utils.eclass
7 # @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
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 # * GSettings schemas management
14 # * GConf schemas management
15 # * scrollkeeper (old Gnome help system) management
17 [[ ${EAPI:-0} == [012345] ]] && inherit multilib
18 [[ ${EAPI:-0} == [0123456] ]] && inherit eutils
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: GLIB_COMPILE_SCHEMAS
47 # Path to glib-compile-schemas
48 : ${GLIB_COMPILE_SCHEMAS:="/usr/bin/glib-compile-schemas"}
50 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCHEMAS
54 # List of GConf schemas provided by the package
56 # @ECLASS-VARIABLE: GNOME2_ECLASS_ICONS
60 # List of icons provided by the package
62 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCROLLS
66 # List of scrolls (documentation files) provided by the package
68 # @ECLASS-VARIABLE: GNOME2_ECLASS_GLIB_SCHEMAS
72 # List of GSettings schemas provided by the package
74 # @ECLASS-VARIABLE: GNOME2_ECLASS_GDK_PIXBUF_LOADERS
78 # List of gdk-pixbuf loaders provided by the package
81 # @FUNCTION: gnome2_environment_reset
83 # Reset various variables inherited from root's evironment to a reasonable
84 # default for ebuilds to help avoid access violations and test failures.
85 gnome2_environment_reset() {
88 # Respected by >=glib-2.30.1-r1
91 # GST_REGISTRY is to work around gst utilities trying to read/write /root
92 export GST_REGISTRY="${T}/registry.xml"
94 # Ensure we don't rely on dconf/gconf while building, bug #511946
95 export GSETTINGS_BACKEND="memory"
97 if has ${EAPI:-0} 6 7; then
98 # Try to cover the packages honoring this variable, bug #508124
99 export GST_INSPECT="$(type -P true)"
101 # Stop relying on random DISPLAY variable values, bug #534312
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_omf_fix
202 # Workaround applied to Makefile rules in order to remove redundant
203 # calls to scrollkeeper-update and sandbox violations.
204 # This function should be called from src_prepare.
206 local omf_makefiles filename
210 if [[ -f ${S}/omf.make ]] ; then
211 omf_makefiles="${omf_makefiles} ${S}/omf.make"
214 if [[ -f ${S}/gnome-doc-utils.make ]] ; then
215 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
218 # testing fixing of all makefiles found
219 # The sort is important to ensure .am is listed before the respective .in for
220 # maintainer mode regeneration not kicking in due to .am being newer than .in
221 for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
222 omf_makefiles="${omf_makefiles} ${filename}"
225 ebegin "Fixing OMF Makefiles"
230 for omf in ${omf_makefiles} ; do
231 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
234 if [[ $retval -ne 0 ]] ; then
235 debug-print "updating of ${omf} failed"
237 # Add to the list of failures
238 fails[$(( ${#fails[@]} + 1 ))]=$omf
246 for f in "${fails[@]}" ; do
247 eerror "Failed to update OMF Makefile $f"
251 # @FUNCTION: gnome2_scrollkeeper_savelist
253 # Find the scrolls that are about to be installed and save their location
254 # in the GNOME2_ECLASS_SCROLLS environment variable.
255 # This function should be called from pkg_preinst.
256 gnome2_scrollkeeper_savelist() {
257 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
258 pushd "${ED}" > /dev/null || die
259 export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null)
260 popd > /dev/null || die
263 # @FUNCTION: gnome2_scrollkeeper_update
265 # Updates the global scrollkeeper database.
266 # This function should be called from pkg_postinst and pkg_postrm.
267 gnome2_scrollkeeper_update() {
268 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
269 local updater="${EROOT}${SCROLLKEEPER_UPDATE_BIN}"
271 if [[ ! -x "${updater}" ]] ; then
272 debug-print "${updater} is not executable"
276 if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
277 debug-print "No scroll cache to update"
281 ebegin "Updating scrollkeeper database ..."
282 "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
286 # @FUNCTION: gnome2_schemas_savelist
288 # Find if there is any GSettings schema to install and save the list in
289 # GNOME2_ECLASS_GLIB_SCHEMAS variable. This is only necessary for eclass
290 # implementations that call gnome2_schemas_update conditionally.
291 # This function should be called from pkg_preinst.
292 gnome2_schemas_savelist() {
293 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
294 pushd "${ED}" > /dev/null || die
295 export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
296 popd > /dev/null || die
299 # @FUNCTION: gnome2_schemas_update
300 # @USAGE: gnome2_schemas_update
302 # Updates GSettings schemas.
303 # This function should be called from pkg_postinst and pkg_postrm.
304 gnome2_schemas_update() {
305 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
306 local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}"
308 if [[ ! -x ${updater} ]]; then
309 debug-print "${updater} is not executable"
313 ebegin "Updating GSettings schemas"
314 ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
318 # @FUNCTION: gnome2_gdk_pixbuf_savelist
320 # Find if there is any gdk-pixbuf loader to install and save the list in
321 # GNOME2_ECLASS_GDK_PIXBUF_LOADERS variable.
322 # This function should be called from pkg_preinst.
323 gnome2_gdk_pixbuf_savelist() {
324 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
325 pushd "${ED}" > /dev/null || die
326 export GNOME2_ECLASS_GDK_PIXBUF_LOADERS=$(find usr/lib*/gdk-pixbuf-2.0 -type f 2>/dev/null)
327 popd > /dev/null || die
330 # @FUNCTION: gnome2_gdk_pixbuf_update
331 # @USAGE: gnome2_gdk_pixbuf_update
333 # Updates gdk-pixbuf loader cache if GNOME2_ECLASS_GDK_PIXBUF_LOADERS has some.
334 # This function should be called from pkg_postinst and pkg_postrm.
335 gnome2_gdk_pixbuf_update() {
336 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
337 local updater="${EROOT}/usr/bin/${CHOST}-gdk-pixbuf-query-loaders"
339 if [[ ! -x ${updater} ]]; then
340 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
343 if [[ ! -x ${updater} ]]; then
344 debug-print "${updater} is not executable"
348 if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
349 debug-print "gdk-pixbuf loader cache does not need an update"
353 ebegin "Updating gdk-pixbuf loader cache"
354 local tmp_file=$(emktemp)
355 ${updater} 1> "${tmp_file}" &&
356 chmod 0644 "${tmp_file}" &&
357 cp -f "${tmp_file}" "${EROOT}usr/$(get_libdir)/gdk-pixbuf-2.0/2.10.0/loaders.cache" &&
358 rm "${tmp_file}" # don't replace this with mv, required for SELinux support
362 # @FUNCTION: gnome2_query_immodules_gtk2
363 # @USAGE: gnome2_query_immodules_gtk2
365 # Updates gtk2 immodules/gdk-pixbuf loaders listing.
366 gnome2_query_immodules_gtk2() {
367 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-2.0
368 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-2.0
370 ebegin "Updating gtk2 input method module cache"
371 GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-2.0/2.10.0/immodules.cache" \
372 "${updater}" --update-cache
376 # @FUNCTION: gnome2_query_immodules_gtk3
377 # @USAGE: gnome2_query_immodules_gtk3
379 # Updates gtk3 immodules/gdk-pixbuf loaders listing.
380 gnome2_query_immodules_gtk3() {
381 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-3.0
382 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-3.0
384 ebegin "Updating gtk3 input method module cache"
385 GTK_IM_MODULE_FILE="${EROOT}usr/$(get_libdir)/gtk-3.0/3.0.0/immodules.cache" \
386 "${updater}" --update-cache
390 # @FUNCTION: gnome2_giomodule_cache_update
391 # @USAGE: gnome2_giomodule_cache_update
393 # Updates glib's gio modules cache.
394 # This function should be called from pkg_postinst and pkg_postrm.
395 gnome2_giomodule_cache_update() {
396 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
397 local updater="${EROOT}/usr/bin/${CHOST}-gio-querymodules"
399 if [[ ! -x ${updater} ]]; then
400 updater="${EROOT}/usr/bin/gio-querymodules"
403 if [[ ! -x ${updater} ]]; then
404 debug-print "${updater} is not executable"
408 ebegin "Updating GIO modules cache"
409 ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
413 # @FUNCTION: gnome2_disable_deprecation_warning
415 # Disable deprecation warnings commonly found in glib based packages.
416 # Should be called from src_prepare.
417 gnome2_disable_deprecation_warning() {
422 ebegin "Disabling deprecation warnings"
423 # The sort is important to ensure .am is listed before the respective .in for
424 # maintainer mode regeneration not kicking in due to .am being newer than .in
425 while read makefile ; do
426 if ! grep -qE "(DISABLE_DEPRECATED|GSEAL_ENABLE)" "${makefile}"; then
431 -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
432 -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
435 if [[ $? -ne 0 ]]; then
436 # Add to the list of failures
437 fails+=( "${makefile}" )
440 done < <(find "${S}" -name "Makefile.in" \
441 -o -name "Makefile.am" -o -name "Makefile.decl" \
442 | sort; [[ -f "${S}"/configure ]] && echo configure)
443 # TODO: sedding configure.ac can trigger maintainer mode; bug #439602
444 # -o -name "configure.ac" -o -name "configure.in" \
445 # | sort; echo configure)
448 for makefile in "${fails[@]}" ; do
449 ewarn "Failed to disable deprecation warnings in ${makefile}"
456 # @FUNCTION: gnome2_icon_savelist
458 # Find the icons that are about to be installed and save their location
459 # in the GNOME2_ECLASS_ICONS environment variable. This is only
460 # necessary for eclass implementations that call
461 # gnome2_icon_cache_update conditionally.
462 # This function should be called from pkg_preinst.
463 gnome2_icon_savelist() {
464 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
465 pushd "${ED}" > /dev/null || die
466 export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
467 popd > /dev/null || die
470 # @FUNCTION: gnome2_icon_cache_update
472 # Updates Gtk+ icon cache files under /usr/share/icons.
473 # Deprecated. Please use xdg_icon_cache_update from xdg-utils.eclass
474 gnome2_icon_cache_update() {
475 xdg_icon_cache_update