/[gentoo-x86]/eclass/gnome2-utils.eclass
Gentoo

Contents of /eclass/gnome2-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.33 - (show annotations) (download)
Sun Sep 15 19:29:11 2013 UTC (12 months, 1 week ago) by pacho
Branch: MAIN
Changes since 1.32: +25 -21 lines
Support gtk+-2.24.20 query immodules (#476100)

1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/gnome2-utils.eclass,v 1.32 2013/09/03 21:54:38 eva Exp $
4
5 # @ECLASS: gnome2-utils.eclass
6 # @MAINTAINER:
7 # gnome@gentoo.org
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 # * Gtk+ icon cache management
14 # * GSettings schemas management
15 # * GConf schemas management
16 # * scrollkeeper (old Gnome help system) management
17
18 inherit multilib
19
20 case "${EAPI:-0}" in
21 0|1|2|3|4|5) ;;
22 *) die "EAPI=${EAPI} is not supported" ;;
23 esac
24
25 # @ECLASS-VARIABLE: GCONFTOOL_BIN
26 # @INTERNAL
27 # @DESCRIPTION:
28 # Path to gconftool-2
29 : ${GCONFTOOL_BIN:="/usr/bin/gconftool-2"}
30
31 # @ECLASS-VARIABLE: SCROLLKEEPER_DIR
32 # @INTERNAL
33 # @DESCRIPTION:
34 # Directory where scrollkeeper-update should do its work
35 : ${SCROLLKEEPER_DIR:="/var/lib/scrollkeeper"}
36
37 # @ECLASS-VARIABLE: SCROLLKEEPER_UPDATE_BIN
38 # @INTERNAL
39 # @DESCRIPTION:
40 # Path to scrollkeeper-update
41 : ${SCROLLKEEPER_UPDATE_BIN:="/usr/bin/scrollkeeper-update"}
42
43 # @ECLASS-VARIABLE: GTK_UPDATE_ICON_CACHE
44 # @INTERNAL
45 # @DESCRIPTION:
46 # Path to gtk-update-icon-cache
47 : ${GTK_UPDATE_ICON_CACHE:="/usr/bin/gtk-update-icon-cache"}
48
49 # @ECLASS-VARIABLE: GLIB_COMPILE_SCHEMAS
50 # @INTERNAL
51 # @DESCRIPTION:
52 # Path to glib-compile-schemas
53 : ${GLIB_COMPILE_SCHEMAS:="/usr/bin/glib-compile-schemas"}
54
55 # @ECLASS-VARIABLE: GDK_PIXBUF_UPDATE_BIN
56 # @INTERNAL
57 # @DESCRIPTION:
58 # Path to gdk-pixbuf-query-loaders
59 : ${GDK_PIXBUF_UPDATE_BIN:="/usr/bin/gdk-pixbuf-query-loaders"}
60
61 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCHEMAS
62 # @INTERNAL
63 # @DEFAULT_UNSET
64 # @DESCRIPTION:
65 # List of GConf schemas provided by the package
66
67 # @ECLASS-VARIABLE: GNOME2_ECLASS_ICONS
68 # @INTERNAL
69 # @DEFAULT_UNSET
70 # @DESCRIPTION:
71 # List of icons provided by the package
72
73 # @ECLASS-VARIABLE: GNOME2_ECLASS_SCROLLS
74 # @INTERNAL
75 # @DEFAULT_UNSET
76 # @DESCRIPTION:
77 # List of scrolls (documentation files) provided by the package
78
79 # @ECLASS-VARIABLE: GNOME2_ECLASS_GLIB_SCHEMAS
80 # @INTERNAL
81 # @DEFAULT_UNSET
82 # @DESCRIPTION:
83 # List of GSettings schemas provided by the package
84
85 # @ECLASS-VARIABLE: GNOME2_ECLASS_GDK_PIXBUF_LOADERS
86 # @INTERNAL
87 # @DEFAULT_UNSET
88 # @DESCRIPTION:
89 # List of gdk-pixbuf loaders provided by the package
90
91 DEPEND=">=sys-apps/sed-4"
92
93
94 # @FUNCTION: gnome2_environment_reset
95 # @DESCRIPTION:
96 # Reset various variables inherited from root's evironment to a reasonable
97 # default for ebuilds to help avoid access violations and test failures.
98 gnome2_environment_reset() {
99 # Respected by >=glib-2.30.1-r1
100 export G_HOME="${T}"
101
102 # GST_REGISTRY is to work around gst utilities trying to read/write /root
103 export GST_REGISTRY="${T}/registry.xml"
104
105 # XXX: code for resetting XDG_* directories should probably be moved into
106 # a separate function in a non-gnome eclass
107 export XDG_DATA_HOME="${T}/.local/share"
108 export XDG_CONFIG_HOME="${T}/.config"
109 export XDG_CACHE_HOME="${T}/.cache"
110 export XDG_RUNTIME_DIR="${T}/run"
111 mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" \
112 "${XDG_RUNTIME_DIR}"
113 # This directory needs to be owned by the user, and chmod 0700
114 # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
115 chmod 0700 "${XDG_RUNTIME_DIR}"
116 }
117
118 # @FUNCTION: gnome2_gconf_savelist
119 # @DESCRIPTION:
120 # Find the GConf schemas that are about to be installed and save their location
121 # in the GNOME2_ECLASS_SCHEMAS environment variable.
122 # This function should be called from pkg_preinst.
123 gnome2_gconf_savelist() {
124 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
125 pushd "${ED}" &> /dev/null
126 export GNOME2_ECLASS_SCHEMAS=$(find 'etc/gconf/schemas/' -name '*.schemas' 2> /dev/null)
127 popd &> /dev/null
128 }
129
130 # @FUNCTION: gnome2_gconf_install
131 # @DESCRIPTION:
132 # Applies any schema files installed by the current ebuild to Gconf's database
133 # using gconftool-2.
134 # This function should be called from pkg_postinst.
135 gnome2_gconf_install() {
136 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
137 local updater="${EROOT}${GCONFTOOL_BIN}"
138
139 if [[ ! -x "${updater}" ]]; then
140 debug-print "${updater} is not executable"
141 return
142 fi
143
144 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
145 debug-print "No GNOME 2 GConf schemas found"
146 return
147 fi
148
149 # We are ready to install the GCONF Scheme now
150 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
151 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
152
153 einfo "Installing GNOME 2 GConf schemas"
154
155 local F
156 for F in ${GNOME2_ECLASS_SCHEMAS}; do
157 if [[ -e "${EROOT}${F}" ]]; then
158 debug-print "Installing schema: ${F}"
159 "${updater}" --makefile-install-rule "${EROOT}${F}" 1>/dev/null
160 fi
161 done
162
163 # have gconf reload the new schemas
164 pids=$(pgrep -x gconfd-2)
165 if [[ $? == 0 ]] ; then
166 ebegin "Reloading GConf schemas"
167 kill -HUP ${pids}
168 eend $?
169 fi
170 }
171
172 # @FUNCTION: gnome2_gconf_uninstall
173 # @DESCRIPTION:
174 # Removes schema files previously installed by the current ebuild from Gconf's
175 # database.
176 gnome2_gconf_uninstall() {
177 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
178 local updater="${EROOT}${GCONFTOOL_BIN}"
179
180 if [[ ! -x "${updater}" ]]; then
181 debug-print "${updater} is not executable"
182 return
183 fi
184
185 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
186 debug-print "No GNOME 2 GConf schemas found"
187 return
188 fi
189
190 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
191 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
192
193 einfo "Uninstalling GNOME 2 GConf schemas"
194
195 local F
196 for F in ${GNOME2_ECLASS_SCHEMAS}; do
197 if [[ -e "${EROOT}${F}" ]]; then
198 debug-print "Uninstalling gconf schema: ${F}"
199 "${updater}" --makefile-uninstall-rule "${EROOT}${F}" 1>/dev/null
200 fi
201 done
202
203 # have gconf reload the new schemas
204 pids=$(pgrep -x gconfd-2)
205 if [[ $? == 0 ]] ; then
206 ebegin "Reloading GConf schemas"
207 kill -HUP ${pids}
208 eend $?
209 fi
210 }
211
212 # @FUNCTION: gnome2_icon_savelist
213 # @DESCRIPTION:
214 # Find the icons that are about to be installed and save their location
215 # in the GNOME2_ECLASS_ICONS environment variable.
216 # This function should be called from pkg_preinst.
217 gnome2_icon_savelist() {
218 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
219 pushd "${ED}" &> /dev/null
220 export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
221 popd &> /dev/null
222 }
223
224 # @FUNCTION: gnome2_icon_cache_update
225 # @DESCRIPTION:
226 # Updates Gtk+ icon cache files under /usr/share/icons if the current ebuild
227 # have installed anything under that location.
228 # This function should be called from pkg_postinst and pkg_postrm.
229 gnome2_icon_cache_update() {
230 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
231 local updater="${EROOT}${GTK_UPDATE_ICON_CACHE}"
232
233 if [[ ! -x "${updater}" ]] ; then
234 debug-print "${updater} is not executable"
235 return
236 fi
237
238 if [[ -z "${GNOME2_ECLASS_ICONS}" ]]; then
239 debug-print "No icon cache to update"
240 return
241 fi
242
243 ebegin "Updating icons cache"
244
245 local retval=0
246 local fails=( )
247
248 for dir in ${GNOME2_ECLASS_ICONS}
249 do
250 if [[ -f "${EROOT}${dir}/index.theme" ]] ; then
251 local rv=0
252
253 "${updater}" -qf "${EROOT}${dir}"
254 rv=$?
255
256 if [[ ! $rv -eq 0 ]] ; then
257 debug-print "Updating cache failed on ${EROOT}${dir}"
258
259 # Add to the list of failures
260 fails[$(( ${#fails[@]} + 1 ))]="${EROOT}${dir}"
261
262 retval=2
263 fi
264 elif [[ $(ls "${EROOT}${dir}") = "icon-theme.cache" ]]; then
265 # Clear stale cache files after theme uninstallation
266 rm "${EROOT}${dir}/icon-theme.cache"
267 fi
268
269 if [[ -z $(ls "${EROOT}${dir}") ]]; then
270 # Clear empty theme directories after theme uninstallation
271 rmdir "${EROOT}${dir}"
272 fi
273 done
274
275 eend ${retval}
276
277 for f in "${fails[@]}" ; do
278 eerror "Failed to update cache with icon $f"
279 done
280 }
281
282 # @FUNCTION: gnome2_omf_fix
283 # @DESCRIPTION:
284 # Workaround applied to Makefile rules in order to remove redundant
285 # calls to scrollkeeper-update and sandbox violations.
286 # This function should be called from src_prepare.
287 gnome2_omf_fix() {
288 local omf_makefiles filename
289
290 omf_makefiles="$@"
291
292 if [[ -f ${S}/omf.make ]] ; then
293 omf_makefiles="${omf_makefiles} ${S}/omf.make"
294 fi
295
296 if [[ -f ${S}/gnome-doc-utils.make ]] ; then
297 omf_makefiles="${omf_makefiles} ${S}/gnome-doc-utils.make"
298 fi
299
300 # testing fixing of all makefiles found
301 # The sort is important to ensure .am is listed before the respective .in for
302 # maintainer mode regeneration not kicking in due to .am being newer than .in
303 for filename in $(find "${S}" -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
304 omf_makefiles="${omf_makefiles} ${filename}"
305 done
306
307 ebegin "Fixing OMF Makefiles"
308
309 local retval=0
310 local fails=( )
311
312 for omf in ${omf_makefiles} ; do
313 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
314 retval=$?
315
316 if [[ $retval -ne 0 ]] ; then
317 debug-print "updating of ${omf} failed"
318
319 # Add to the list of failures
320 fails[$(( ${#fails[@]} + 1 ))]=$omf
321
322 retval=2
323 fi
324 done
325
326 eend $retval
327
328 for f in "${fails[@]}" ; do
329 eerror "Failed to update OMF Makefile $f"
330 done
331 }
332
333 # @FUNCTION: gnome2_scrollkeeper_savelist
334 # @DESCRIPTION:
335 # Find the scrolls that are about to be installed and save their location
336 # in the GNOME2_ECLASS_SCROLLS environment variable.
337 # This function should be called from pkg_preinst.
338 gnome2_scrollkeeper_savelist() {
339 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
340 pushd "${ED}" &> /dev/null
341 export GNOME2_ECLASS_SCROLLS=$(find 'usr/share/omf' -type f -name "*.omf" 2> /dev/null)
342 popd &> /dev/null
343 }
344
345 # @FUNCTION: gnome2_scrollkeeper_update
346 # @DESCRIPTION:
347 # Updates the global scrollkeeper database.
348 # This function should be called from pkg_postinst and pkg_postrm.
349 gnome2_scrollkeeper_update() {
350 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
351 local updater="${EROOT}${SCROLLKEEPER_UPDATE_BIN}"
352
353 if [[ ! -x "${updater}" ]] ; then
354 debug-print "${updater} is not executable"
355 return
356 fi
357
358 if [[ -z "${GNOME2_ECLASS_SCROLLS}" ]]; then
359 debug-print "No scroll cache to update"
360 return
361 fi
362
363 ebegin "Updating scrollkeeper database ..."
364 "${updater}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
365 eend $?
366 }
367
368 # @FUNCTION: gnome2_schemas_savelist
369 # @DESCRIPTION:
370 # Find if there is any GSettings schema to install and save the list in
371 # GNOME2_ECLASS_GLIB_SCHEMAS variable.
372 # This function should be called from pkg_preinst.
373 gnome2_schemas_savelist() {
374 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
375 pushd "${ED}" &>/dev/null
376 export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
377 popd &>/dev/null
378 }
379
380 # @FUNCTION: gnome2_schemas_update
381 # @USAGE: gnome2_schemas_update
382 # @DESCRIPTION:
383 # Updates GSettings schemas if GNOME2_ECLASS_GLIB_SCHEMAS has some.
384 # This function should be called from pkg_postinst and pkg_postrm.
385 gnome2_schemas_update() {
386 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
387 local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}"
388
389 if [[ ! -x ${updater} ]]; then
390 debug-print "${updater} is not executable"
391 return
392 fi
393
394 if [[ -z ${GNOME2_ECLASS_GLIB_SCHEMAS} ]]; then
395 debug-print "No GSettings schemas to update"
396 return
397 fi
398
399 ebegin "Updating GSettings schemas"
400 ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
401 eend $?
402 }
403
404 # @FUNCTION: gnome2_gdk_pixbuf_savelist
405 # @DESCRIPTION:
406 # Find if there is any gdk-pixbuf loader to install and save the list in
407 # GNOME2_ECLASS_GDK_PIXBUF_LOADERS variable.
408 # This function should be called from pkg_preinst.
409 gnome2_gdk_pixbuf_savelist() {
410 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
411 pushd "${ED}" 1>/dev/null
412 export GNOME2_ECLASS_GDK_PIXBUF_LOADERS=$(find "usr/$(get_libdir)/gdk-pixbuf-2.0" -type f 2>/dev/null)
413 popd 1>/dev/null
414 }
415
416 # @FUNCTION: gnome2_gdk_pixbuf_update
417 # @USAGE: gnome2_gdk_pixbuf_update
418 # @DESCRIPTION:
419 # Updates gdk-pixbuf loader cache if GNOME2_ECLASS_GDK_PIXBUF_LOADERS has some.
420 # This function should be called from pkg_postinst and pkg_postrm.
421 gnome2_gdk_pixbuf_update() {
422 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
423 local updater="${EROOT}${GDK_PIXBUF_UPDATE_BIN}"
424
425 if [[ ! -x ${updater} ]]; then
426 debug-print "${updater} is not executable"
427 return
428 fi
429
430 if [[ -z ${GNOME2_ECLASS_GDK_PIXBUF_LOADERS} ]]; then
431 debug-print "gdk-pixbuf loader cache does not need an update"
432 return
433 fi
434
435 ebegin "Updating gdk-pixbuf loader cache"
436 local tmp_file=$(mktemp -t tmp.XXXXXXXXXX_gdkpixbuf)
437 ${updater} 1> "${tmp_file}" &&
438 chmod 0644 "${tmp_file}" &&
439 mv -f "${tmp_file}" "${EROOT}usr/$(get_libdir)/gdk-pixbuf-2.0/2.10.0/loaders.cache"
440 eend $?
441 }
442
443
444 # @FUNCTION: gnome2_query_immodules_gtk2
445 # @USAGE: gnome2_query_immodules_gtk2
446 # @DESCRIPTION:
447 # Updates gtk2 immodules/gdk-pixbuf loaders listing.
448 gnome2_query_immodules_gtk2() {
449 if has_version ">=x11-libs/gtk+-2.24.20:2"; then
450 "${EPREFIX}/usr/bin/gtk-query-immodules-2.0" --update-cache
451 else
452 local GTK2_CONFDIR="/etc/gtk-2.0/$(get_abi_CHOST)"
453
454 local query_exec="${EPREFIX}/usr/bin/gtk-query-immodules-2.0"
455 local gtk_conf="${EPREFIX}${GTK2_CONFDIR}/gtk.immodules"
456 local gtk_conf_dir=$(dirname "${gtk_conf}")
457
458 einfo "Generating Gtk2 immodules/gdk-pixbuf loaders listing:"
459 einfo "-> ${gtk_conf}"
460
461 mkdir -p "${gtk_conf_dir}"
462 local tmp_file=$(mktemp -t tmp.XXXXXXXXXXgtk_query_immodules)
463 if [ -z "${tmp_file}" ]; then
464 ewarn "gtk_query_immodules: cannot create temporary file"
465 return 1
466 fi
467
468 if ${query_exec} > "${tmp_file}"; then
469 cat "${tmp_file}" > "${gtk_conf}" || \
470 ewarn "Failed to write to ${gtk_conf}"
471 else
472 ewarn "Cannot update gtk.immodules, file generation failed"
473 fi
474 rm "${tmp_file}"
475 fi
476 }
477
478 # @FUNCTION: gnome2_query_immodules_gtk3
479 # @USAGE: gnome2_query_immodules_gtk3
480 # @DESCRIPTION:
481 # Updates gtk3 immodules/gdk-pixbuf loaders listing.
482 gnome2_query_immodules_gtk3() {
483 "${EPREFIX}/usr/bin/gtk-query-immodules-3.0" --update-cache
484 }
485
486 # @FUNCTION: gnome2_disable_deprecation_warning
487 # @DESCRIPTION:
488 # Disable deprecation warnings commonly found in glib based packages.
489 # Should be called from src_prepare.
490 gnome2_disable_deprecation_warning() {
491 local retval=0
492 local fails=( )
493 local makefile
494
495 ebegin "Disabling deprecation warnings"
496 # The sort is important to ensure .am is listed before the respective .in for
497 # maintainer mode regeneration not kicking in due to .am being newer than .in
498 while read makefile ; do
499 if ! grep -qE "(DISABLE_DEPRECATED|GSEAL_ENABLE)" "${makefile}"; then
500 continue
501 fi
502
503 LC_ALL=C sed -r -i \
504 -e 's:-D[A-Z_]+_DISABLE_DEPRECATED:$(NULL):g' \
505 -e 's:-DGSEAL_ENABLE:$(NULL):g' \
506 -i "${makefile}"
507
508 if [[ $? -ne 0 ]]; then
509 # Add to the list of failures
510 fails+=( "${makefile}" )
511 retval=2
512 fi
513 done < <(find "${S}" -name "Makefile.in" \
514 -o -name "Makefile.am" -o -name "Makefile.decl" \
515 | sort; echo configure)
516 # TODO: sedding configure.ac can trigger maintainer mode; bug #439602
517 # -o -name "configure.ac" -o -name "configure.in" \
518 # | sort; echo configure)
519 eend ${retval}
520
521 for makefile in "${fails[@]}" ; do
522 ewarn "Failed to disable deprecation warnings in ${makefile}"
523 done
524 }

  ViewVC Help
Powered by ViewVC 1.1.20