| 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.72 2009/09/11 19:55:05 arfrever Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.73 2009/09/18 17:50:08 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 | # |
|
|
| 9 | # original author: Alastair Tse <liquidx@gentoo.org> |
|
|
| 10 | # @BLURB: A Utility Eclass that should be inherited by anything that deals with Python or Python modules. |
8 | # @BLURB: A Utility Eclass that should be inherited by anything that deals with Python or Python modules. |
| 11 | # @DESCRIPTION: |
9 | # @DESCRIPTION: |
| 12 | # Some useful functions for dealing with Python. |
10 | # Some useful functions for dealing with Python. |
| 13 | |
11 | |
| 14 | inherit multilib |
12 | inherit multilib |
| … | |
… | |
| 249 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--] <function> [arguments] |
247 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--] <function> [arguments] |
| 250 | # @DESCRIPTION: |
248 | # @DESCRIPTION: |
| 251 | # Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
249 | # Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
| 252 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
250 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
| 253 | python_execute_function() { |
251 | python_execute_function() { |
| 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" |
252 | local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" |
| 255 | |
253 | |
| 256 | while (($#)); do |
254 | while (($#)); do |
| 257 | case "$1" in |
255 | case "$1" in |
| 258 | --action-message) |
256 | --action-message) |
| 259 | action_message_template="$2" |
257 | action_message_template="$2" |
| … | |
… | |
| 381 | pushd "${BUILDDIR}" > /dev/null || die "pushd failed" |
379 | pushd "${BUILDDIR}" > /dev/null || die "pushd failed" |
| 382 | else |
380 | else |
| 383 | export BUILDDIR="${S}" |
381 | export BUILDDIR="${S}" |
| 384 | fi |
382 | fi |
| 385 | |
383 | |
| 386 | previous_directory_stack_length="${#DIRSTACK[@]}" |
384 | previous_directory="$(pwd)" |
|
|
385 | previous_directory_stack="$(dirs -p)" |
|
|
386 | previous_directory_stack_length="$(dirs -p | wc -l)" |
| 387 | |
387 | |
| 388 | 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 |
| 389 | EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" |
389 | EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" |
| 390 | else |
390 | else |
| 391 | EPYTHON="$(PYTHON)" "${function}" "$@" |
391 | EPYTHON="$(PYTHON)" "${function}" "$@" |
| … | |
… | |
| 419 | else |
419 | else |
| 420 | die "${failure_message}" |
420 | die "${failure_message}" |
| 421 | fi |
421 | fi |
| 422 | fi |
422 | fi |
| 423 | |
423 | |
|
|
424 | # Ensure that directory stack hasn't been decreased. |
| 424 | if [[ "${#DIRSTACK[@]}" -lt "${previous_directory_stack_length}" ]]; then |
425 | if [[ "$(dirs -p | wc -l)" -lt "${previous_directory_stack_length}" ]]; then |
| 425 | die "Directory stack decreased illegally" |
426 | die "Directory stack decreased illegally" |
| 426 | fi |
427 | fi |
| 427 | |
428 | |
|
|
429 | # Avoid side effects of earlier returning from the specified function. |
| 428 | while [[ "${#DIRSTACK[@]}" -gt "${previous_directory_stack_length}" ]]; do |
430 | while [[ "$(dirs -p | wc -l)" -gt "${previous_directory_stack_length}" ]]; do |
| 429 | popd > /dev/null || die "popd failed" |
431 | popd > /dev/null || die "popd failed" |
| 430 | done |
432 | done |
|
|
433 | |
|
|
434 | # Ensure that the bottom part of directory stack hasn't been changed. Restore |
|
|
435 | # previous directory (from before running of the specified function) before |
|
|
436 | # comparison of directory stacks to avoid mismatch of directory stacks after |
|
|
437 | # potential using of 'cd' to change current directory. Restoration of previous |
|
|
438 | # directory allows to safely use 'cd' to change current directory in the |
|
|
439 | # specified function without changing it back to original directory. |
|
|
440 | cd "${previous_directory}" |
|
|
441 | if [[ "$(dirs -p)" != "${previous_directory_stack}" ]]; then |
|
|
442 | die "Directory stack changed illegally" |
|
|
443 | fi |
| 431 | |
444 | |
| 432 | if [[ "${separate_build_dirs}" == "1" ]]; then |
445 | if [[ "${separate_build_dirs}" == "1" ]]; then |
| 433 | popd > /dev/null || die "popd failed" |
446 | popd > /dev/null || die "popd failed" |
| 434 | fi |
447 | fi |
| 435 | unset BUILDDIR |
448 | unset BUILDDIR |