| 1 | # Copyright 1999-2008 Gentoo Foundation |
1 | # Copyright 1999-2008 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/python.eclass,v 1.37 2008/05/29 18:36:20 hawking Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.39 2008/05/29 21:19:19 hawking Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: python.eclass |
5 | # @ECLASS: python.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # python@gentoo.org |
7 | # python@gentoo.org |
| 8 | # |
8 | # |
| … | |
… | |
| 135 | python_mod_compile() { |
135 | python_mod_compile() { |
| 136 | local f myroot |
136 | local f myroot |
| 137 | |
137 | |
| 138 | # Check if phase is pkg_postinst() |
138 | # Check if phase is pkg_postinst() |
| 139 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
139 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
| 140 | die "${FUNCNAME} should only be run in pkg_postinst()" |
140 | die "${FUNCNAME} should only be run in pkg_postinst()" |
| 141 | |
141 | |
| 142 | # allow compiling for older python versions |
142 | # allow compiling for older python versions |
| 143 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
143 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
| 144 | PYVER=${PYTHON_OVERRIDE_PYVER} |
144 | PYVER=${PYTHON_OVERRIDE_PYVER} |
| 145 | else |
145 | else |
| … | |
… | |
| 171 | # |
171 | # |
| 172 | # If supplied with arguments, it will recompile all modules recursively |
172 | # If supplied with arguments, it will recompile all modules recursively |
| 173 | # in the supplied directory |
173 | # in the supplied directory |
| 174 | # This function should only be run in pkg_postinst() |
174 | # This function should only be run in pkg_postinst() |
| 175 | # |
175 | # |
|
|
176 | # Options passed to this function are passed to compileall.py |
|
|
177 | # |
| 176 | # Example: |
178 | # Example: |
| 177 | # python_mod_optimize /usr/share/codegen |
179 | # python_mod_optimize /usr/share/codegen |
| 178 | python_mod_optimize() { |
180 | python_mod_optimize() { |
| 179 | local mydirs myfiles myroot path |
181 | local mydirs myfiles myroot myopts path |
| 180 | |
182 | |
| 181 | # Check if phase is pkg_postinst() |
183 | # Check if phase is pkg_postinst() |
| 182 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
184 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
| 183 | die "${FUNCNAME} should only be run in pkg_postinst()" |
185 | die "${FUNCNAME} should only be run in pkg_postinst()" |
| 184 | |
186 | |
| 185 | # strip trailing slash |
187 | # strip trailing slash |
| 186 | myroot="${ROOT%/}" |
188 | myroot="${ROOT%/}" |
| 187 | |
189 | |
| 188 | # respect ROOT |
190 | # respect ROOT and options passed to compileall.py |
|
|
191 | while [ $# -gt 0 ]; do |
|
|
192 | case $1 in |
|
|
193 | -l|-f|-q) |
|
|
194 | myopts="${myopts} $1" |
|
|
195 | ;; |
|
|
196 | -d|-x) |
|
|
197 | # -x takes regexp as argument so quoting is necessary. |
|
|
198 | myopts="${myopts} $1 \"$2\"" |
|
|
199 | shift |
|
|
200 | ;; |
|
|
201 | -*) |
|
|
202 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
|
|
203 | ;; |
|
|
204 | *) |
| 189 | for path in $@; do |
205 | for path in $@; do |
| 190 | [ ! -e "${myroot}/${path}" ] && ewarn "${myroot}/${path} doesn't exist!" |
206 | [ ! -e "${myroot}/${path}" ] && ewarn "${myroot}/${path} doesn't exist!" |
| 191 | [ -d "${myroot}/${path#/}" ] && mydirs="${mydirs} ${myroot}/${path#/}" |
207 | [ -d "${myroot}/${path#/}" ] && mydirs="${mydirs} ${myroot}/${path#/}" |
| 192 | # Files are passed to python_mod_compile which is ROOT-aware |
208 | # Files are passed to python_mod_compile which is ROOT-aware |
| 193 | [ -f "${myroot}/${path}" ] && myfiles="${myfiles} ${path}" |
209 | [ -f "${myroot}/${path}" ] && myfiles="${myfiles} ${path}" |
|
|
210 | done |
|
|
211 | ;; |
|
|
212 | esac |
|
|
213 | shift |
| 194 | done |
214 | done |
| 195 | |
215 | |
| 196 | # allow compiling for older python versions |
216 | # allow compiling for older python versions |
| 197 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
217 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
| 198 | PYVER=${PYTHON_OVERRIDE_PYVER} |
218 | PYVER=${PYTHON_OVERRIDE_PYVER} |
| … | |
… | |
| 209 | |
229 | |
| 210 | ebegin "Byte compiling python modules for python-${PYVER} .." |
230 | ebegin "Byte compiling python modules for python-${PYVER} .." |
| 211 | if [ -n "${mydirs}" ]; then |
231 | if [ -n "${mydirs}" ]; then |
| 212 | python${PYVER} \ |
232 | python${PYVER} \ |
| 213 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
233 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 214 | ${compileopts} ${mydirs} |
234 | ${compileopts} ${myopts} ${mydirs} |
| 215 | python${PYVER} -O \ |
235 | python${PYVER} -O \ |
| 216 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
236 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 217 | ${compileopts} ${mydirs} |
237 | ${compileopts} ${myopts} ${mydirs} |
| 218 | fi |
238 | fi |
| 219 | |
239 | |
| 220 | if [ -n "${myfiles}" ]; then |
240 | if [ -n "${myfiles}" ]; then |
| 221 | python_mod_compile ${myfiles} |
241 | python_mod_compile ${myfiles} |
| 222 | fi |
242 | fi |
| … | |
… | |
| 236 | # |
256 | # |
| 237 | # This function should only be run in pkg_postrm() |
257 | # This function should only be run in pkg_postrm() |
| 238 | python_mod_cleanup() { |
258 | python_mod_cleanup() { |
| 239 | local SEARCH_PATH myroot |
259 | local SEARCH_PATH myroot |
| 240 | |
260 | |
| 241 | # Check if phase is pkg_postinst() |
261 | # Check if phase is pkg_postrm() |
| 242 | [[ ${EBUILD_PHASE} != postrm ]] &&\ |
262 | [[ ${EBUILD_PHASE} != postrm ]] &&\ |
| 243 | die "${FUNCNAME} should only be run in pkg_postrm()" |
263 | die "${FUNCNAME} should only be run in pkg_postrm()" |
| 244 | |
264 | |
| 245 | # strip trailing slash |
265 | # strip trailing slash |
| 246 | myroot="${ROOT%/}" |
266 | myroot="${ROOT%/}" |
| 247 | |
267 | |
| 248 | if [ $# -gt 0 ]; then |
268 | if [ $# -gt 0 ]; then |