dev-qt/qttest: stable 5.14.2 for ppc, bug #719732
[gentoo.git] / eclass / gnome2-utils.eclass
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: gnome2-utils.eclass
5 # @MAINTAINER:
6 # gnome@gentoo.org
7 # @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
8 # @BLURB: Auxiliary functions commonly used by Gnome packages.
9 # @DESCRIPTION:
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
16
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
21
22 case "${EAPI:-0}" in
23         0|1|2|3|4|5|6|7) ;;
24         *) die "EAPI=${EAPI} is not supported" ;;
25 esac
26
27 # @ECLASS-VARIABLE: GCONFTOOL_BIN
28 # @INTERNAL
29 # @DESCRIPTION:
30 # Path to gconftool-2
31 : ${GCONFTOOL_BIN:="/usr/bin/gconftool-2"}
32
33 # @ECLASS-VARIABLE: SCROLLKEEPER_DIR
34 # @INTERNAL
35 # @DESCRIPTION:
36 # Directory where scrollkeeper-update should do its work
37 : ${SCROLLKEEPER_DIR:="/var/lib/scrollkeeper"}
38
39 # @ECLASS-VARIABLE: SCROLLKEEPER_UPDATE_BIN
40 # @INTERNAL
41 # @DESCRIPTION:
42 # Path to scrollkeeper-update
43 : ${SCROLLKEEPER_UPDATE_BIN:="/usr/bin/scrollkeeper-update"}
44
45 # @ECLASS-VARIABLE: GLIB_COMPILE_SCHEMAS
46 # @INTERNAL
47 # @DESCRIPTION:
48 # Path to glib-compile-schemas
49 : ${GLIB_COMPILE_SCHEMAS:="/usr/bin/glib-compile-schemas"}
50
51 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCHEMAS
52 # @INTERNAL
53 # @DEFAULT_UNSET
54 # @DESCRIPTION:
55 # List of GConf schemas provided by the package
56
57 # @ECLASS-VARIABLE: GNOME2_ECLASS_ICONS
58 # @INTERNAL
59 # @DEFAULT_UNSET
60 # @DESCRIPTION:
61 # List of icons provided by the package
62
63 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCROLLS
64 # @INTERNAL
65 # @DEFAULT_UNSET
66 # @DESCRIPTION:
67 # List of scrolls (documentation files) provided by the package
68
69 # @ECLASS-VARIABLE: GNOME2_ECLASS_GLIB_SCHEMAS
70 # @INTERNAL
71 # @DEFAULT_UNSET
72 # @DESCRIPTION:
73 # List of GSettings schemas provided by the package
74
75 # @ECLASS-VARIABLE: GNOME2_ECLASS_GDK_PIXBUF_LOADERS
76 # @INTERNAL
77 # @DEFAULT_UNSET
78 # @DESCRIPTION:
79 # List of gdk-pixbuf loaders provided by the package
80
81
82 # @FUNCTION: gnome2_environment_reset
83 # @DESCRIPTION:
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() {
87         xdg_environment_reset
88
89         # Respected by >=glib-2.30.1-r1
90         export G_HOME="${T}"
91
92         # GST_REGISTRY is to work around gst utilities trying to read/write /root
93         export GST_REGISTRY="${T}/registry.xml"
94
95         # Ensure we don't rely on dconf/gconf while building, bug #511946
96         export GSETTINGS_BACKEND="memory"
97
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)"
101
102                 # Stop relying on random DISPLAY variable values, bug #534312
103                 unset DISPLAY
104         fi
105 }
106
107 # @FUNCTION: gnome2_gconf_savelist
108 # @DESCRIPTION:
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
117 }
118
119 # @FUNCTION: gnome2_gconf_install
120 # @DESCRIPTION:
121 # Applies any schema files installed by the current ebuild to Gconf's database
122 # using gconftool-2.
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}"
127
128         if [[ ! -x "${updater}" ]]; then
129                 debug-print "${updater} is not executable"
130                 return
131         fi
132
133         if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
134                 debug-print "No GNOME 2 GConf schemas found"
135                 return
136         fi
137
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%/}/;")"
141
142         einfo "Installing GNOME 2 GConf schemas"
143
144         local F
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
149                 fi
150         done
151
152         # have gconf reload the new schemas
153         pids=$(pgrep -x gconfd-2)
154         if [[ $? == 0 ]] ; then
155                 ebegin "Reloading GConf schemas"
156                 kill -HUP ${pids}
157                 eend $?
158         fi
159 }
160
161 # @FUNCTION: gnome2_gconf_uninstall
162 # @DESCRIPTION:
163 # Removes schema files previously installed by the current ebuild from Gconf's
164 # database.
165 gnome2_gconf_uninstall() {
166         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
167         local updater="${EROOT%/}${GCONFTOOL_BIN}"
168
169         if [[ ! -x "${updater}" ]]; then
170                 debug-print "${updater} is not executable"
171                 return
172         fi
173
174         if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
175                 debug-print "No GNOME 2 GConf schemas found"
176                 return
177         fi
178
179         unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
180         export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT%/}/;")"
181
182         einfo "Uninstalling GNOME 2 GConf schemas"
183
184         local F
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
189                 fi
190         done
191
192         # have gconf reload the new schemas
193         pids=$(pgrep -x gconfd-2)
194         if [[ $? == 0 ]] ; then
195                 ebegin "Reloading GConf schemas"
196                 kill -HUP ${pids}
197                 eend $?
198         fi
199 }
200
201 # @FUNCTION: gnome2_omf_fix
202 # @DESCRIPTION:
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.
206 gnome2_omf_fix() {
207         local omf_makefiles filename
208
209         omf_makefiles="$@"
210
211         if [[ -f ${S}/omf.make ]] ; then
212                 omf_makefiles="${omf_makefiles} ${S}/omf.make"
213         fi
214
215         if [[ -f ${S}/gnome-doc-utils.make ]] ; then
216                 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
217         fi
218
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}"
224         done
225
226         ebegin "Fixing OMF Makefiles"
227
228         local retval=0
229         local fails=( )
230
231         for omf in ${omf_makefiles} ; do
232                 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
233                 retval=$?
234
235                 if [[ $retval -ne 0 ]] ; then
236                         debug-print "updating of ${omf} failed"
237
238                         # Add to the list of failures
239                         fails[$(( ${#fails[@]} + 1 ))]=$omf
240
241                         retval=2
242                 fi
243         done
244
245         eend $retval
246
247         for f in "${fails[@]}" ; do
248                 eerror "Failed to update OMF Makefile $f"
249         done
250 }
251
252 # @FUNCTION: gnome2_scrollkeeper_savelist
253 # @DESCRIPTION:
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
262 }
263
264 # @FUNCTION: gnome2_scrollkeeper_update
265 # @DESCRIPTION:
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}"
271
272         if [[ ! -x "${updater}" ]] ; then
273                 debug-print "${updater} is not executable"
274                 return
275         fi
276
277         if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
278                 debug-print "No scroll cache to update"
279                 return
280         fi
281
282         ebegin "Updating scrollkeeper database ..."
283         "${updater}" -q -p "${EROOT%/}${SCROLLKEEPER_DIR}"
284         eend $?
285 }
286
287 # @FUNCTION: gnome2_schemas_savelist
288 # @DESCRIPTION:
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
298 }
299
300 # @FUNCTION: gnome2_schemas_update
301 # @DESCRIPTION:
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}"
307
308         if [[ ! -x ${updater} ]]; then
309                 debug-print "${updater} is not executable"
310                 return
311         fi
312
313         ebegin "Updating GSettings schemas"
314         ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
315         eend $?
316 }
317
318 # @FUNCTION: gnome2_gdk_pixbuf_savelist
319 # @DESCRIPTION:
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
328 }
329
330 # @FUNCTION: gnome2_gdk_pixbuf_update
331 # @DESCRIPTION:
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"
337
338         if [[ ! -x ${updater} ]]; then
339                 updater="${EROOT%/}/usr/bin/gdk-pixbuf-query-loaders"
340         fi
341
342         if [[ ! -x ${updater} ]]; then
343                 debug-print "${updater} is not executable"
344                 return
345         fi
346
347         if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
348                 debug-print "gdk-pixbuf loader cache does not need an update"
349                 return
350         fi
351
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
358         eend $?
359 }
360
361 # @FUNCTION: gnome2_query_immodules_gtk2
362 # @DESCRIPTION:
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
367
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
371         eend $?
372 }
373
374 # @FUNCTION: gnome2_query_immodules_gtk3
375 # @DESCRIPTION:
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
380
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
384         eend $?
385 }
386
387 # @FUNCTION: gnome2_giomodule_cache_update
388 # @DESCRIPTION:
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"
394
395         if [[ ! -x ${updater} ]]; then
396                 updater="${EROOT%/}/usr/bin/gio-querymodules"
397         fi
398
399         if [[ ! -x ${updater} ]]; then
400                 debug-print "${updater} is not executable"
401                 return
402         fi
403
404         ebegin "Updating GIO modules cache"
405         ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
406         eend $?
407 }
408
409 # @FUNCTION: gnome2_disable_deprecation_warning
410 # @DESCRIPTION:
411 # Disable deprecation warnings commonly found in glib based packages.
412 # Should be called from src_prepare.
413 gnome2_disable_deprecation_warning() {
414         local retval=0
415         local fails=( )
416         local makefile
417
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
423                         continue
424                 fi
425
426                 LC_ALL=C sed -r -i \
427                         -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
428                         -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
429                         -i "${makefile}"
430
431                 if [[ $? -ne 0 ]]; then
432                         # Add to the list of failures
433                         fails+=( "${makefile}" )
434                         retval=2
435                 fi
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)
442         eend ${retval}
443
444         for makefile in "${fails[@]}" ; do
445                 ewarn "Failed to disable deprecation warnings in ${makefile}"
446         done
447 }
448
449 case ${EAPI:-0} in
450 0|1|2|3|4|5|6)
451
452 # @FUNCTION: gnome2_icon_savelist
453 # @DESCRIPTION:
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
464 }
465
466 # @FUNCTION: gnome2_icon_cache_update
467 # @DESCRIPTION:
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
472 }
473
474 ;;
475 esac