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

Diff of /eclass/gnome2-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.3 Revision 1.26
1# Copyright 1999-2006 Gentoo Foundation 1# Copyright 1999-2012 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/gnome2-utils.eclass,v 1.3 2007/01/24 18:20:01 compnerd Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/gnome2-utils.eclass,v 1.26 2012/04/08 02:29:44 tetromino Exp $
4 4
5#
6# gnome2-utils.eclass 5# @ECLASS: gnome2-utils.eclass
7# 6# @MAINTAINER:
8# Set of auxiliary functions used to perform actions commonly needed by packages 7# gnome@gentoo.org
9# using the GNOME framework. 8# @BLURB: Auxiliary functions commonly used by Gnome packages.
10# 9# @DESCRIPTION:
11# Maintained by Gentoo's GNOME herd <gnome@gentoo.org> 10# This eclass provides a set of auxiliary functions needed by most Gnome
12# 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
13 17
18case "${EAPI:-0}" in
19 0|1|2|3|4) ;;
20 *) die "EAPI=${EAPI} is not supported" ;;
21esac
14 22
15 23# @ECLASS-VARIABLE: GCONFTOOL_BIN
24# @INTERNAL
25# @DESCRIPTION:
16# Path to gconftool-2 26# Path to gconftool-2
17GCONFTOOL_BIN=${GCONFTOOL_BIN:="${ROOT}usr/bin/gconftool-2"} 27: ${GCONFTOOL_BIN:="/usr/bin/gconftool-2"}
18 28
29# @ECLASS-VARIABLE: SCROLLKEEPER_DIR
30# @INTERNAL
31# @DESCRIPTION:
19# Directory where scrollkeeper-update should do its work 32# Directory where scrollkeeper-update should do its work
20SCROLLKEEPER_DIR=${SCROLLKEEPER_DIR:="${ROOT}var/lib/scrollkeeper"} 33: ${SCROLLKEEPER_DIR:="/var/lib/scrollkeeper"}
21 34
35# @ECLASS-VARIABLE: SCROLLKEEPER_UPDATE_BIN
36# @INTERNAL
37# @DESCRIPTION:
22# Path to scrollkeeper-update 38# Path to scrollkeeper-update
23SCROLLKEEPER_UPDATE_BIN=${SCROLLKEEPER_UPDATE_BIN:="${ROOT}usr/bin/scrollkeeper-update"} 39: ${SCROLLKEEPER_UPDATE_BIN:="/usr/bin/scrollkeeper-update"}
24 40
41# @ECLASS-VARIABLE: GTK_UPDATE_ICON_CACHE
42# @INTERNAL
43# @DESCRIPTION:
44# Path to gtk-update-icon-cache
45: ${GTK_UPDATE_ICON_CACHE:="/usr/bin/gtk-update-icon-cache"}
46
47# @ECLASS-VARIABLE: GLIB_COMPILE_SCHEMAS
48# @INTERNAL
49# @DESCRIPTION:
50# Path to glib-compile-schemas
51: ${GLIB_COMPILE_SCHEMAS:="/usr/bin/glib-compile-schemas"}
52
53# @ECLASS-VARIABLE: GNOME2_ECLASS_SCHEMAS
54# @INTERNAL
55# @DEFAULT_UNSET
56# @DESCRIPTION:
57# List of GConf schemas provided by the package
58
59# @ECLASS-VARIABLE: GNOME2_ECLASS_ICONS
60# @INTERNAL
61# @DEFAULT_UNSET
62# @DESCRIPTION:
63# List of icons provided by the package
64
65# @ECLASS-VARIABLE: GNOME2_ECLASS_GLIB_SCHEMAS
66# @INTERNAL
67# @DEFAULT_UNSET
68# @DESCRIPTION:
69# List of GSettings schemas provided by the package
25 70
26 71
27DEPEND=">=sys-apps/sed-4" 72DEPEND=">=sys-apps/sed-4"
28 73
29 74
75# @FUNCTION: gnome2_environment_reset
76# @DESCRIPTION:
77# Reset various variables inherited from root's evironment to a reasonable
78# default for ebuilds to help avoid access violations and test failures.
79gnome2_environment_reset() {
80 # Respected by >=glib-2.30.1-r1
81 export G_HOME="${T}"
30 82
83 # GST_REGISTRY is to work around gst utilities trying to read/write /root
84 export GST_REGISTRY="${T}/registry.xml"
85
86 # XXX: code for resetting XDG_* directories should probably be moved into
87 # a separate function in a non-gnome eclass
88 export XDG_DATA_HOME="${T}/.local/share"
89 export XDG_CONFIG_HOME="${T}/.config"
90 export XDG_CACHE_HOME="${T}/.cache"
91 export XDG_RUNTIME_DIR="${T}/run"
92 mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" \
93 "${XDG_RUNTIME_DIR}"
94 # This directory needs to be owned by the user, and chmod 0700
95 # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
96 chmod 0700 "${XDG_RUNTIME_DIR}"
97}
98
99# @FUNCTION: gnome2_gconf_savelist
100# @DESCRIPTION:
101# Find the GConf schemas that are about to be installed and save their location
102# in the GNOME2_ECLASS_SCHEMAS environment variable.
103# This function should be called from pkg_preinst.
104gnome2_gconf_savelist() {
105 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
106 pushd "${ED}" &> /dev/null
107 export GNOME2_ECLASS_SCHEMAS=$(find 'etc/gconf/schemas/' -name '*.schemas' 2> /dev/null)
108 popd &> /dev/null
109}
110
111# @FUNCTION: gnome2_gconf_install
112# @DESCRIPTION:
31# Applies any schema files installed by the current ebuild to Gconf's database 113# Applies any schema files installed by the current ebuild to Gconf's database
32# using gconftool-2 114# using gconftool-2.
115# This function should be called from pkg_postinst.
33gnome2_gconf_install() { 116gnome2_gconf_install() {
34 if [[ ! -x ${GCONFTOOL_BIN} ]]; then 117 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
118 local updater="${EROOT}${GCONFTOOL_BIN}"
119
120 if [[ ! -x "${updater}" ]]; then
121 debug-print "${updater} is not executable"
122 return
123 fi
124
125 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
126 debug-print "No GNOME 2 GConf schemas found"
35 return 127 return
36 fi 128 fi
37 129
38 # We are ready to install the GCONF Scheme now 130 # We are ready to install the GCONF Scheme now
39 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL 131 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
40 export GCONF_CONFIG_SOURCE=$(${GCONFTOOL_BIN} --get-default-source) 132 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
41 133
42 einfo "Installing GNOME 2 GConf schemas" 134 einfo "Installing GNOME 2 GConf schemas"
43 135
44 local contents="${ROOT}var/db/pkg/*/${PN}-${PVR}/CONTENTS"
45 local F 136 local F
46 137 for F in ${GNOME2_ECLASS_SCHEMAS}; do
47 for F in $(grep "^obj /etc/gconf/schemas/.\+\.schemas\b" ${contents} | gawk '{print $2}' ); do
48 if [[ -e "${F}" ]]; then 138 if [[ -e "${EROOT}${F}" ]]; then
49 # echo "DEBUG::gconf install ${F}" 139 debug-print "Installing schema: ${F}"
50 ${GCONFTOOL_BIN} --makefile-install-rule ${F} 1>/dev/null 140 "${updater}" --makefile-install-rule "${EROOT}${F}" 1>/dev/null
51 fi 141 fi
52 done 142 done
53 143
54 # have gconf reload the new schemas 144 # have gconf reload the new schemas
55 pids=$(pidof gconfd-2) 145 pids=$(pgrep -x gconfd-2)
56 if [[ $? == 0 ]] ; then 146 if [[ $? == 0 ]] ; then
57 ebegin "Reloading GConf schemas" 147 ebegin "Reloading GConf schemas"
58 kill -HUP ${pids} 148 kill -HUP ${pids}
59 eend $? 149 eend $?
60 fi 150 fi
61} 151}
62 152
63 153# @FUNCTION: gnome2_gconf_uninstall
154# @DESCRIPTION:
64# Removes schema files previously installed by the current ebuild from Gconf's 155# Removes schema files previously installed by the current ebuild from Gconf's
65# database. 156# database.
66gnome2_gconf_uninstall() { 157gnome2_gconf_uninstall() {
67 if [[ ! -x ${GCONFTOOL_BIN} ]]; then 158 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
159 local updater="${EROOT}${GCONFTOOL_BIN}"
160
161 if [[ ! -x "${updater}" ]]; then
162 debug-print "${updater} is not executable"
163 return
164 fi
165
166 if [[ -z "${GNOME2_ECLASS_SCHEMAS}" ]]; then
167 debug-print "No GNOME 2 GConf schemas found"
68 return 168 return
69 fi 169 fi
70 170
71 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL 171 unset GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL
72 export GCONF_CONFIG_SOURCE=$(${GCONFTOOL_BIN} --get-default-source) 172 export GCONF_CONFIG_SOURCE="$("${updater}" --get-default-source | sed "s;:/;:${ROOT};")"
73 173
74 einfo "Uninstalling GNOME 2 GConf schemas" 174 einfo "Uninstalling GNOME 2 GConf schemas"
75 175
76 local contents="${ROOT}/var/db/pkg/*/${PN}-${PVR}/CONTENTS"
77 local F 176 local F
78 177 for F in ${GNOME2_ECLASS_SCHEMAS}; do
79 for F in $(grep "obj /etc/gconf/schemas" ${contents} | sed 's:obj \([^ ]*\) .*:\1:' ); do 178 if [[ -e "${EROOT}${F}" ]]; then
80 # echo "DEBUG::gconf install ${F}" 179 debug-print "Uninstalling gconf schema: ${F}"
81 ${GCONFTOOL_BIN} --makefile-uninstall-rule ${F} 1>/dev/null 180 "${updater}" --makefile-uninstall-rule "${EROOT}${F}" 1>/dev/null
181 fi
82 done 182 done
83}
84 183
184 # have gconf reload the new schemas
185 pids=$(pgrep -x gconfd-2)
186 if [[ $? == 0 ]] ; then
187 ebegin "Reloading GConf schemas"
188 kill -HUP ${pids}
189 eend $?
190 fi
191}
85 192
193# @FUNCTION: gnome2_icon_savelist
194# @DESCRIPTION:
195# Find the icons that are about to be installed and save their location
196# in the GNOME2_ECLASS_ICONS environment variable.
197# This function should be called from pkg_preinst.
198gnome2_icon_savelist() {
199 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
200 pushd "${ED}" &> /dev/null
201 export GNOME2_ECLASS_ICONS=$(find 'usr/share/icons' -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
202 popd &> /dev/null
203}
204
205# @FUNCTION: gnome2_icon_cache_update
206# @DESCRIPTION:
86# Updates Gtk+ icon cache files under /usr/share/icons if the current ebuild 207# Updates Gtk+ icon cache files under /usr/share/icons if the current ebuild
87# have installed anything under that location. 208# have installed anything under that location.
209# This function should be called from pkg_postinst and pkg_postrm.
88gnome2_icon_cache_update() { 210gnome2_icon_cache_update() {
89 local updater=$(type -p gtk-update-icon-cache 2> /dev/null) 211 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
212 local updater="${EROOT}${GTK_UPDATE_ICON_CACHE}"
90 213
91 if [[ ! -x ${updater} ]] ; then 214 if [[ ! -x "${updater}" ]] ; then
92 debug-print "${updater} is not executable" 215 debug-print "${updater} is not executable"
93
94 return 216 return
95 fi 217 fi
96 218
97 if ! grep -q "obj /usr/share/icons" ${ROOT}var/db/pkg/*/${PF}/CONTENTS 219 if [[ -z "${GNOME2_ECLASS_ICONS}" ]]; then
98 then
99 debug-print "No items to update" 220 debug-print "No icon cache to update"
100
101 return 221 return
102 fi 222 fi
103 223
104 ebegin "Updating icons cache" 224 ebegin "Updating icons cache"
105 225
106 local retval=0 226 local retval=0
107 local fails=( ) 227 local fails=( )
108 228
109 for dir in $(find ${ROOT}/usr/share/icons -maxdepth 1 -mindepth 1 -type d) 229 for dir in ${GNOME2_ECLASS_ICONS}
110 do 230 do
111 if [[ -f "${dir}/index.theme" ]] ; then 231 if [[ -f "${EROOT}${dir}/index.theme" ]] ; then
112 local rv=0 232 local rv=0
113 233
114 ${updater} -qf ${dir} 234 "${updater}" -qf "${EROOT}${dir}"
115 rv=$? 235 rv=$?
116 236
117 if [[ ! $rv -eq 0 ]] ; then 237 if [[ ! $rv -eq 0 ]] ; then
118 debug-print "Updating cache failed on ${dir}" 238 debug-print "Updating cache failed on ${EROOT}${dir}"
119 239
120 # Add to the list of failures 240 # Add to the list of failures
121 fails[$(( ${#fails[@]} + 1 ))]=$dir 241 fails[$(( ${#fails[@]} + 1 ))]="${EROOT}${dir}"
122 242
123 retval=2 243 retval=2
124 fi 244 fi
245 elif [[ $(ls "${EROOT}${dir}") = "icon-theme.cache" ]]; then
246 # Clear stale cache files after theme uninstallation
247 rm "${EROOT}${dir}/icon-theme.cache"
248 fi
249
250 if [[ -z $(ls "${EROOT}${dir}") ]]; then
251 # Clear empty theme directories after theme uninstallation
252 rmdir "${EROOT}${dir}"
125 fi 253 fi
126 done 254 done
127 255
128 eend ${retval} 256 eend ${retval}
129 257
130 for (( i = 0 ; i < ${#fails[@]} ; i++ )) ; do 258 for f in "${fails[@]}" ; do
131 ### HACK!! This is needed until bash 3.1 is unmasked.
132 ## The current stable version of bash lists the sizeof fails to be 1
133 ## when there are no elements in the list because it is declared local.
134 ## In order to prevent the declaration from being in global scope, we
135 ## this hack to prevent an empty error message being printed for stable
136 ## users. -- compnerd && allanonjl
137 if [[ "${fails[i]}" != "" && "${fails[i]}" != "()" ]] ; then
138 eerror "Failed to update cache with icon ${fails[i]}" 259 eerror "Failed to update cache with icon $f"
139 fi
140 done 260 done
141} 261}
142 262
143 263# @FUNCTION: gnome2_omf_fix
264# @DESCRIPTION:
144# Workaround applied to Makefile rules in order to remove redundant 265# Workaround applied to Makefile rules in order to remove redundant
145# calls to scrollkeeper-update and sandbox violations. 266# calls to scrollkeeper-update and sandbox violations.
267# This function should be called from src_prepare.
146gnome2_omf_fix() { 268gnome2_omf_fix() {
147 local omf_makefiles filename 269 local omf_makefiles filename
148 270
149 omf_makefiles="$@" 271 omf_makefiles="$@"
150 272
151 if [[ -f ${S}/omf.make ]] ; then 273 if [[ -f ${S}/omf.make ]] ; then
152 omf_makefiles="${omf_makefiles} ${S}/omf.make" 274 omf_makefiles="${omf_makefiles} ${S}/omf.make"
153 fi 275 fi
154 276
155 # testing fixing of all makefiles found 277 # testing fixing of all makefiles found
278 # The sort is important to ensure .am is listed before the respective .in for
279 # maintainer mode regeneration not kicking in due to .am being newer than .in
156 for filename in $(find ./ -name "Makefile.in" -o -name "Makefile.am") ; do 280 for filename in $(find ./ -name "Makefile.in" -o -name "Makefile.am" |sort) ; do
157 omf_makefiles="${omf_makefiles} ${filename}" 281 omf_makefiles="${omf_makefiles} ${filename}"
158 done 282 done
159 283
160 ebegin "Fixing OMF Makefiles" 284 ebegin "Fixing OMF Makefiles"
161 285
163 local fails=( ) 287 local fails=( )
164 288
165 for omf in ${omf_makefiles} ; do 289 for omf in ${omf_makefiles} ; do
166 local rv=0 290 local rv=0
167 291
168 sed -i -e 's:scrollkeeper-update:true:' ${omf} 292 sed -i -e 's:scrollkeeper-update:true:' "${omf}"
169 retval=$? 293 retval=$?
170 294
171 if [[ ! $rv -eq 0 ]] ; then 295 if [[ ! $rv -eq 0 ]] ; then
172 debug-print "updating of ${omf} failed" 296 debug-print "updating of ${omf} failed"
173 297
178 fi 302 fi
179 done 303 done
180 304
181 eend $retval 305 eend $retval
182 306
183 for (( i = 0 ; i < ${#fails[@]} ; i++ )) ; do 307 for f in "${fails[@]}" ; do
184 ### HACK!! This is needed until bash 3.1 is unmasked.
185 ## The current stable version of bash lists the sizeof fails to be 1
186 ## when there are no elements in the list because it is declared local.
187 ## In order to prevent the declaration from being in global scope, we
188 ## this hack to prevent an empty error message being printed for stable
189 ## users. -- compnerd && allanonjl
190 if [[ "${fails[i]}" != "" && "${fails[i]}" != "()" ]] ; then
191 eerror "Failed to update OMF Makefile ${fails[i]}" 308 eerror "Failed to update OMF Makefile $f"
192 fi
193 done 309 done
194} 310}
195 311
196 312# @FUNCTION: gnome2_scrollkeeper_update
313# @DESCRIPTION:
197# Updates the global scrollkeeper database. 314# Updates the global scrollkeeper database.
315# This function should be called from pkg_postinst and pkg_postrm.
198gnome2_scrollkeeper_update() { 316gnome2_scrollkeeper_update() {
317 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
199 if [[ -x ${SCROLLKEEPER_UPDATE_BIN} ]]; then 318 if [[ -x "${EROOT}${SCROLLKEEPER_UPDATE_BIN}" ]]; then
200 einfo "Updating scrollkeeper database ..." 319 einfo "Updating scrollkeeper database ..."
201 ${SCROLLKEEPER_UPDATE_BIN} -q -p ${SCROLLKEEPER_DIR} 320 "${EROOT}${SCROLLKEEPER_UPDATE_BIN}" -q -p "${EROOT}${SCROLLKEEPER_DIR}"
202 fi 321 fi
203} 322}
204 323
324# @FUNCTION: gnome2_schemas_savelist
325# @DESCRIPTION:
326# Find if there is any GSettings schema to install and save the list in
327# GNOME2_ECLASS_GLIB_SCHEMAS variable.
328# This function should be called from pkg_preinst.
329gnome2_schemas_savelist() {
330 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
331 pushd "${ED}" &>/dev/null
332 export GNOME2_ECLASS_GLIB_SCHEMAS=$(find 'usr/share/glib-2.0/schemas' -name '*.gschema.xml' 2>/dev/null)
333 popd &>/dev/null
334}
335
336# @FUNCTION: gnome2_schemas_update
337# @USAGE: gnome2_schemas_update
338# @DESCRIPTION:
339# Updates GSettings schemas if GNOME2_ECLASS_GLIB_SCHEMAS has some.
340# This function should be called from pkg_postinst and pkg_postrm.
341gnome2_schemas_update() {
342 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT="${ROOT}"
343 local updater="${EROOT}${GLIB_COMPILE_SCHEMAS}"
344
345 if [[ ! -x ${updater} ]]; then
346 debug-print "${updater} is not executable"
347 return
348 fi
349
350 if [[ -z ${GNOME2_ECLASS_GLIB_SCHEMAS} ]]; then
351 debug-print "No GSettings schemas to update"
352 return
353 fi
354
355 ebegin "Updating GSettings schemas"
356 ${updater} --allow-any-name "$@" "${EROOT%/}/usr/share/glib-2.0/schemas" &>/dev/null
357 eend $?
358}

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.26

  ViewVC Help
Powered by ViewVC 1.1.20