ecm.eclass: Set correct KFMIN default for kde-frameworks/*
[gentoo.git] / eclass / gnome2-utils.eclass
1 # Copyright 1999-2019 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 [[ ${EAPI:-0} == [0123456] ]] && inherit eutils
19 inherit xdg-utils
20
21 case "${EAPI:-0}" in
22         0|1|2|3|4|5|6|7) ;;
23         *) die "EAPI=${EAPI} is not supported" ;;
24 esac
25
26 # @ECLASS-VARIABLE: GCONFTOOL_BIN
27 # @INTERNAL
28 # @DESCRIPTION:
29 # Path to gconftool-2
30 : ${GCONFTOOL_BIN:="/usr/bin/gconftool-2"}
31
32 # @ECLASS-VARIABLE: SCROLLKEEPER_DIR
33 # @INTERNAL
34 # @DESCRIPTION:
35 # Directory where scrollkeeper-update should do its work
36 : ${SCROLLKEEPER_DIR:="/var/lib/scrollkeeper"}
37
38 # @ECLASS-VARIABLE: SCROLLKEEPER_UPDATE_BIN
39 # @INTERNAL
40 # @DESCRIPTION:
41 # Path to scrollkeeper-update
42 : ${SCROLLKEEPER_UPDATE_BIN:="/usr/bin/scrollkeeper-update"}
43
44 # @ECLASS-VARIABLE: GLIB_COMPILE_SCHEMAS
45 # @INTERNAL
46 # @DESCRIPTION:
47 # Path to glib-compile-schemas
48 : ${GLIB_COMPILE_SCHEMAS:="/usr/bin/glib-compile-schemas"}
49
50 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCHEMAS
51 # @INTERNAL
52 # @DEFAULT_UNSET
53 # @DESCRIPTION:
54 # List of GConf schemas provided by the package
55
56 # @ECLASS-VARIABLE: GNOME2_ECLASS_ICONS
57 # @INTERNAL
58 # @DEFAULT_UNSET
59 # @DESCRIPTION:
60 # List of icons provided by the package
61
62 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCROLLS
63 # @INTERNAL
64 # @DEFAULT_UNSET
65 # @DESCRIPTION:
66 # List of scrolls (documentation files) provided by the package
67
68 # @ECLASS-VARIABLE: GNOME2_ECLASS_GLIB_SCHEMAS
69 # @INTERNAL
70 # @DEFAULT_UNSET
71 # @DESCRIPTION:
72 # List of GSettings schemas provided by the package
73
74 # @ECLASS-VARIABLE: GNOME2_ECLASS_GDK_PIXBUF_LOADERS
75 # @INTERNAL
76 # @DEFAULT_UNSET
77 # @DESCRIPTION:
78 # List of gdk-pixbuf loaders provided by the package
79
80
81 # @FUNCTION: gnome2_environment_reset
82 # @DESCRIPTION:
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() {
86         xdg_environment_reset
87
88         # Respected by >=glib-2.30.1-r1
89         export G_HOME="${T}"
90
91         # GST_REGISTRY is to work around gst utilities trying to read/write /root
92         export GST_REGISTRY="${T}/registry.xml"
93
94         # Ensure we don't rely on dconf/gconf while building, bug #511946
95         export GSETTINGS_BACKEND="memory"
96
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)"
100
101                 # Stop relying on random DISPLAY variable values, bug #534312
102                 unset DISPLAY
103         fi
104 }
105
106 # @FUNCTION: gnome2_gconf_savelist
107 # @DESCRIPTION:
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
116 }
117
118 # @FUNCTION: gnome2_gconf_install
119 # @DESCRIPTION:
120 # Applies any schema files installed by the current ebuild to Gconf's database
121 # using gconftool-2.
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}"
126
127         if [[ ! -x "${updater}" ]]; then
128                 debug-print "${updater} is not executable"
129                 return
130         fi
131
132         if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
133                 debug-print "No GNOME 2 GConf schemas found"
134                 return
135         fi
136
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};")"
140
141         einfo "Installing GNOME 2 GConf schemas"
142
143         local F
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
148                 fi
149         done
150
151         # have gconf reload the new schemas
152         pids=$(pgrep -x gconfd-2)
153         if [[ $? == 0 ]] ; then
154                 ebegin "Reloading GConf schemas"
155                 kill -HUP ${pids}
156                 eend $?
157         fi
158 }
159
160 # @FUNCTION: gnome2_gconf_uninstall
161 # @DESCRIPTION:
162 # Removes schema files previously installed by the current ebuild from Gconf's
163 # database.
164 gnome2_gconf_uninstall() {
165         has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
166         local updater="${EROOT}${GCONFTOOL_BIN}"
167
168         if [[ ! -x "${updater}" ]]; then
169                 debug-print "${updater} is not executable"
170                 return
171         fi
172
173         if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
174                 debug-print "No GNOME 2 GConf schemas found"
175                 return
176         fi
177
178         unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
179         export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
180
181         einfo "Uninstalling GNOME 2 GConf schemas"
182
183         local F
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
188                 fi
189         done
190
191         # have gconf reload the new schemas
192         pids=$(pgrep -x gconfd-2)
193         if [[ $? == 0 ]] ; then
194                 ebegin "Reloading GConf schemas"
195                 kill -HUP ${pids}
196                 eend $?
197         fi
198 }
199
200 # @FUNCTION: gnome2_omf_fix
201 # @DESCRIPTION:
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.
205 gnome2_omf_fix() {
206         local omf_makefiles filename
207
208         omf_makefiles="$@"
209
210         if [[ -f ${S}/omf.make ]] ; then
211                 omf_makefiles="${omf_makefiles} ${S}/omf.make"
212         fi
213
214         if [[ -f ${S}/gnome-doc-utils.make ]] ; then
215                 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
216         fi
217
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}"
223         done
224
225         ebegin "Fixing OMF Makefiles"
226
227         local retval=0
228         local fails=( )
229
230         for omf in ${omf_makefiles} ; do
231                 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
232                 retval=$?
233
234                 if [[ $retval -ne 0 ]] ; then
235                         debug-print "updating of ${omf} failed"
236
237                         # Add to the list of failures
238                         fails[$(( ${#fails[@]} + 1 ))]=$omf
239
240                         retval=2
241                 fi
242         done
243
244         eend $retval
245
246         for f in "${fails[@]}" ; do
247                 eerror "Failed to update OMF Makefile $f"
248         done
249 }
250
251 # @FUNCTION: gnome2_scrollkeeper_savelist
252 # @DESCRIPTION:
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
261 }
262
263 # @FUNCTION: gnome2_scrollkeeper_update
264 # @DESCRIPTION:
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}"
270
271         if [[ ! -x "${updater}" ]] ; then
272                 debug-print "${updater} is not executable"
273                 return
274         fi
275
276         if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
277                 debug-print "No scroll cache to update"
278                 return
279         fi
280
281         ebegin "Updating scrollkeeper database ..."
282         "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
283         eend $?
284 }
285
286 # @FUNCTION: gnome2_schemas_savelist
287 # @DESCRIPTION:
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
297 }
298
299 # @FUNCTION: gnome2_schemas_update
300 # @USAGE: 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 # @USAGE: gnome2_gdk_pixbuf_update
332 # @DESCRIPTION:
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"
338
339         if [[ ! -x ${updater} ]]; then
340                 updater="${EROOT}/usr/bin/gdk-pixbuf-query-loaders"
341         fi
342
343         if [[ ! -x ${updater} ]]; then
344                 debug-print "${updater} is not executable"
345                 return
346         fi
347
348         if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
349                 debug-print "gdk-pixbuf loader cache does not need an update"
350                 return
351         fi
352
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
359         eend $?
360 }
361
362 # @FUNCTION: gnome2_query_immodules_gtk2
363 # @USAGE: gnome2_query_immodules_gtk2
364 # @DESCRIPTION:
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
369
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
373         eend $?
374 }
375
376 # @FUNCTION: gnome2_query_immodules_gtk3
377 # @USAGE: gnome2_query_immodules_gtk3
378 # @DESCRIPTION:
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
383
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
387         eend $?
388 }
389
390 # @FUNCTION: gnome2_giomodule_cache_update
391 # @USAGE: gnome2_giomodule_cache_update
392 # @DESCRIPTION:
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"
398
399         if [[ ! -x ${updater} ]]; then
400                 updater="${EROOT}/usr/bin/gio-querymodules"
401         fi
402
403         if [[ ! -x ${updater} ]]; then
404                 debug-print "${updater} is not executable"
405                 return
406         fi
407
408         ebegin "Updating GIO modules cache"
409         ${updater} "${EROOT%/}"/usr/$(get_libdir)/gio/modules
410         eend $?
411 }
412
413 # @FUNCTION: gnome2_disable_deprecation_warning
414 # @DESCRIPTION:
415 # Disable deprecation warnings commonly found in glib based packages.
416 # Should be called from src_prepare.
417 gnome2_disable_deprecation_warning() {
418         local retval=0
419         local fails=( )
420         local makefile
421
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
427                         continue
428                 fi
429
430                 LC_ALL=C sed -r -i \
431                         -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(/bin/true):g' \
432                         -e 's:-DGSEAL_ENABLE(=[A-Za-z0-9_]*)?:$(/bin/true):g' \
433                         -i "${makefile}"
434
435                 if [[ $? -ne 0 ]]; then
436                         # Add to the list of failures
437                         fails+=( "${makefile}" )
438                         retval=2
439                 fi
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)
446         eend ${retval}
447
448         for makefile in "${fails[@]}" ; do
449                 ewarn "Failed to disable deprecation warnings in ${makefile}"
450         done
451 }
452
453 case ${EAPI:-0} in
454 0|1|2|3|4|5|6)
455
456 # @FUNCTION: gnome2_icon_savelist
457 # @DESCRIPTION:
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
468 }
469
470 # @FUNCTION: gnome2_icon_cache_update
471 # @DESCRIPTION:
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
476 }
477
478 ;;
479 esac