public inbox for gentoo-python@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-python@lists.gentoo.org
Cc: python@gentoo.org, maksbotan@gentoo.org, sterkrig@myopera.com,
	"Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-python] [PATCH 3/3] Support requesting single implementation only (python-single-r1).
Date: Sun, 20 Jan 2013 11:18:14 +0100	[thread overview]
Message-ID: <1358677094-20652-3-git-send-email-mgorny@gentoo.org> (raw)
In-Reply-To: <1358677094-20652-1-git-send-email-mgorny@gentoo.org>

---
 gx86/eclass/distutils-r1.eclass | 98 ++++++++++++++++++++++++++++++++---------
 1 file changed, 76 insertions(+), 22 deletions(-)

diff --git a/gx86/eclass/distutils-r1.eclass b/gx86/eclass/distutils-r1.eclass
index 71c2e67..7c6ace4 100644
--- a/gx86/eclass/distutils-r1.eclass
+++ b/gx86/eclass/distutils-r1.eclass
@@ -66,9 +66,26 @@ esac
 # distutils-r1 default phase functions or call the build system
 # manually.
 
+# @ECLASS-VARIABLE: DISTUTILS_SINGLE_IMPL
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If set to a non-null value, the ebuild will support setting a single
+# Python implementation only. It will effectively replace the python-r1
+# eclass inherit with python-single-r1.
+#
+# Note that inheriting python-single-r1 will cause pkg_setup()
+# to be exported. It must be run in order for the eclass functions
+# to function properly.
+
 if [[ ! ${_DISTUTILS_R1} ]]; then
 
-inherit eutils multiprocessing python-r1
+inherit eutils
+
+if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
+	inherit multiprocessing python-r1
+else
+	inherit python-single-r1
+fi
 
 fi
 
@@ -237,7 +254,8 @@ distutils-r1_python_prepare_all() {
 		fi
 	fi
 
-	if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
+	if [[ ${DISTUTILS_IN_SOURCE_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
+	then
 		# create source copies for each implementation
 		python_copy_sources
 	fi
@@ -345,11 +363,14 @@ distutils-r1_python_install() {
 	addpredict /usr/lib/portage/pym
 
 	local root=${D}/_${EPYTHON}
+	[[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D}
 
 	esetup.py install "${flags[@]}" --root="${root}" "${@}"
-	_distutils-r1_rename_scripts "${root}"
 
-	_distutils-r1_merge_root "${root}" "${D}"
+	if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
+		_distutils-r1_rename_scripts "${root}"
+		_distutils-r1_merge_root "${root}" "${D}"
+	fi
 }
 
 # @FUNCTION: distutils-r1_merge_root
@@ -431,7 +452,9 @@ distutils-r1_run_phase() {
 	debug-print-function ${FUNCNAME} "${@}"
 
 	if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
-		pushd "${BUILD_DIR}" &>/dev/null || die
+		if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
+			pushd "${BUILD_DIR}" &>/dev/null || die
+		fi
 	else
 		local PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
 		export PYTHONPATH
@@ -441,7 +464,8 @@ distutils-r1_run_phase() {
 
 	mkdir -p "${TMPDIR}" || die
 
-	if [[ ${DISTUTILS_NO_PARALLEL_BUILD} ]]; then
+	if [[ ${DISTUTILS_NO_PARALLEL_BUILD} || ${DISTUTILS_SINGLE_IMPL} ]]
+	then
 		"${@}" 2>&1 | tee -a "${T}/build-${EPYTHON}.log"
 	else
 		(
@@ -451,7 +475,8 @@ distutils-r1_run_phase() {
 		multijob_post_fork
 	fi
 
-	if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
+	if [[ ${DISTUTILS_IN_SOURCE_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
+	then
 		popd &>/dev/null || die
 	fi
 
@@ -487,14 +512,17 @@ _distutils-r1_run_common_phase() {
 _distutils-r1_multijob_init() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	local opts
-	if [[ ${DISTUTILS_JOBS} ]]; then
-		opts=-j${DISTUTILS_JOBS}
-	else
-		opts=${MAKEOPTS}
-	fi
+	if [[ ! ${DISTUTILS_NO_PARALLEL_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
+	then
+		local opts
+		if [[ ${DISTUTILS_JOBS} ]]; then
+			opts=-j${DISTUTILS_JOBS}
+		else
+			opts=${MAKEOPTS}
+		fi
 
-	multijob_init "${opts}"
+		multijob_init "${opts}"
+	fi
 }
 
 # @FUNCTION: _distutils-r1_multijob_finish
@@ -504,7 +532,33 @@ _distutils-r1_multijob_init() {
 _distutils-r1_multijob_finish() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	multijob_finish
+	if [[ ! ${DISTUTILS_NO_PARALLEL_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
+	then
+		multijob_finish
+	fi
+}
+
+# @FUNCTION: _distutils-r1_run_foreach_impl
+# @INTERNAL
+# @DESCRIPTION:
+# Run the given phase for each implementation if multiple implementations
+# are enabled, once otherwise.
+_distutils-r1_run_foreach_impl() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	set -- distutils-r1_run_phase "${@}"
+
+	if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
+		python_foreach_impl "${@}"
+	else
+		if [[ ! ${EPYTHON} ]]; then
+			die "EPYTHON unset, python-single-r1_pkg_setup not called?!"
+		fi
+		local BUILD_DIR=${BUILD_DIR:-${S}}
+		BUILD_DIR=${BUILD_DIR%%/}_${EPYTHON}
+
+		"${@}"
+	fi
 }
 
 distutils-r1_src_prepare() {
@@ -519,7 +573,7 @@ distutils-r1_src_prepare() {
 
 	_distutils-r1_multijob_init
 	if declare -f python_prepare >/dev/null; then
-		python_foreach_impl distutils-r1_run_phase python_prepare
+		_distutils-r1_run_foreach_impl python_prepare
 	fi
 	_distutils-r1_multijob_finish
 }
@@ -527,7 +581,7 @@ distutils-r1_src_prepare() {
 distutils-r1_src_configure() {
 	_distutils-r1_multijob_init
 	if declare -f python_configure >/dev/null; then
-		python_foreach_impl distutils-r1_run_phase python_configure
+		_distutils-r1_run_foreach_impl python_configure
 	fi
 	_distutils-r1_multijob_finish
 
@@ -541,9 +595,9 @@ distutils-r1_src_compile() {
 
 	_distutils-r1_multijob_init
 	if declare -f python_compile >/dev/null; then
-		python_foreach_impl distutils-r1_run_phase python_compile
+		_distutils-r1_run_foreach_impl python_compile
 	else
-		python_foreach_impl distutils-r1_run_phase distutils-r1_python_compile
+		_distutils-r1_run_foreach_impl distutils-r1_python_compile
 	fi
 	_distutils-r1_multijob_finish
 
@@ -557,7 +611,7 @@ distutils-r1_src_test() {
 
 	_distutils-r1_multijob_init
 	if declare -f python_test >/dev/null; then
-		python_foreach_impl distutils-r1_run_phase python_test
+		_distutils-r1_run_foreach_impl python_test
 	fi
 	_distutils-r1_multijob_finish
 
@@ -571,9 +625,9 @@ distutils-r1_src_install() {
 
 	_distutils-r1_multijob_init
 	if declare -f python_install >/dev/null; then
-		python_foreach_impl distutils-r1_run_phase python_install
+		_distutils-r1_run_foreach_impl python_install
 	else
-		python_foreach_impl distutils-r1_run_phase distutils-r1_python_install
+		_distutils-r1_run_foreach_impl distutils-r1_python_install
 	fi
 	_distutils-r1_multijob_finish
 
-- 
1.8.1.1



  parent reply	other threads:[~2013-01-20 10:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-20 10:18 [gentoo-python] [PATCH 1/3] Support making distutils-r1 deps and phases optional Michał Górny
2013-01-20 10:18 ` [gentoo-python] [PATCH 2/3] Wrap multijob_finish in a private function as well Michał Górny
2013-01-20 10:18 ` Michał Górny [this message]
2013-01-20 18:30   ` [gentoo-python] Re: [PATCH 3/3] Support requesting single implementation only (python-single-r1) Mike Gilbert
2013-01-20 18:39     ` Michał Górny
2013-01-20 18:47       ` Mike Gilbert
2013-01-20 18:19 ` [gentoo-python] Re: [PATCH 1/3] Support making distutils-r1 deps and phases optional Mike Gilbert
2013-01-21  6:17 ` Nikolaj Sjujskij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1358677094-20652-3-git-send-email-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-python@lists.gentoo.org \
    --cc=maksbotan@gentoo.org \
    --cc=python@gentoo.org \
    --cc=sterkrig@myopera.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox