/[gentoo-x86]/eclass/python.eclass
Gentoo

Diff of /eclass/python.eclass

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

Revision 1.69 Revision 1.72
1# Copyright 1999-2009 Gentoo Foundation 1# Copyright 1999-2009 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.69 2009/08/31 23:58:28 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.72 2009/09/11 19:55:05 arfrever 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#
66 export PYVER_ALL="${tmpstr#Python }" 66 export PYVER_ALL="${tmpstr#Python }"
67 __python_version_extract $PYVER_ALL 67 __python_version_extract $PYVER_ALL
68} 68}
69 69
70# @FUNCTION: PYTHON 70# @FUNCTION: PYTHON
71# @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}"> 71# @USAGE: [-a|--absolute-path] [--] <Python_ABI="${PYTHON_ABI}">
72# @DESCRIPTION: 72# @DESCRIPTION:
73# Get Python interpreter filename for specified Python ABI. If Python_ABI argument 73# Get Python interpreter filename for specified Python ABI. If Python_ABI argument
74# is ommitted, then PYTHON_ABI environment variable must be set and is used. 74# is ommitted, then PYTHON_ABI environment variable must be set and is used.
75PYTHON() { 75PYTHON() {
76 local absolute_path="0" slot= 76 local absolute_path="0" slot=
77 77
78 while (($#)); do 78 while (($#)); do
79 case "$1" in 79 case "$1" in
80 -a|--absolute-path) 80 -a|--absolute-path)
81 absolute_path="1" 81 absolute_path="1"
82 ;;
83 --)
84 break
82 ;; 85 ;;
83 -*) 86 -*)
84 die "${FUNCNAME}(): Unrecognized option $1" 87 die "${FUNCNAME}(): Unrecognized option $1"
85 ;; 88 ;;
86 *) 89 *)
125 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then 128 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
126 die "'/usr/bin/python-config' isn't valid script" 129 die "'/usr/bin/python-config' isn't valid script"
127 fi 130 fi
128 131
129 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. 132 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4.
130 if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then 133 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then
131 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI 134 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI
132 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" 135 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
133 136
134 if [[ "$(declare -p USE_PYTHON 2>/dev/null)" == "declare -x USE_PYTHON="* ]]; then 137 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
135 if [[ -z "${USE_PYTHON}" ]]; then 138 if [[ -z "${USE_PYTHON}" ]]; then
136 die "USE_PYTHON variable is empty" 139 die "USE_PYTHON variable is empty"
137 fi 140 fi
138 141
139 for ABI in ${USE_PYTHON}; do 142 for ABI in ${USE_PYTHON}; do
165 done 168 done
166 export PYTHON_ABIS="${PYVER}" 169 export PYTHON_ABIS="${PYVER}"
167 fi 170 fi
168 fi 171 fi
169 172
170 # Ensure that EPYTHON variable is respected.
171 local PYTHON_ABI 173 local PYTHON_ABI
172 for PYTHON_ABI in ${PYTHON_ABIS}; do 174 for PYTHON_ABI in ${PYTHON_ABIS}; do
175 # Ensure that appropriate Python version is installed.
176 if ! has_version "dev-lang/python:${PYTHON_ABI}"; then
177 die "dev-lang/python:${PYTHON_ABI} isn't installed"
178 fi
179
180 # Ensure that EPYTHON variable is respected.
173 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then 181 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then
174 die "'python' doesn't respect EPYTHON variable" 182 die "'python' doesn't respect EPYTHON variable"
175 fi 183 fi
176 done 184 done
177} 185}
178 186
179# @FUNCTION: python_copy_sources 187# @FUNCTION: python_copy_sources
180# @USAGE: [directory] 188# @USAGE: [--no-link] [--] [directory]
181# @DESCRIPTION: 189# @DESCRIPTION:
182# Copy unpacked sources of given package for each Python ABI. 190# Copy unpacked sources of given package for each Python ABI.
183python_copy_sources() { 191python_copy_sources() {
184 local dir dirs=() PYTHON_ABI 192 local dir dirs=() no_link="0" PYTHON_ABI
193
194 while (($#)); do
195 case "$1" in
196 --no-link)
197 no_link="1"
198 ;;
199 --)
200 break
201 ;;
202 -*)
203 die "${FUNCNAME}(): Unrecognized option '$1'"
204 ;;
205 *)
206 break
207 ;;
208 esac
209 shift
210 done
185 211
186 if [[ "$#" -eq "0" ]]; then 212 if [[ "$#" -eq "0" ]]; then
187 if [[ "${WORKDIR}" == "${S}" ]]; then 213 if [[ "${WORKDIR}" == "${S}" ]]; then
188 die "${FUNCNAME}() cannot be used" 214 die "${FUNCNAME}() cannot be used"
189 fi 215 fi
193 fi 219 fi
194 220
195 validate_PYTHON_ABIS 221 validate_PYTHON_ABIS
196 for PYTHON_ABI in ${PYTHON_ABIS}; do 222 for PYTHON_ABI in ${PYTHON_ABIS}; do
197 for dir in "${dirs[@]}"; do 223 for dir in "${dirs[@]}"; do
224 if [[ "${no_link}" == "1" ]]; then
225 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
226 else
198 cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" 227 cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
228 fi
199 done 229 done
200 done 230 done
201} 231}
202 232
203# @FUNCTION: python_set_build_dir_symlink 233# @FUNCTION: python_set_build_dir_symlink
214 rm -f "${dir}" || die "Deletion of '${dir}' failed" 244 rm -f "${dir}" || die "Deletion of '${dir}' failed"
215 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" 245 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
216} 246}
217 247
218# @FUNCTION: python_execute_function 248# @FUNCTION: python_execute_function
219# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments] 249# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--] <function> [arguments]
220# @DESCRIPTION: 250# @DESCRIPTION:
221# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 251# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
222# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 252# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
223python_execute_function() { 253python_execute_function() {
224 local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" PYTHON_ABI quiet="0" separate_build_dirs="0" 254 local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0"
225 255
226 while (($#)); do 256 while (($#)); do
227 case "$1" in 257 case "$1" in
228 --action-message) 258 --action-message)
229 action_message_template="$2" 259 action_message_template="$2"
242 -q|--quiet) 272 -q|--quiet)
243 quiet="1" 273 quiet="1"
244 ;; 274 ;;
245 -s|--separate-build-dirs) 275 -s|--separate-build-dirs)
246 separate_build_dirs="1" 276 separate_build_dirs="1"
277 ;;
278 --)
279 break
247 ;; 280 ;;
248 -*) 281 -*)
249 die "${FUNCNAME}(): Unrecognized option '$1'" 282 die "${FUNCNAME}(): Unrecognized option '$1'"
250 ;; 283 ;;
251 *) 284 *)
348 pushd "${BUILDDIR}" > /dev/null || die "pushd failed" 381 pushd "${BUILDDIR}" > /dev/null || die "pushd failed"
349 else 382 else
350 export BUILDDIR="${S}" 383 export BUILDDIR="${S}"
351 fi 384 fi
352 385
386 previous_directory_stack_length="${#DIRSTACK[@]}"
387
353 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 388 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
354 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 389 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
355 else 390 else
356 EPYTHON="$(PYTHON)" "${function}" "$@" 391 EPYTHON="$(PYTHON)" "${function}" "$@"
357 fi 392 fi
366 if [[ "${nonfatal}" == "1" ]]; then 401 if [[ "${nonfatal}" == "1" ]]; then
367 if [[ "${quiet}" == "0" ]]; then 402 if [[ "${quiet}" == "0" ]]; then
368 ewarn "${RED}${failure_message}${NORMAL}" 403 ewarn "${RED}${failure_message}${NORMAL}"
369 fi 404 fi
370 elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 405 elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
406 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
371 local ABI enabled_PYTHON_ABIS= 407 local ABI enabled_PYTHON_ABIS=
372 for ABI in ${PYTHON_ABIS}; do 408 for ABI in ${PYTHON_ABIS}; do
373 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}" 409 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
374 done 410 done
375 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }" 411 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
412 fi
376 if [[ "${quiet}" == "0" ]]; then 413 if [[ "${quiet}" == "0" ]]; then
377 ewarn "${RED}${failure_message}${NORMAL}" 414 ewarn "${RED}${failure_message}${NORMAL}"
378 fi 415 fi
379 if [[ -z "${PYTHON_ABIS}" ]]; then 416 if [[ -z "${PYTHON_ABIS}" ]]; then
380 die "${function}() function failed with all enabled versions of Python" 417 die "${function}() function failed with all enabled versions of Python"
381 fi 418 fi
382 else 419 else
383 die "${failure_message}" 420 die "${failure_message}"
384 fi 421 fi
385 fi 422 fi
423
424 if [[ "${#DIRSTACK[@]}" -lt "${previous_directory_stack_length}" ]]; then
425 die "Directory stack decreased illegally"
426 fi
427
428 while [[ "${#DIRSTACK[@]}" -gt "${previous_directory_stack_length}" ]]; do
429 popd > /dev/null || die "popd failed"
430 done
386 431
387 if [[ "${separate_build_dirs}" == "1" ]]; then 432 if [[ "${separate_build_dirs}" == "1" ]]; then
388 popd > /dev/null || die "popd failed" 433 popd > /dev/null || die "popd failed"
389 fi 434 fi
390 unset BUILDDIR 435 unset BUILDDIR

Legend:
Removed from v.1.69  
changed lines
  Added in v.1.72

  ViewVC Help
Powered by ViewVC 1.1.20