Python: improve cross-compilation

This changeset allows for cross-compilation of Python packages. Packages
built with buildPythonPackage are not allowed to refer to the build
machine. Executables that have shebangs will refer to the host.
This commit is contained in:
Frederik Rietdijk
2019-01-02 20:09:44 +01:00
parent 613498af97
commit f665828fa3
14 changed files with 68 additions and 41 deletions

View File

@@ -16,8 +16,8 @@ buildPythonPath() {
declare -A pythonPathsSeen=()
program_PYTHONPATH=
program_PATH=
pythonPathsSeen["@python@"]=1
addToSearchPath program_PATH @python@/bin
pythonPathsSeen["@pythonHost@"]=1
addToSearchPath program_PATH @pythonHost@/bin
for path in $pythonPath; do
_addToPythonPath $path
done
@@ -53,7 +53,13 @@ wrapPythonProgramsIn() {
# Strip suffix, like "3" or "2.7m" -- we don't have any choice on which
# Python to use besides one with this hook anyway.
if head -n1 "$f" | grep -q '#!.*/env.*\(python\|pypy\)'; then
sed -i "$f" -e "1 s^.*/env[ ]*\(python\|pypy\)[^ ]*^#! @executable@^"
sed -i "$f" -e "1 s^.*/env[ ]*\(python\|pypy\)[^ ]*^#!@executable@^"
fi
if head -n1 "$f" | grep -q '#!.*'; then
# Cross-compilation hack: ensure shebangs are for the host
echo "Rewriting $(head -n 1 $f) to #!@pythonHost@"
sed -i "$f" -e "1 s^#!@python@^#!@pythonHost@^"
fi
# catch /python and /.python-wrapped