diff mbox series

[2/5] package/python3: install wrapper in HOST_BIN_CROSS

Message ID 20200204142456.1537358-3-arnout@mind.be
State New
Headers show
Series Introduce cross-bin directory | expand

Commit Message

Arnout Vandecappelle Feb. 4, 2020, 2:24 p.m. UTC
When building python packages, we set some environment variables to make
sure python picks up the correct configuration even though we're running
host-python intead of target-python.

Create a wrapper script that does the same, without requiring an
explicit export from Buildroot. This script is installed in
HOST_BIN_CROSS so that it can be found when cross-compiling.

The script is made auto-discovering as much as possible. Since we know
the script will be installed in $(HOST_DIR)/$(GNU_TARGET_NAME)/bin, we
know that STAGING_DIR is at ../sysroot. sysconfigdata can be calculated
based on that. Since this is specific for python3, we don't need the
python3 condition. Only PYTHONPATH is still passed in explicitly, since
that refers to TARGET_DIR - because most python packages are only
installed in target and not in staging. So until we install everything
in staging as well, we keep an explicit TARGET_DIR.

Since the installation hook uses PYTHON3_PATH, move the definition of
that variable higher in the file so it comes before its first use.

It is not really necessary to have a similar script for native python,
because the only environment variable we need in that case is

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
 package/python3/python-wrapper.in | 24 ++++++++++++++++++++++++
 package/python3/python3.mk        | 17 ++++++++++++++---
 2 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 package/python3/python-wrapper.in
diff mbox series


diff --git a/package/python3/python-wrapper.in b/package/python3/python-wrapper.in
new file mode 100644
index 0000000000..c2f34f32df
--- /dev/null
+++ b/package/python3/python-wrapper.in
@@ -0,0 +1,24 @@ 
+#! /bin/sh
+STAGING_DIR=$(cd "${0%/*}/../sysroot"; pwd)
+for sysconfig in ${STAGING_DIR}/usr/lib/python*/_sysconfigdata__linux_*.py; do
+    if [ -n "$SYSCONFIGDATA" ]; then
+        echo "*** More than one sysconfigdata exists. Buildroot doesn't support mixing targets." 1>&2
+        exit 1
+    fi
+    if [ ! -r "$sysconfig" ]; then
+        echo "*** No sysconfigdata found in $sysconfig." 1>&2
+        exit 1
+    fi
+    SYSCONFIGDATA="$(echo $sysconfig | sed 's%.*/\([^/]*\).py%\1%')"
+_python_sysroot="$STAGING_DIR" \
+_python_prefix=/usr \
+_python_exec_prefix=/usr \
+exec "${0%/*}/../../bin/python3" "$@"
diff --git a/package/python3/python3.mk b/package/python3/python3.mk
index 9432f1c59e..6280b4a550 100644
--- a/package/python3/python3.mk
+++ b/package/python3/python3.mk
@@ -239,6 +239,20 @@  ifneq ($(BR2_PACKAGE_PYTHON),y)
+# Provided to other packages
+	mkdir -p $(HOST_BIN_CROSS)
+	sed 's%@PYTHON_PATH@%$(PYTHON3_PATH)%' \
+		package/python3/python-wrapper.in \
+		> $(HOST_BIN_CROSS)/python
+	chmod 0755 $(HOST_BIN_CROSS)/python
+	ln -sf python $(HOST_BIN_CROSS)/python3
 # Some packages may have build scripts requiring python3, whatever is the
 # python version chosen for the target.
 # Only install the python symlink in the host tree if python3 is enabled
@@ -252,9 +266,6 @@  endef
-# Provided to other packages
 # Support for socket.AF_BLUETOOTH
 PYTHON3_DEPENDENCIES += bluez5_utils-headers