From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-python@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-python] [PATCH] Create a temporary links for Python execs and pkg-config.
Date: Fri, 29 Mar 2013 23:39:30 +0100 [thread overview]
Message-ID: <1364596770-17336-1-git-send-email-mgorny@gentoo.org> (raw)
In-Reply-To: <20130329233803.2ba9f24b@pomiocik.lan>
With this patch, all apps which call 'python', 'python2', 'python3',
'2to3', 'python-config' or 'pkg-config ... python' start to work
properly without any kind of wrapper.
The wrappers are set up in python_foreach_impl, python_export_best
and pkg_setup phases of python-any-r1 and python-single-r1.
python_foreach_impl uses ${T}/${EPYTHON} subdirs for the wrappers.
The remaining functions set them 'globally' in ${T}.
---
gx86/eclass/python-any-r1.eclass | 5 +-
gx86/eclass/python-r1.eclass | 3 ++
gx86/eclass/python-single-r1.eclass | 1 +
gx86/eclass/python-utils-r1.eclass | 94 +++++++++++++++++++++++++++++++++++++
4 files changed, 102 insertions(+), 1 deletion(-)
diff --git a/gx86/eclass/python-any-r1.eclass b/gx86/eclass/python-any-r1.eclass
index 5d9a3d1..4761221 100644
--- a/gx86/eclass/python-any-r1.eclass
+++ b/gx86/eclass/python-any-r1.eclass
@@ -205,7 +205,10 @@ python-any-r1_pkg_setup() {
local PYTHON_PKG_DEP
for i in "${rev_impls[@]}"; do
python_export "${i}" PYTHON_PKG_DEP EPYTHON PYTHON
- ROOT=/ has_version "${PYTHON_PKG_DEP}" && return
+ if ROOT=/ has_version "${PYTHON_PKG_DEP}"; then
+ python_wrapper_setup "${T}"
+ return
+ fi
done
}
diff --git a/gx86/eclass/python-r1.eclass b/gx86/eclass/python-r1.eclass
index 4ba80a9..a3fdd0e 100644
--- a/gx86/eclass/python-r1.eclass
+++ b/gx86/eclass/python-r1.eclass
@@ -634,7 +634,9 @@ _python_multibuild_wrapper() {
debug-print-function ${FUNCNAME} "${@}"
local -x EPYTHON PYTHON
+ local -x PATH=${PATH} PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
python_export "${MULTIBUILD_VARIANT}" EPYTHON PYTHON
+ python_wrapper_setup "${T}/${EPYTHON}"
"${@}"
}
@@ -707,6 +709,7 @@ python_export_best() {
debug-print "${FUNCNAME}: Best implementation is: ${best}"
python_export "${best}" "${@}"
+ python_wrapper_setup "${T}"
}
# @FUNCTION: python_replicate_script
diff --git a/gx86/eclass/python-single-r1.eclass b/gx86/eclass/python-single-r1.eclass
index 6235b66..950bf52 100644
--- a/gx86/eclass/python-single-r1.eclass
+++ b/gx86/eclass/python-single-r1.eclass
@@ -207,6 +207,7 @@ python-single-r1_pkg_setup() {
fi
python_export "${impl}" EPYTHON PYTHON
+ python_wrapper_setup "${T}"
fi
done
diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass
index a375546..6aa4a64 100644
--- a/gx86/eclass/python-utils-r1.eclass
+++ b/gx86/eclass/python-utils-r1.eclass
@@ -818,5 +818,99 @@ python_doheader() {
doins -r "${@}" || die
}
+# @FUNCTION: python_wrapper_setup
+# @USAGE: <path> [<impl>]
+# @DESCRIPTION:
+# Create proper 'python' executable and pkg-config wrappers
+# (if available) in the directory named by <path>. Set up PATH
+# and PKG_CONFIG_PATH appropriately.
+#
+# The wrappers will be created for implementation named by <impl>,
+# or for one named by ${EPYTHON} if no <impl> passed.
+#
+# If the named directory contains a python symlink already, it will
+# be assumed to contain proper wrappers already and only environment
+# setup will be done. If wrapper update is requested, the directory
+# shall be removed first.
+python_wrapper_setup() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local workdir=${1}
+ local impl=${2:-${EPYTHON}}
+
+ [[ ${workdir} ]] || die "${FUNCNAME}: no workdir specified."
+ [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON specified."
+
+ if [[ ! -x ${workdir}/bin/python ]]; then
+ mkdir -p "${workdir}"/{bin,pkgconfig} || die
+
+ # Clean up, in case we were supposed to do a cheap update.
+ rm -f "${workdir}"/bin/python{,2,3,-config}
+ rm -f "${workdir}"/bin/2to3
+ rm -f "${workdir}"/pkgconfig/python{,2,3}.pc
+
+ local EPYTHON PYTHON
+ python_export "${impl}" EPYTHON PYTHON
+
+ local pyver
+ if [[ ${EPYTHON} == python3* ]]; then
+ pyver=3
+ else # includes pypy & jython
+ pyver=2
+ fi
+
+ # Python interpreter
+ ln -s "${PYTHON}" "${workdir}"/bin/python || die
+ ln -s python "${workdir}"/bin/python${pyver} || die
+
+ local nonsupp=()
+
+ # CPython-specific
+ if [[ ${EPYTHON} == python* ]]; then
+ ln -s "${PYTHON}-config" "${workdir}"/bin/python-config || die
+
+ # Python 2.6+.
+ if [[ ${EPYTHON} != python2.5 ]]; then
+ ln -s "${PYTHON/python/2to3-}" "${workdir}"/bin/2to3 || die
+ else
+ nonsupp+=( 2to3 )
+ fi
+
+ # Python 2.7+.
+ if [[ ${EPYTHON} != python2.[56] ]]; then
+ ln -s "${EPREFIX}"/usr/$(get_libdir)/pkgconfig/${EPYTHON/n/n-}.pc \
+ "${workdir}"/pkgconfig/python.pc || die
+ else
+ # XXX?
+ ln -s /dev/null "${workdir}"/pkgconfig/python.pc || die
+ fi
+ ln -s python.pc "${workdir}"/pkgconfig/python${pyver}.pc || die
+ else
+ nonsupp+=( 2to3 python-config )
+ fi
+
+ local x
+ for x in "${nonsupp[@]}"; do
+ echo >"${workdir}"/bin/${x} <<__EOF__ || die
+#!/bin/sh
+echo "${x} is not supported by ${EPYTHON}" >&2
+exit 1
+__EOF__
+ chmod +x "${workdir}"/bin/${x} || die
+ done
+
+ # Now, set the environment.
+ # But note that ${workdir} may be shared with something else,
+ # and thus already on top of PATH.
+ if [[ ${PATH##:*} != ${workdir}/bin ]]; then
+ PATH=${workdir}/bin${PATH:+:${PATH}}
+ fi
+ if [[ ${PKG_CONFIG_PATH##:*} != ${workdir}/pkgconfig ]]; then
+ PKG_CONFIG_PATH=${workdir}/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
+ fi
+ export PATH PKG_CONFIG_PATH
+ fi
+}
+
_PYTHON_UTILS_R1=1
fi
--
1.8.1.5
next prev parent reply other threads:[~2013-03-29 22:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-29 19:57 [gentoo-python] Alternate solution for 'python', 'python2' and 'pkg-config python' in ebuilds Michał Górny
2013-03-29 22:38 ` Michał Górny
2013-03-29 22:39 ` Michał Górny [this message]
2013-04-03 0:45 ` [gentoo-python] [PATCH] Create a temporary links for Python execs and pkg-config Mike Gilbert
2013-04-07 18:18 ` Michał Górny
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=1364596770-17336-1-git-send-email-mgorny@gentoo.org \
--to=mgorny@gentoo.org \
--cc=gentoo-python@lists.gentoo.org \
/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