From 421c58a946043fe888903c17dd81d73bd5ff0cca Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Mon, 4 Feb 2019 16:36:25 +0200 Subject: [PATCH 1/2] python,python3: move shebang handle in install script This extends the Python[3] shebang fixup to all packages. Only Python scripts in `/usr/bin` will be handled at the moment. Later it may make sense to also cover executables in `/bin`, though typically Python executables shouldn't be placed there. Previously the shebang handling was only done for python[3]-pip & python[3]-setuptools. Signed-off-by: Alexandru Ardelean --- lang/python/python-package-install.sh | 6 ++++++ lang/python/python/Makefile | 2 +- lang/python/python/files/python-package-pip.mk | 2 -- lang/python/python/files/python-package-setuptools.mk | 2 -- lang/python/python3/Makefile | 2 +- lang/python/python3/files/python3-package-pip.mk | 2 -- lang/python/python3/files/python3-package-setuptools.mk | 2 -- 7 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lang/python/python-package-install.sh b/lang/python/python-package-install.sh index e5f6ec893..f21c00c81 100644 --- a/lang/python/python-package-install.sh +++ b/lang/python/python-package-install.sh @@ -52,6 +52,12 @@ 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 $usr_bin_dir/* +fi + if [ "$mode" == "sources" ] ; then # Copy only python source files find $dst_dir -not -type d -not -name "*\.py" | xargs rm -f diff --git a/lang/python/python/Makefile b/lang/python/python/Makefile index b590e2f12..6e44f5144 100644 --- a/lang/python/python/Makefile +++ b/lang/python/python/Makefile @@ -12,7 +12,7 @@ include ../python-version.mk PKG_NAME:=python PKG_VERSION:=$(PYTHON_VERSION).$(PYTHON_VERSION_MICRO) -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION) diff --git a/lang/python/python/files/python-package-pip.mk b/lang/python/python/files/python-package-pip.mk index b08256464..e0c6de978 100644 --- a/lang/python/python/files/python-package-pip.mk +++ b/lang/python/python/files/python-package-pip.mk @@ -14,8 +14,6 @@ endef define PyPackage/python-pip/install $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib/python$(PYTHON_VERSION)/site-packages - # Adjust shebang to proper python location on target - sed "1s@.*@#\!/usr/bin/python$(PYTHON_VERSION)@" -i $(PKG_BUILD_DIR)/install-pip/bin/* $(CP) $(PKG_BUILD_DIR)/install-pip/bin/* $(1)/usr/bin $(CP) \ $(PKG_BUILD_DIR)/install-pip/lib/python$(PYTHON_VERSION)/site-packages/pip \ diff --git a/lang/python/python/files/python-package-setuptools.mk b/lang/python/python/files/python-package-setuptools.mk index 413ec7979..f90b01864 100644 --- a/lang/python/python/files/python-package-setuptools.mk +++ b/lang/python/python/files/python-package-setuptools.mk @@ -14,8 +14,6 @@ endef define PyPackage/python-setuptools/install $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib/python$(PYTHON_VERSION)/site-packages - # Adjust shebang to proper python location on target - sed "1s@.*@#\!/usr/bin/python$(PYTHON_VERSION)@" -i $(PKG_BUILD_DIR)/install-setuptools/bin/* $(CP) $(PKG_BUILD_DIR)/install-setuptools/bin/* $(1)/usr/bin $(CP) \ $(PKG_BUILD_DIR)/install-setuptools/lib/python$(PYTHON_VERSION)/site-packages/pkg_resources \ diff --git a/lang/python/python3/Makefile b/lang/python/python3/Makefile index 9fbb6923e..25ea949f8 100644 --- a/lang/python/python3/Makefile +++ b/lang/python/python3/Makefile @@ -14,7 +14,7 @@ PYTHON_VERSION:=$(PYTHON3_VERSION) PYTHON_VERSION_MICRO:=$(PYTHON3_VERSION_MICRO) PKG_NAME:=python3 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_VERSION:=$(PYTHON_VERSION).$(PYTHON_VERSION_MICRO) PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz diff --git a/lang/python/python3/files/python3-package-pip.mk b/lang/python/python3/files/python3-package-pip.mk index 1aaeaf2ee..0f8476c18 100644 --- a/lang/python/python3/files/python3-package-pip.mk +++ b/lang/python/python3/files/python3-package-pip.mk @@ -14,8 +14,6 @@ endef define Package/python3-pip/install $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib/python$(PYTHON3_VERSION)/site-packages - # Adjust shebang to proper python location on target - sed "1s@.*@#\!/usr/bin/python$(PYTHON3_VERSION)@" -i $(PKG_BUILD_DIR)/install-pip/bin/* $(CP) $(PKG_BUILD_DIR)/install-pip/bin/pip3* $(1)/usr/bin $(CP) \ $(PKG_BUILD_DIR)/install-pip/lib/python$(PYTHON3_VERSION)/site-packages/pip \ diff --git a/lang/python/python3/files/python3-package-setuptools.mk b/lang/python/python3/files/python3-package-setuptools.mk index c8415cbd9..fa3c2a22b 100644 --- a/lang/python/python3/files/python3-package-setuptools.mk +++ b/lang/python/python3/files/python3-package-setuptools.mk @@ -14,8 +14,6 @@ endef define Py3Package/python3-setuptools/install $(INSTALL_DIR) $(1)/usr/bin $(1)/usr/lib/python$(PYTHON3_VERSION)/site-packages - # Adjust shebang to proper python location on target - sed "1s@.*@#\!/usr/bin/python$(PYTHON3_VERSION)@" -i $(PKG_BUILD_DIR)/install-setuptools/bin/* $(CP) $(PKG_BUILD_DIR)/install-setuptools/bin/easy_install-* $(1)/usr/bin $(LN) easy_install-$(PYTHON3_VERSION) $(1)/usr/bin/easy_install-3 $(CP) \ From af975f0f30b433054d593de2c76a892cc37ea7ad Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Sun, 31 Mar 2019 19:11:15 +0800 Subject: [PATCH 2/2] python,python3: Fix overridden usr/bin symlinks Currently, all files in usr/bin (presumably all Python scripts) are run through sed to replace the shebang; sed will overwrite the file whether or not a match is found. This causes symlinks to be overridden and made into copies of their targets. python[3]-base and python[3]-dev are affected by this. This adds the --follow-symlinks flag to sed, in addition to using $(SED), so that symlinks are not overridden. Signed-off-by: Jeffery To --- lang/python/python-package-install.sh | 4 +++- lang/python/python-package.mk | 1 + lang/python/python3-package.mk | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lang/python/python-package-install.sh b/lang/python/python-package-install.sh index f21c00c81..34ba0721b 100644 --- a/lang/python/python-package-install.sh +++ b/lang/python/python-package-install.sh @@ -47,6 +47,8 @@ python="$4" mode="$5" filespec="$6" +SED="${SED:-sed -e}" + process_filespec "$src_dir" "$dst_dir" "$filespec" || { echo "process filespec error-ed" exit 1 @@ -55,7 +57,7 @@ process_filespec "$src_dir" "$dst_dir" "$filespec" || { usr_bin_dir="$dst_dir/usr/bin" if [ -d "$usr_bin_dir" ] ; then - sed "1"'!'"b;s,^#"'!'".*python.*,#"'!'"/usr/bin/python${ver}," -i $usr_bin_dir/* + $SED "1"'!'"b;s,^#"'!'".*python.*,#"'!'"/usr/bin/python${ver}," -i --follow-symlinks $usr_bin_dir/* fi if [ "$mode" == "sources" ] ; then diff --git a/lang/python/python-package.mk b/lang/python/python-package.mk index 66a492983..855dd4449 100644 --- a/lang/python/python-package.mk +++ b/lang/python/python-package.mk @@ -70,6 +70,7 @@ define PyPackage define Package/$(1)/install $(call PyPackage/$(1)/install,$$(1)) find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f + SED="$(SED)" \ $(SHELL) $(python_mk_path)python-package-install.sh "2" \ "$(PKG_INSTALL_DIR)" "$$(1)" \ "$(HOST_PYTHON_BIN)" "$$(2)" \ diff --git a/lang/python/python3-package.mk b/lang/python/python3-package.mk index 9e473b5c5..5a779c217 100644 --- a/lang/python/python3-package.mk +++ b/lang/python/python3-package.mk @@ -69,6 +69,7 @@ define Py3Package define Package/$(1)/install $(call Py3Package/$(1)/install,$$(1)) find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f + SED="$(SED)" \ $(SHELL) $(python3_mk_path)python-package-install.sh "3" \ "$(PKG_INSTALL_DIR)" "$$(1)" \ "$(HOST_PYTHON3_BIN)" "$$(2)" \