| 1 |
# Copyright 1999-2013 Gentoo Foundation
|
| 2 |
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/python-single-r1.eclass,v 1.10 2012/12/20 23:36:15 mgorny Exp $
|
| 4 |
|
| 5 |
# @ECLASS: python-single-r1
|
| 6 |
# @MAINTAINER:
|
| 7 |
# Python team <python@gentoo.org>
|
| 8 |
# @AUTHOR:
|
| 9 |
# Author: Michał Górny <mgorny@gentoo.org>
|
| 10 |
# Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
|
| 11 |
# @BLURB: An eclass for Python packages not installed for multiple implementations.
|
| 12 |
# @DESCRIPTION:
|
| 13 |
# An extension of the python-r1 eclass suite for packages which
|
| 14 |
# don't support being installed for multiple Python implementations.
|
| 15 |
# This mostly includes tools embedding Python.
|
| 16 |
#
|
| 17 |
# This eclass extends the IUSE and REQUIRED_USE set by python-r1
|
| 18 |
# to request correct PYTHON_SINGLE_TARGET. It also replaces
|
| 19 |
# PYTHON_USEDEP and PYTHON_DEPS with a more suitable form.
|
| 20 |
#
|
| 21 |
# Please note that packages support multiple Python implementations
|
| 22 |
# (using python-r1 eclass) can not depend on packages not supporting
|
| 23 |
# them (using this eclass).
|
| 24 |
#
|
| 25 |
# Please note that python-single-r1 will always inherit python-utils-r1
|
| 26 |
# as well. Thus, all the functions defined there can be used
|
| 27 |
# in the packages using python-single-r1, and there is no need ever
|
| 28 |
# to inherit both.
|
| 29 |
#
|
| 30 |
# For more information, please see the python-r1 Developer's Guide:
|
| 31 |
# http://www.gentoo.org/proj/en/Python/python-r1/dev-guide.xml
|
| 32 |
|
| 33 |
case "${EAPI:-0}" in
|
| 34 |
0|1|2|3|4)
|
| 35 |
die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
|
| 36 |
;;
|
| 37 |
5)
|
| 38 |
# EAPI=5 is required for meaningful USE default deps
|
| 39 |
# on USE_EXPAND flags
|
| 40 |
;;
|
| 41 |
*)
|
| 42 |
die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
|
| 43 |
;;
|
| 44 |
esac
|
| 45 |
|
| 46 |
if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
|
| 47 |
|
| 48 |
if [[ ${_PYTHON_R1} ]]; then
|
| 49 |
die 'python-single-r1.eclass can not be used with python-r1.eclass.'
|
| 50 |
elif [[ ${_PYTHON_ANY_R1} ]]; then
|
| 51 |
die 'python-single-r1.eclass can not be used with python-any-r1.eclass.'
|
| 52 |
fi
|
| 53 |
|
| 54 |
inherit python-utils-r1
|
| 55 |
|
| 56 |
fi
|
| 57 |
|
| 58 |
EXPORT_FUNCTIONS pkg_setup
|
| 59 |
|
| 60 |
if [[ ! ${_PYTHON_SINGLE_R1} ]]; then
|
| 61 |
|
| 62 |
# @ECLASS-VARIABLE: PYTHON_COMPAT
|
| 63 |
# @REQUIRED
|
| 64 |
# @DESCRIPTION:
|
| 65 |
# This variable contains a list of Python implementations the package
|
| 66 |
# supports. It must be set before the `inherit' call. It has to be
|
| 67 |
# an array.
|
| 68 |
#
|
| 69 |
# Example:
|
| 70 |
# @CODE
|
| 71 |
# PYTHON_COMPAT=( python{2_5,2_6,2_7} )
|
| 72 |
# @CODE
|
| 73 |
if ! declare -p PYTHON_COMPAT &>/dev/null; then
|
| 74 |
die 'PYTHON_COMPAT not declared.'
|
| 75 |
fi
|
| 76 |
|
| 77 |
# @ECLASS-VARIABLE: PYTHON_REQ_USE
|
| 78 |
# @DEFAULT_UNSET
|
| 79 |
# @DESCRIPTION:
|
| 80 |
# The list of USEflags required to be enabled on the chosen Python
|
| 81 |
# implementations, formed as a USE-dependency string. It should be valid
|
| 82 |
# for all implementations in PYTHON_COMPAT, so it may be necessary to
|
| 83 |
# use USE defaults.
|
| 84 |
#
|
| 85 |
# Example:
|
| 86 |
# @CODE
|
| 87 |
# PYTHON_REQ_USE="gdbm,ncurses(-)?"
|
| 88 |
# @CODE
|
| 89 |
#
|
| 90 |
# It will cause the Python dependencies to look like:
|
| 91 |
# @CODE
|
| 92 |
# python_single_target_pythonX_Y? ( dev-lang/python:X.Y[gdbm,ncurses(-)?] )
|
| 93 |
# @CODE
|
| 94 |
|
| 95 |
# @ECLASS-VARIABLE: PYTHON_DEPS
|
| 96 |
# @DESCRIPTION:
|
| 97 |
# This is an eclass-generated Python dependency string for all
|
| 98 |
# implementations listed in PYTHON_COMPAT.
|
| 99 |
#
|
| 100 |
# The dependency string is conditional on PYTHON_SINGLE_TARGET.
|
| 101 |
#
|
| 102 |
# Example use:
|
| 103 |
# @CODE
|
| 104 |
# RDEPEND="${PYTHON_DEPS}
|
| 105 |
# dev-foo/mydep"
|
| 106 |
# DEPEND="${RDEPEND}"
|
| 107 |
# @CODE
|
| 108 |
#
|
| 109 |
# Example value:
|
| 110 |
# @CODE
|
| 111 |
# dev-python/python-exec
|
| 112 |
# python_single_target_python2_6? ( dev-lang/python:2.6[gdbm] )
|
| 113 |
# python_single_target_python2_7? ( dev-lang/python:2.7[gdbm] )
|
| 114 |
# @CODE
|
| 115 |
|
| 116 |
# @ECLASS-VARIABLE: PYTHON_USEDEP
|
| 117 |
# @DESCRIPTION:
|
| 118 |
# This is an eclass-generated USE-dependency string which can be used to
|
| 119 |
# depend on another Python package being built for the same Python
|
| 120 |
# implementations.
|
| 121 |
#
|
| 122 |
# The generate USE-flag list is compatible with packages using python-r1,
|
| 123 |
# python-single-r1 and python-distutils-ng eclasses. It must not be used
|
| 124 |
# on packages using python.eclass.
|
| 125 |
#
|
| 126 |
# Example use:
|
| 127 |
# @CODE
|
| 128 |
# RDEPEND="dev-python/foo[${PYTHON_USEDEP}]"
|
| 129 |
# @CODE
|
| 130 |
#
|
| 131 |
# Example value:
|
| 132 |
# @CODE
|
| 133 |
# python_targets_python2_7?,python_single_target_python2_7(+)?
|
| 134 |
# @CODE
|
| 135 |
|
| 136 |
_python_single_set_globals() {
|
| 137 |
local flags_mt=( "${PYTHON_COMPAT[@]/#/python_targets_}" )
|
| 138 |
local flags=( "${PYTHON_COMPAT[@]/#/python_single_target_}" )
|
| 139 |
local optflags=${flags_mt[@]/%/?}
|
| 140 |
optflags+=,${flags[@]/%/(+)?}
|
| 141 |
|
| 142 |
IUSE="${flags_mt[*]} ${flags[*]}"
|
| 143 |
REQUIRED_USE="|| ( ${flags_mt[*]} ) ^^ ( ${flags[*]} )"
|
| 144 |
PYTHON_USEDEP=${optflags// /,}
|
| 145 |
|
| 146 |
# 1) well, python-exec would suffice as an RDEP
|
| 147 |
# but no point in making this overcomplex, BDEP doesn't hurt anyone
|
| 148 |
# 2) python-exec should be built with all targets forced anyway
|
| 149 |
# but if new targets were added, we may need to force a rebuild
|
| 150 |
PYTHON_DEPS="dev-python/python-exec[${PYTHON_USEDEP}]"
|
| 151 |
local i PYTHON_PKG_DEP
|
| 152 |
for i in "${PYTHON_COMPAT[@]}"; do
|
| 153 |
# The chosen targets need to be in PYTHON_TARGETS as well.
|
| 154 |
# This is in order to enforce correct dependencies on packages
|
| 155 |
# supporting multiple implementations.
|
| 156 |
REQUIRED_USE+=" python_single_target_${i}? ( python_targets_${i} )"
|
| 157 |
|
| 158 |
python_export "${i}" PYTHON_PKG_DEP
|
| 159 |
PYTHON_DEPS+=" python_single_target_${i}? ( ${PYTHON_PKG_DEP} )"
|
| 160 |
done
|
| 161 |
}
|
| 162 |
_python_single_set_globals
|
| 163 |
|
| 164 |
# @FUNCTION: python-single-r1_pkg_setup
|
| 165 |
# @DESCRIPTION:
|
| 166 |
# Determine what the selected Python implementation is and set EPYTHON
|
| 167 |
# and PYTHON accordingly.
|
| 168 |
python-single-r1_pkg_setup() {
|
| 169 |
debug-print-function ${FUNCNAME} "${@}"
|
| 170 |
|
| 171 |
local impl
|
| 172 |
for impl in "${_PYTHON_ALL_IMPLS[@]}"; do
|
| 173 |
if has "${impl}" "${PYTHON_COMPAT[@]}" \
|
| 174 |
&& use "python_single_target_${impl}"
|
| 175 |
then
|
| 176 |
python_export "${impl}" EPYTHON PYTHON
|
| 177 |
break
|
| 178 |
fi
|
| 179 |
done
|
| 180 |
}
|
| 181 |
|
| 182 |
# @FUNCTION: python_fix_shebang
|
| 183 |
# @USAGE: <path>...
|
| 184 |
# @DESCRIPTION:
|
| 185 |
# Replace the shebang in Python scripts with the current Python
|
| 186 |
# implementation (EPYTHON). If a directory is passed, works recursively
|
| 187 |
# on all Python scripts.
|
| 188 |
#
|
| 189 |
# Only files having a 'python' shebang will be modified; other files
|
| 190 |
# will be skipped. If a script has a complete shebang matching
|
| 191 |
# the chosen interpreter version, it is left unmodified. If a script has
|
| 192 |
# a complete shebang matching other version, the command dies.
|
| 193 |
python_fix_shebang() {
|
| 194 |
debug-print-function ${FUNCNAME} "${@}"
|
| 195 |
|
| 196 |
[[ ${1} ]] || die "${FUNCNAME}: no paths given"
|
| 197 |
[[ ${EPYTHON} ]] || die "${FUNCNAME}: EPYTHON unset (pkg_setup not called?)"
|
| 198 |
|
| 199 |
local path f
|
| 200 |
for path; do
|
| 201 |
while IFS= read -r -d '' f; do
|
| 202 |
local shebang=$(head -n 1 "${f}")
|
| 203 |
|
| 204 |
case "${shebang}" in
|
| 205 |
'#!'*${EPYTHON}*)
|
| 206 |
debug-print "${FUNCNAME}: in file ${f#${D}}"
|
| 207 |
debug-print "${FUNCNAME}: shebang matches EPYTHON: ${shebang}"
|
| 208 |
;;
|
| 209 |
'#!'*python[23].[0123456789]*|'#!'*pypy-c*|'#!'*jython*)
|
| 210 |
debug-print "${FUNCNAME}: in file ${f#${D}}"
|
| 211 |
debug-print "${FUNCNAME}: incorrect specific shebang: ${shebang}"
|
| 212 |
|
| 213 |
die "${f#${D}} has a specific Python shebang not matching EPYTHON"
|
| 214 |
;;
|
| 215 |
'#!'*python*)
|
| 216 |
debug-print "${FUNCNAME}: in file ${f#${D}}"
|
| 217 |
debug-print "${FUNCNAME}: rewriting shebang: ${shebang}"
|
| 218 |
|
| 219 |
einfo "Fixing shebang in ${f#${D}}"
|
| 220 |
_python_rewrite_shebang "${f}"
|
| 221 |
esac
|
| 222 |
done < <(find "${path}" -type f -print0)
|
| 223 |
done
|
| 224 |
}
|
| 225 |
|
| 226 |
_PYTHON_SINGLE_R1=1
|
| 227 |
fi
|