diff options
author | Michał Górny <mgorny@gentoo.org> | 2012-11-19 21:38:33 +0000 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2012-11-19 21:38:33 +0000 |
commit | 0b46bb8c7e27c396cb51996af45eb07559317086 (patch) | |
tree | 407555d7d228ba19378387f4bcf891153fcf12e7 /eclass | |
parent | Version bump wrt bug #397645. Thanks to Andrew Savchenko for his effort on li... (diff) | |
download | gentoo-2-0b46bb8c7e27c396cb51996af45eb07559317086.tar.gz gentoo-2-0b46bb8c7e27c396cb51996af45eb07559317086.tar.bz2 gentoo-2-0b46bb8c7e27c396cb51996af45eb07559317086.zip |
Introduce a check for USE_PYTHON & PYTHON_TARGETS compatibility.
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/ChangeLog | 5 | ||||
-rw-r--r-- | eclass/python-r1.eclass | 200 |
2 files changed, 203 insertions, 2 deletions
diff --git a/eclass/ChangeLog b/eclass/ChangeLog index bfc50089a1e3..2478d1953435 100644 --- a/eclass/ChangeLog +++ b/eclass/ChangeLog @@ -1,6 +1,9 @@ # ChangeLog for eclass directory # Copyright 1999-2012 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.512 2012/11/19 20:35:16 slyfox Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.513 2012/11/19 21:38:33 mgorny Exp $ + + 19 Nov 2012; Michał Górny <mgorny@gentoo.org> python-r1.eclass: + Introduce a check for USE_PYTHON & PYTHON_TARGETS compatibility. 19 Nov 2012; Sergei Trofimovich <slyfox@gentoo.org> haskell-cabal.eclass: Added new helper function 'cabal_chdeps' and and debug variable diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass index 0d6ef4c86211..a08e0a0523be 100644 --- a/eclass/python-r1.eclass +++ b/eclass/python-r1.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.17 2012/11/04 15:16:34 mgorny Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/python-r1.eclass,v 1.18 2012/11/19 21:38:33 mgorny Exp $ # @ECLASS: python-r1 # @MAINTAINER: @@ -363,6 +363,202 @@ python_copy_sources() { done } +# @FUNCTION: _python_check_USE_PYTHON +# @INTERNAL +# @DESCRIPTION: +# Check whether USE_PYTHON and PYTHON_TARGETS are in sync. Output +# warnings if they are not. +_python_check_USE_PYTHON() { + debug-print-function ${FUNCNAME} "${@}" + + if [[ ! ${_PYTHON_USE_PYTHON_CHECKED} ]]; then + _PYTHON_USE_PYTHON_CHECKED=1 + + # python-exec has profile-forced flags. + if [[ ${CATEGORY}/${PN} == dev-python/python-exec ]]; then + return + fi + + _try_eselect() { + # The eselect solution will work only with one py2 & py3. + + local impl py2 py3 dis_py2 dis_py3 + for impl in "${PYTHON_COMPAT[@]}"; do + if use "python_targets_${impl}"; then + case "${impl}" in + python2_*) + if [[ ${py2+1} ]]; then + debug-print "${FUNCNAME}: -> more than one py2: ${py2} ${impl}" + return 1 + fi + py2=${impl/_/.} + ;; + python3_*) + if [[ ${py3+1} ]]; then + debug-print "${FUNCNAME}: -> more than one py3: ${py3} ${impl}" + return 1 + fi + py3=${impl/_/.} + ;; + *) + return 1 + ;; + esac + else + case "${impl}" in + python2_*) + dis_py2=1 + ;; + python3_*) + dis_py3=1 + ;; + esac + fi + done + + # The eselect solution won't work if the disabled Python version + # is installed. + if [[ ! ${py2+1} && ${dis_py2} ]]; then + debug-print "${FUNCNAME}: -> all py2 versions disabled" + if has_version '=dev-lang/python-2*'; then + debug-print "${FUNCNAME}: ---> but =python-2* installed!" + return 1 + fi + fi + if [[ ! ${py3+1} && ${dis_py3} ]]; then + debug-print "${FUNCNAME}: -> all py3 versions disabled" + if has_version '=dev-lang/python-3*'; then + debug-print "${FUNCNAME}: ---> but =python-3* installed!" + return 1 + fi + fi + + local warned + + # Now check whether the correct implementations are active. + if [[ ${py2+1} ]]; then + local sel_py2=$(eselect python show --python2) + + debug-print "${FUNCNAME}: -> py2 built: ${py2}, active: ${sel_py2}" + if [[ ${py2} != ${sel_py2} ]]; then + ewarn "Building package for ${py2} only while ${sel_py2} is active." + ewarn "Please consider switching the active Python 2 interpreter:" + ewarn + ewarn " eselect python set --python2 ${py2}" + warned=1 + fi + fi + + if [[ ${py3+1} ]]; then + local sel_py3=$(eselect python show --python3) + + debug-print "${FUNCNAME}: -> py3 built: ${py3}, active: ${sel_py3}" + if [[ ${py3} != ${sel_py3} ]]; then + [[ ${warned} ]] && ewarn + ewarn "Building package for ${py3} only while ${sel_py3} is active." + ewarn "Please consider switching the active Python 3 interpreter:" + ewarn + ewarn " eselect python set --python3 ${py3}" + warned=1 + fi + fi + + if [[ ${warned} ]]; then + ewarn + ewarn "Please note that after switching the active Python interpreter," + ewarn "you may need to run 'python-updater' to rebuild affected packages." + ewarn + ewarn "For more information on python.eclass compatibility, please see" + ewarn "the appropriate python-r1 User's Guide chapter [1]." + ewarn + ewarn "[1] http://www.gentoo.org/proj/en/Python/python-r1/user-guide.xml#doc_chap2" + fi + } + + # If user has no USE_PYTHON, try to avoid it. + if [[ ! ${USE_PYTHON} ]]; then + debug-print "${FUNCNAME}: trying eselect solution ..." + _try_eselect && return + fi + + debug-print "${FUNCNAME}: trying USE_PYTHON solution ..." + debug-print "${FUNCNAME}: -> USE_PYTHON=${USE_PYTHON}" + + local impl old=${USE_PYTHON} new=() removed=() + + for impl in "${PYTHON_COMPAT[@]}"; do + local abi + case "${impl}" in + python*) + abi=${impl#python} + ;; + jython*) + abi=${impl#jython}-jython + ;; + pypy*) + abi=2.7-pypy-${impl#pypy} + ;; + *) + die "Unexpected Python implementation: ${impl}" + ;; + esac + abi=${abi/_/.} + + has "${abi}" ${USE_PYTHON} + local has_abi=${?} + use "python_targets_${impl}" + local has_impl=${?} + + # 0 = has, 1 = does not have + if [[ ${has_abi} == 0 && ${has_impl} == 1 ]]; then + debug-print "${FUNCNAME}: ---> remove ${abi}" + # remove from USE_PYTHON + old=${old/${abi}/} + removed+=( ${abi} ) + elif [[ ${has_abi} == 1 && ${has_impl} == 0 ]]; then + debug-print "${FUNCNAME}: ---> add ${abi}" + # add to USE_PYTHON + new+=( ${abi} ) + fi + done + + if [[ ${removed[@]} || ${new[@]} ]]; then + old=( ${old} ) + + debug-print "${FUNCNAME}: -> old: ${old[@]}" + debug-print "${FUNCNAME}: -> new: ${new[@]}" + debug-print "${FUNCNAME}: -> removed: ${removed[@]}" + + if [[ ${USE_PYTHON} ]]; then + ewarn "It seems that your USE_PYTHON setting lists different Python" + ewarn "implementations than your PYTHON_TARGETS variable. Please consider" + ewarn "using the following value instead:" + ewarn + ewarn " USE_PYTHON='\033[35m${old[@]}${new[@]+ \033[1m${new[@]}}\033[0m'" + + if [[ ${removed[@]} ]]; then + ewarn + ewarn "(removed \033[31m${removed[@]}\033[0m)" + fi + else + ewarn "It seems that you need to set USE_PYTHON to make sure that legacy" + ewarn "packages will be built with respect to PYTHON_TARGETS correctly:" + ewarn + ewarn " USE_PYTHON='\033[35;1m${new[@]}\033[0m'" + fi + + ewarn + ewarn "Please note that after changing the USE_PYTHON variable, you may need" + ewarn "to run 'python-updater' to rebuild affected packages." + ewarn + ewarn "For more information on python.eclass compatibility, please see" + ewarn "the appropriate python-r1 User's Guide chapter [1]." + ewarn + ewarn "[1] http://www.gentoo.org/proj/en/Python/python-r1/user-guide.xml#doc_chap2" + fi + fi +} + # @FUNCTION: python_foreach_impl # @USAGE: <command> [<args>...] # @DESCRIPTION: @@ -376,6 +572,8 @@ python_copy_sources() { python_foreach_impl() { debug-print-function ${FUNCNAME} "${@}" + _python_check_USE_PYTHON + local impl local bdir=${BUILD_DIR:-${S}} |