diff options
author | Dirkjan Ochtman <djc@gentoo.org> | 2011-10-07 10:48:24 +0000 |
---|---|---|
committer | Dirkjan Ochtman <djc@gentoo.org> | 2011-10-07 10:48:24 +0000 |
commit | 0b9237de9e73fb27826bd7dbb8241c7bfd4dce86 (patch) | |
tree | 04936f56035b7fb2a3dbf25897541f35cff4f257 /eclass | |
parent | Fix ChangeLog entry (diff) | |
download | gentoo-2-0b9237de9e73fb27826bd7dbb8241c7bfd4dce86.tar.gz gentoo-2-0b9237de9e73fb27826bd7dbb8241c7bfd4dce86.tar.bz2 gentoo-2-0b9237de9e73fb27826bd7dbb8241c7bfd4dce86.zip |
Respect options from shebangs of target scripts in wrapper scripts generated
by python_generate_wrapper_scripts(). (Patch by Arfrever.)
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/python.eclass | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/eclass/python.eclass b/eclass/python.eclass index 0ca021fbd345..ee5c175a60d0 100644 --- a/eclass/python.eclass +++ b/eclass/python.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.132 2011/09/10 13:48:46 djc Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.133 2011/10/07 10:48:24 djc Exp $ # @ECLASS: python.eclass # @MAINTAINER: @@ -1236,7 +1236,8 @@ import sys cpython_re = re.compile(r"^python(\d+\.\d+)$") jython_re = re.compile(r"^jython(\d+\.\d+)$") pypy_re = re.compile(r"^pypy-c(\d+\.\d+)$") -python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") +cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)") +python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)") python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") pypy_versions_mapping = { @@ -1340,14 +1341,19 @@ EOF target_executable = open(target_executable_path, "rb") target_executable_first_line = target_executable.readline() +target_executable.close() if not isinstance(target_executable_first_line, str): # Python 3 target_executable_first_line = target_executable_first_line.decode("utf_8", "replace") -python_shebang_matched = python_shebang_re.match(target_executable_first_line) -target_executable.close() +options = [] +python_shebang_options_matched = python_shebang_options_re.match(target_executable_first_line) +if python_shebang_options_matched is not None: + options = [python_shebang_options_matched.group(1)] + +cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line) -if python_shebang_matched is not None: +if cpython_shebang_matched is not None: try: python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" @@ -1370,9 +1376,9 @@ if python_shebang_matched is not None: os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path if hasattr(os, "execv"): - os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv) + os.execv(python_interpreter_path, [python_interpreter_path] + options + sys.argv) else: - sys.exit(subprocess.Popen([python_interpreter_path] + sys.argv).wait()) + sys.exit(subprocess.Popen([python_interpreter_path] + options + sys.argv).wait()) except (KeyboardInterrupt, SystemExit): raise except: |