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

Contents of /eclass/gnome2-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.36 - (show annotations) (download)
Sat Mar 1 10:18:35 2014 UTC (4 months, 4 weeks ago) by mgorny
Branch: MAIN
CVS Tags: HEAD
Changes since 1.35: +7 -9 lines
Error occurred while calculating annotation data.
Add multilib love for gnome2_gdk_pixbuf_update().

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

  ViewVC Help
Powered by ViewVC 1.1.20