1 # Copyright 1999-2020 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 # eutils.eclass: emktemp
19 # xdg-utils.eclass: xdg_environment_reset, xdg_icon_cache_update
20 inherit eutils xdg-utils
24 *) die "EAPI=${EAPI} is not supported" ;;
27 # @ECLASS-VARIABLE: GCONFTOOL_BIN
31 : ${GCONFTOOL_BIN:="/usr/bin/gconftool-2"}
33 # @ECLASS-VARIABLE: SCROLLKEEPER_DIR
36 # Directory where scrollkeeper-update should do its work
37 : ${SCROLLKEEPER_DIR:="/var/lib/scrollkeeper"}
39 # @ECLASS-VARIABLE: SCROLLKEEPER_UPDATE_BIN
42 # Path to scrollkeeper-update
43 : ${SCROLLKEEPER_UPDATE_BIN:="/usr/bin/scrollkeeper-update"}
45 # @ECLASS-VARIABLE: GLIB_COMPILE_SCHEMAS
48 # Path to glib-compile-schemas
49 : ${GLIB_COMPILE_SCHEMAS:="/usr/bin/glib-compile-schemas"}
51 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCHEMAS
55 # List of GConf schemas provided by the package
57 # @ECLASS-VARIABLE: GNOME2_ECLASS_ICONS
61 # List of icons provided by the package
63 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCROLLS
67 # List of scrolls (documentation files) provided by the package
69 # @ECLASS-VARIABLE: GNOME2_ECLASS_GLIB_SCHEMAS
73 # List of GSettings schemas provided by the package
75 # @ECLASS-VARIABLE: GNOME2_ECLASS_GDK_PIXBUF_LOADERS
79 # List of gdk-pixbuf loaders provided by the package
82 # @FUNCTION: gnome2_environment_reset
84 # Reset various variables inherited from root's evironment to a reasonable
85 # default for ebuilds to help avoid access violations and test failures.
86 gnome2_environment_reset() {
89 # Respected by >=glib-2.30.1-r1
92 # GST_REGISTRY is to work around gst utilities trying to read/write /root
93 export GST_REGISTRY="${T}/registry.xml"
95 # Ensure we don't rely on dconf/gconf while building, bug #511946
96 export GSETTINGS_BACKEND="memory"
98 if has ${EAPI:-0} 6 7; then
99 # Try to cover the packages honoring this variable, bug #508124
100 export GST_INSPECT="$(type -P true)"
102 # Stop relying on random DISPLAY variable values, bug #534312
107 # @FUNCTION: gnome2_gconf_savelist
109 # Find the GConf schemas that are about to be installed and save their location
110 # in the GNOME2_ECLASS_SCHEMAS environment variable.
111 # This function should be called from pkg_preinst.
112 gnome2_gconf_savelist() {
113 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
114 pushd "${ED}" > /dev/null || die
115 export GNOME2_ECLASS_SCHEMAS=$(find 'etc/gconf/schemas/' -name '*.schemas' 2> /dev/null)
116 popd > /dev/null || die
119 # @FUNCTION: gnome2_gconf_install
121 # Applies any schema files installed by the current ebuild to Gconf's database
123 # This function should be called from pkg_postinst.
124 gnome2_gconf_install() {
125 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
126 local updater="${EROOT%/}${GCONFTOOL_BIN}"
128 if [[ ! -x "${updater}" ]]; then
129 debug-print "${updater} is not executable"
133 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
134 debug-print "No GNOME 2 GConf schemas found"
138 # We are ready to install the GCONF Scheme now
139 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
140 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT%/}/;")"
142 einfo "Installing GNOME 2 GConf schemas"
145 for F in ${GNOME2_ECLASS_SCHEMAS}; do
146 if [[ -e "${EROOT%/}/${F}" ]]; then
147 debug-print "Installing schema: ${F}"
148 "${updater}" --makefile-install-rule "${EROOT%/}/${F}" 1>/dev/null
152 # have gconf reload the new schemas
153 pids=$(pgrep -x gconfd-2)
154 if [[ $? == 0 ]] ; then
155 ebegin "Reloading GConf schemas"
161 # @FUNCTION: gnome2_gconf_uninstall
163 # Removes schema files previously installed by the current ebuild from Gconf's
165 gnome2_gconf_uninstall() {
166 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
167 local updater="${EROOT%/}${GCONFTOOL_BIN}"
169 if [[ ! -x "${updater}" ]]; then
170 debug-print "${updater} is not executable"
174 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
175 debug-print "No GNOME 2 GConf schemas found"
179 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
180 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT%/}/;")"
182 einfo "Uninstalling GNOME 2 GConf schemas"
185 for F in ${GNOME2_ECLASS_SCHEMAS}; do
186 if [[ -e "${EROOT%/}/${F}" ]]; then
187 debug-print "Uninstalling gconf schema: ${F}"
188 "${updater}" --makefile-uninstall-rule "${EROOT%/}/${F}" 1>/dev/null
192 # have gconf reload the new schemas
193 pids=$(pgrep -x gconfd-2)
194 if [[ $? == 0 ]] ; then
195 ebegin "Reloading GConf schemas"
201 # @FUNCTION: gnome2_omf_fix
203 # Workaround applied to Makefile rules in order to remove redundant
204 # calls to scrollkeeper-update and sandbox violations.
205 # This function should be called from src_prepare.
207 local omf_makefiles filename
211 if [[ -f ${S}/omf.make ]] ; then
212 omf_makefiles="${omf_makefiles} ${S}/omf.make"
215 if [[ -f ${S}/gnome-doc-utils.make ]] ; then
216 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
219 # testing fixing of all makefiles found
220 # The sort is important to ensure .am is listed before the respective .in for
221 # maintainer mode regeneration not kicking in due to .am being newer than .in
222 for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
223 omf_makefiles="${omf_makefiles} ${filename}"
226 ebegin "Fixing OMF Makefiles"
231 for omf in ${omf_makefiles} ; do
232 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
235 if [[ $retval -ne 0 ]] ; then
236 debug-print "updating of ${omf} failed"
238 # Add to the list of failures
239 fails[$(( ${#fails[@]} + 1 ))]=$omf
247 for f in "${fails[@]}" ; do
248 eerror "Failed to update OMF Makefile $f"
252 # @FUNCTION: gnome2_scrollkeeper_savelist
254 # Find the scrolls that are about to be installed and save their location
255 # in the GNOME2_ECLASS_SCROLLS environment variable.
256 # This function should be called from pkg_preinst.
257 gnome2_scrollkeeper_savelist() {
258 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
259 pushd "${ED}" > /dev/null || die
260 export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null)
261 popd > /dev/null || die
264 # @FUNCTION: gnome2_scrollkeeper_update
266 # Updates the global scrollkeeper database.
267 # This function should be called from pkg_postinst and pkg_postrm.
268 gnome2_scrollkeeper_update() {
269 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
270 local updater="${EROOT%/}${SCROLLKEEPER_UPDATE_BIN}"
272 if [[ ! -x "${updater}" ]] ; then
273 debug-print "${updater} is not executable"
277 if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
278 debug-print "No scroll cache to update"
282 ebegin "Updating scrollkeeper database ..."
283 "${updater}" -q -p "${EROOT%/}${SCROLLKEEPER_DIR}"
287 # @FUNCTION: gnome2_schemas_savelist
289 # Find if there is any GSettings schema to install and save the list in
290 # GNOME2_ECLASS_GLIB_SCHEMAS variable. This is only necessary for eclass
291 # implementations that call gnome2_schemas_update conditionally.
292 # This function should be called from pkg_preinst.
293 gnome2_schemas_savelist() {
294 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
295 pushd "${ED}" > /dev/null || die
296 export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
297 popd > /dev/null || die
300 # @FUNCTION: 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
332 # Updates gdk-pixbuf loader cache if GNOME2_ECLASS_GDK_PIXBUF_LOADERS has some.
333 # This function should be called from pkg_postinst and pkg_postrm.
334 gnome2_gdk_pixbuf_update() {
335 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
336 local updater="${EROOT%/}/usr/bin/${CHOST}-gdk-pixbuf-query-loaders"
338 if [[ ! -x ${updater} ]]; then
339 updater="${EROOT%/}/usr/bin/gdk-pixbuf-query-loaders"
342 if [[ ! -x ${updater} ]]; then
343 debug-print "${updater} is not executable"
347 if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
348 debug-print "gdk-pixbuf loader cache does not need an update"
352 ebegin "Updating gdk-pixbuf loader cache"
353 local tmp_file=$(emktemp)
354 ${updater} 1> "${tmp_file}" &&
355 chmod 0644 "${tmp_file}" &&
356 cp -f "${tmp_file}" "${EROOT%/}/usr/$(get_libdir)/gdk-pixbuf-2.0/2.10.0/loaders.cache" &&
357 rm "${tmp_file}" # don't replace this with mv, required for SELinux support
361 # @FUNCTION: gnome2_query_immodules_gtk2
363 # Updates gtk2 immodules/gdk-pixbuf loaders listing.
364 gnome2_query_immodules_gtk2() {
365 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-2.0
366 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-2.0
368 ebegin "Updating gtk2 input method module cache"
369 GTK_IM_MODULE_FILE="${EROOT%/}/usr/$(get_libdir)/gtk-2.0/2.10.0/immodules.cache" \
370 "${updater}" --update-cache
374 # @FUNCTION: gnome2_query_immodules_gtk3
376 # Updates gtk3 immodules/gdk-pixbuf loaders listing.
377 gnome2_query_immodules_gtk3() {
378 local updater=${EPREFIX}/usr/bin/${CHOST}-gtk-query-immodules-3.0
379 [[ ! -x ${updater} ]] && updater=${EPREFIX}/usr/bin/gtk-query-immodules-3.0
381 ebegin "Updating gtk3 input method module cache"
382 GTK_IM_MODULE_FILE="${EROOT%/}/usr/$(get_libdir)/gtk-3.0/3.0.0/immodules.cache" \
383 "${updater}" --update-cache
387 # @FUNCTION: gnome2_giomodule_cache_update
389 # Updates glib's gio modules cache.
390 # This function should be called from pkg_postinst and pkg_postrm.
391 gnome2_giomodule_cache_update() {
392 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
393 local updater="${EROOT%/}/usr/bin/${CHOST}-gio-querymodules"
395 if [[ ! -x ${updater} ]]; then
396 updater="${EROOT%/}/usr/bin/gio-querymodules"
399 if [[ ! -x ${updater} ]]; then
400 debug-print "${updater} is not executable"
404 ebegin "Updating GIO modules cache"
405 ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
409 # @FUNCTION: gnome2_disable_deprecation_warning
411 # Disable deprecation warnings commonly found in glib based packages.
412 # Should be called from src_prepare.
413 gnome2_disable_deprecation_warning() {
418 ebegin "Disabling deprecation warnings"
419 # The sort is important to ensure .am is listed before the respective .in for
420 # maintainer mode regeneration not kicking in due to .am being newer than .in
421 while read makefile ; do
422 if ! grep -qE "(DISABLE_DEPRECATED|GSEAL_ENABLE)" "${makefile}"; then
427 -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
428 -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
431 if [[ $? -ne 0 ]]; then
432 # Add to the list of failures
433 fails+=( "${makefile}" )
436 done < <(find "${S}" -name "Makefile.in" \
437 -o -name "Makefile.am" -o -name "Makefile.decl" \
438 | sort; [[ -f "${S}"/configure ]] && echo configure)
439 # TODO: sedding configure.ac can trigger maintainer mode; bug #439602
440 # -o -name "configure.ac" -o -name "configure.in" \
441 # | sort; echo configure)
444 for makefile in "${fails[@]}" ; do
445 ewarn "Failed to disable deprecation warnings in ${makefile}"
452 # @FUNCTION: gnome2_icon_savelist
454 # Find the icons that are about to be installed and save their location
455 # in the GNOME2_ECLASS_ICONS environment variable. This is only
456 # necessary for eclass implementations that call
457 # gnome2_icon_cache_update conditionally.
458 # This function should be called from pkg_preinst.
459 gnome2_icon_savelist() {
460 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
461 pushd "${ED}" > /dev/null || die
462 export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
463 popd > /dev/null || die
466 # @FUNCTION: gnome2_icon_cache_update
468 # Updates Gtk+ icon cache files under /usr/share/icons.
469 # Deprecated. Please use xdg_icon_cache_update from xdg-utils.eclass
470 gnome2_icon_cache_update() {
471 xdg_icon_cache_update