This will deal with cases where the shebang is defined using ${PYTHON}
or the location of python in the PATH.

Signed-off-by: James Le Cuirot <ch...@gentoo.org>
---
 eclass/python-utils-r1.eclass | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 607af1b52f75..19cfaf2798ab 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -989,7 +989,8 @@ python_doheader() {
 # @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. <path> defaults to ${T}/${EPYTHON}.
+# and PKG_CONFIG_PATH appropriately. <path> defaults to
+# ${T}/python-wrappers/${EPYTHON}${SYSROOT:+-sysroot}.
 #
 # The wrappers will be created for implementation named by <impl>,
 # or for one named by ${EPYTHON} if no <impl> passed.
@@ -1010,7 +1011,7 @@ python_wrapper_setup() {
 
        # Use separate directories for SYSROOT in case we need to execute
        # Python in the context of the build host by unsetting SYSROOT.
-       local workdir=${3:-${T}/${impl}${SYSROOT:+-sysroot}}
+       local workdir=${3:-${T}/python-wrappers/${impl}${SYSROOT:+-sysroot}}
 
        [[ ${workdir} ]] || die "${FUNCNAME}: no workdir specified."
        [[ ${impl} ]] || die "${FUNCNAME}: no impl nor EPYTHON specified."
@@ -1243,8 +1244,25 @@ python_fix_shebang() {
                                # Match left-to-right in a loop, to avoid 
matching random
                                # repetitions like 'python2.7 python2'.
                                for i in $(seq 0 $((${#split_shebang[@]} - 
1))); do
+                                       # Fix the leading path if it points to 
a wrapper
+                                       # script created by this eclass or 
points to
+                                       # ${BROOT} rather than ${EPREFIX}. We 
generally only
+                                       # touch the tail end of the string as 
this is safer
+                                       # but if a path starts with ${T} or 
${BROOT}, where
+                                       # the latter differs from ${EPREFIX}, 
then it
+                                       # definitely needs fixing. We preserve 
the tail for
+                                       # further processing in the case block 
below.
+                                       if [[ ${split_shebang[${i}]} == 
${T}/python-wrappers/*/bin/* || ( ${split_shebang[${i}]} == ${BROOT}/usr/bin/* 
&& ${BROOT} != ${EPREFIX} ) ]]; then
+                                               
split_shebang[${i}]=${EPREFIX}/usr/bin/${split_shebang[${i}]##*/}
+                                               fix=1
+                                       fi
+
                                        case "/${split_shebang[${i}]}" in
                                                */${EPYTHON})
+                                                       # EPYTHON matched but 
the leading path may
+                                                       # still need fixing.
+                                                       [[ ${fix} ]] && break
+
                                                        debug-print 
"${FUNCNAME}: in file ${f#${D%/}}"
                                                        debug-print 
"${FUNCNAME}: shebang matches EPYTHON: ${shebang}"
 
-- 
2.19.2


Reply via email to