python,python3: add Py[3]Shebang functions & move outside of script
authorAlexandru Ardelean <redacted>
Thu, 12 Sep 2019 12:03:50 +0000 (15:03 +0300)
committerAlexandru Ardelean <redacted>
Fri, 20 Sep 2019 11:10:00 +0000 (14:10 +0300)
Some packages just install some Python binaries, that may need their
shebang fixed.
This change adds some utilities to help with that and try to centralize the
sed rules a bit.

It also removes the logic from the `python-package-install.sh` into the
`python-package[3].mk` files. This does 2 things:
1. It minimizes the need for the shell script to know the Python
   version 2/3
2. Makes the logic re-usable in packages; especially if the install rules
   differ a bit

Signed-off-by: Alexandru Ardelean <redacted>
lang/python/python-package-install.sh
lang/python/python-package.mk
lang/python/python3-package.mk

index f2646f8487ef0d0a481823ac4ec1267e53892091..337727af1f9294389067bf4582a477fc5d53d588 100644 (file)
@@ -54,8 +54,6 @@ python="$4"
 mode="$5"
 filespec="$6"
 
-SED="${SED:-sed -e}"
-
 find "$src_dir" -name "*.exe" -delete
 
 process_filespec "$src_dir" "$dst_dir" "$filespec" || {
@@ -63,12 +61,6 @@ process_filespec "$src_dir" "$dst_dir" "$filespec" || {
        exit 1
 }
 
-usr_bin_dir="$dst_dir/usr/bin"
-
-if [ -d "$usr_bin_dir" ] ; then
-       $SED "1"'!'"b;s,^#"'!'".*python.*,#"'!'"/usr/bin/python${ver}," -i --follow-symlinks $usr_bin_dir/*
-fi
-
 if [ "$mode" == "sources" ] ; then
        # Copy only python source files
        find "$dst_dir" -not -type d -not -name "*.py" -delete
index 9bd0b9aa4baf1d86412d0f72aabe2148e64e90be..019f4f028880b103d8d64532e45a030f285b6a6c 100644 (file)
@@ -35,6 +35,10 @@ ifdef CONFIG_USE_MIPS16
   TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
 endif
 
+define PyShebang
+$(SED) "1"'!'"b;s,^#"'!'".*python.*,#"'!'"/usr/bin/python2," -i --follow-symlinks $(1)
+endef
+
 define PyPackage
 
   define Package/$(1)-src
@@ -74,11 +78,13 @@ define PyPackage
 
   define Package/$(1)/install
        $$(call PyPackage/$(1)/install,$$(1))
-       SED="$(SED)" \
        $(SHELL) $(python_mk_path)python-package-install.sh "2" \
                "$(PKG_INSTALL_DIR)" "$$(1)" \
                "$(HOST_PYTHON_BIN)" "$$(2)" \
-               "$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)"
+               "$$$$$$$$$$(call shvar,PyPackage/$(1)/filespec)" && \
+       if [ -d "$$(1)/usr/bin" ]; then \
+               $(call PyShebang,$$(1)/usr/bin/*) ; \
+       fi
   endef
 
   define Package/$(1)-src/install
index e14290081c6ef1767dc3a9846e7cd0ca6fa3cfa2..d20d19801a0497d13209c329ba197c78d3d50095 100644 (file)
@@ -34,6 +34,10 @@ ifdef CONFIG_USE_MIPS16
   TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
 endif
 
+define Py3Shebang
+$(SED) "1"'!'"b;s,^#"'!'".*python.*,#"'!'"/usr/bin/python3," -i --follow-symlinks $(1)
+endef
+
 define Py3Package
 
   define Package/$(1)-src
@@ -73,12 +77,14 @@ define Py3Package
 
   define Package/$(1)/install
        $$(call Py3Package/$(1)/install,$$(1))
-       SED="$(SED)" \
        $(SHELL) $(python3_mk_path)python-package-install.sh "3" \
                "$(PKG_INSTALL_DIR)" "$$(1)" \
                "$(HOST_PYTHON3_BIN)" "$$(2)" \
-               "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)"
-  endef
+               "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" && \
+       if [ -d "$$(1)/usr/bin" ]; then \
+               $(call Py3Shebang,$$(1)/usr/bin/*) ; \
+       fi
+ endef
 
   define Package/$(1)-src/install
        $$(call Package/$(1)/install,$$(1),sources)
git clone https://git.99rst.org/PROJECT