python3: error on host python path too long
authorDaniel F. Dickinson <redacted>
Sun, 11 Jan 2026 06:46:02 +0000 (01:46 -0500)
committerAlexandru Ardelean <redacted>
Mon, 26 Jan 2026 07:16:08 +0000 (09:16 +0200)
Error if shebang to host python interpreter would exceed 127 characters
(124 characters plus shebang and newline). This is used to alert user
when python-installer would fail to correctly set a Python program's
shebang line.

Closes: https://github.com/openwrt/packages/issues/28310
Signed-off-by: Daniel F. Dickinson <redacted>
lang/python/python3-package.mk

index 3300f1beabe39c2c5651b100896c7f8c4369e108..819b6bf64aa309b39a78bf64c430f0b29d760559 100644 (file)
@@ -22,6 +22,23 @@ PYTHON3PATH:=$(PYTHON3_LIB_DIR):$(STAGING_DIR)/$(PYTHON3_PKG_DIR):$(PKG_INSTALL_
 
 -include $(PYTHON3_LIB_DIR)/openwrt/Makefile-vars
 
+# Error if shebang to host python interpreter would exceed 127 characters
+# (124 characters plus shebang and newline)
+# This is used to alert user when python-installer would fail to correctly
+# set a Python program's shebang line.
+# See https://github.com/openwrt/packages/issues/28310
+PYTHON3_PKG_HOST_BIN_MAX_PATH_LEN:=124
+
+define CheckHostPythonShebang
+       set -e; \
+       HOST_PYTHON3_BIN="$(HOST_PYTHON3_BIN)"; \
+       if \
+               [ $$$${#HOST_PYTHON3_BIN} -gt $(PYTHON3_PKG_HOST_BIN_MAX_PATH_LEN) ]; then \
+               echo >&2 "Path to host python too long; python program install would fail";\
+               exit 1; \
+       fi
+endef
+
 # These configure args are needed in detection of path to Python header files
 # using autotools.
 CONFIGURE_ARGS += \
@@ -264,6 +281,7 @@ define Py3Build/Compile/Default
 endef
 
 define Py3Build/Install/Default
+       $(call CheckHostPythonShebang)
        $(call Python3/Run, \
                $(PKG_BUILD_DIR), \
                -m installer \
git clone https://git.99rst.org/PROJECT