From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 2D9361382C5 for ; Thu, 10 May 2018 17:35:20 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C41BBE09F3; Thu, 10 May 2018 17:35:14 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 65D27E09D1 for ; Thu, 10 May 2018 17:35:14 +0000 (UTC) Received: from localhost.localdomain (d202-252.icpnet.pl [109.173.202.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id 92C28335C85; Thu, 10 May 2018 17:35:12 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH] scons-utils.eclass: Provide proper Python API for EAPI 7 Date: Thu, 10 May 2018 19:35:06 +0200 Message-Id: <20180510173506.21185-1-mgorny@gentoo.org> X-Mailer: git-send-email 2.17.0 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Archives-Salt: f44b79ba-d592-4260-b31a-9d04aad2e0dc X-Archives-Hash: 9f10fb7a3985a1296dd13982652d056e Provide a proper multi-impl Python support for scons-utils in EAPI 7, to account for new versions of dev-util/scons (3.0.1-r100+, to be committed) that support Python 3 and break SConstruct files using Python 2 constructs. Combining scons-utils with python-any-r1 and python-single-r1 is added retroactively for older EAPIs as well, with fallback to Python 2.7. The new (hard-to-use) API for python-r1 is specific to EAPI 7 since it requires adding explicit BDEPEND. The new use of the eclass is described on the wiki page, along with series of examples covering different use cases: https://wiki.gentoo.org/wiki/Project:Python/scons-utils_integration --- eclass/scons-utils.eclass | 64 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/eclass/scons-utils.eclass b/eclass/scons-utils.eclass index 5335968bc52e..615e00e314ad 100644 --- a/eclass/scons-utils.eclass +++ b/eclass/scons-utils.eclass @@ -9,6 +9,14 @@ # This eclass provides a set of function to help developers sanely call # dev-util/scons and pass parameters to it. # +# As of dev-util/scons-3.0.1-r100, SCons supports Python 3. Since +# SCons* files in build systems are written as Python, all packages +# need to explicitly verify which versions of Python are supported +# and use appropriate Python suite eclass to select the implementation. +# The eclass needs to be inherited before scons-utils, and scons-utils +# will automatically take advantage of it. For more details, please see: +# https://wiki.gentoo.org/wiki/Project:Python/scons-utils_integration +# # Please note that SCons is more like a 'build system creation kit', # and requires a lot of upstream customization to be used sanely. # You will often need to request fixes upstream and/or patch the build @@ -26,7 +34,8 @@ # # @EXAMPLE: # @CODE -# inherit scons-utils toolchain-funcs +# PYTHON_COMPAT=( python2_7 ) +# inherit python-any-r1 scons-utils toolchain-funcs # # EAPI=5 # @@ -93,7 +102,7 @@ # -- EAPI support check -- case ${EAPI:-0} in - 0|1|2|3|4|5|6) ;; + 0|1|2|3|4|5|6|7) ;; *) die "EAPI ${EAPI} unsupported." esac @@ -102,9 +111,38 @@ inherit multiprocessing # -- ebuild variables setup -- if [[ -n ${SCONS_MIN_VERSION} ]]; then - BDEPEND=">=dev-util/scons-${SCONS_MIN_VERSION}" + SCONS_DEPEND=">=dev-util/scons-${SCONS_MIN_VERSION}" else - BDEPEND="dev-util/scons" + SCONS_DEPEND="dev-util/scons" +fi + +if [[ ${_PYTHON_ANY_R1} ]]; then + # when using python-any-r1, use any-of dep API + BDEPEND="$(python_gen_any_dep "${SCONS_DEPEND}[\${PYTHON_USEDEP}]")" + + scons-utils_python_check_deps() { + has_version "${SCONS_DEPEND}[${PYTHON_USEDEP}]" + } + python_check_deps() { scons-utils_python_check_deps; } +elif [[ ${_PYTHON_SINGLE_R1} ]]; then + # when using python-single-r1, use plain PYTHON_USEDEP API + BDEPEND="${SCONS_DEPEND}[${PYTHON_USEDEP}] + ${PYTHON_DEPS}" +elif [[ ${EAPI:-0} == [0123456] ]]; then + # in older EAPIs, just force Python 2.7 + BDEPEND="${SCONS_DEPEND}[python_targets_python2_7]" +elif [[ ${_PYTHON_R1} ]]; then + # when using python-r1, you need to depend on scons yourself + # (depending on whether you need any-r1 or full -r1 API) + # -- since this is a breaking API change, it applies to EAPI 7+ only + BDEPEND="" +elif [[ ${EAPI:-0} != [0123456] ]]; then + # in EAPI 7+, require appropriate eclass use + eerror "Using scons-utils.eclass without any python-r1 suite eclass is not supported." + eerror "Please make sure to configure and inherit appropriate -r1 eclass." + eerror "For more information and examples, please see:" + eerror " https://wiki.gentoo.org/wiki/Project:Python/scons-utils_integration" + die "Invalid use of scons-utils.eclass" fi if [[ ${EAPI:-0} == [0123456] ]]; then @@ -124,6 +162,24 @@ escons() { debug-print-function ${FUNCNAME} "${@}" + if [[ ! ${EPYTHON} ]]; then + if [[ ${EAPI:-0} != [0123456] ]]; then + eerror "EPYTHON is unset while calling escons. This most likely means that" + eerror "the ebuild did not call the appropriate eclass function before calling scons." + if [[ ${_PYTHON_ANY_R1} ]]; then + eerror "Please ensure that python-any-r1_pkg_setup is called in pkg_setup()." + elif [[ ${_PYTHON_SINGLE_R1} ]]; then + eerror "Please ensure that python-single-r1_pkg_setup is called in pkg_setup()." + else # python-r1 + eerror "Please ensure that python_setup is called before escons, or that escons" + eerror "is used within python_foreach_impl as appropriate." + fi + die "EPYTHON unset in escons" + else + local -x EPYTHON=python2.7 + fi + fi + # Use myesconsargs in EAPI 5 and older if [[ ${EAPI} == [012345] ]]; then set -- "${myesconsargs[@]}" "${@}" -- 2.17.0