diff mbox series

[3/5] package/python: install wrapper in HOST_BIN_CROSS

Message ID 20200204142456.1537358-4-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. 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.

sysconfigdata is not needed for python2 because it is not "multilib":
there is only a target sysonfigdata module in STAGING_DIR.

Since the installation hook uses PYTHON_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/python/python-wrapper.in | 10 ++++++++++
 package/python/python.mk         | 17 ++++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)
 create mode 100644 package/python/python-wrapper.in
diff mbox series


diff --git a/package/python/python-wrapper.in b/package/python/python-wrapper.in
new file mode 100644
index 0000000000..c5e6e5481b
--- /dev/null
+++ b/package/python/python-wrapper.in
@@ -0,0 +1,10 @@ 
+#! /bin/sh
+STAGING_DIR=$(cd "${0%/*}/../sysroot"; pwd)
+_python_sysroot="$STAGING_DIR" \
+_python_prefix=/usr \
+_python_exec_prefix=/usr \
+exec "${0%/*}/../../bin/python" "$@"
diff --git a/package/python/python.mk b/package/python/python.mk
index 41a981e3d3..6f2e01386e 100644
--- a/package/python/python.mk
+++ b/package/python/python.mk
+# Provided to other packages
+PYTHON_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/
+	mkdir -p $(HOST_BIN_CROSS)
+	sed 's%@PYTHON_PATH@%$(PYTHON_PATH)%' \
+		package/python/python-wrapper.in \
+		> $(HOST_BIN_CROSS)/python
+	chmod 0755 $(HOST_BIN_CROSS)/python
+	ln -sf python $(HOST_BIN_CROSS)/python2
 # Some packages may have build scripts requiring python2.
 # Only install the python symlink in the host tree if python3 is not enabled
 # for the target, otherwise the default python program may be missing.
@@ -239,9 +253,6 @@  endef
-# Provided to other packages
-PYTHON_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/
 $(eval $(autotools-package))
 $(eval $(host-autotools-package))