Patchwork [v4,1/2] dependencies: build a host python2 if no suitable one can be found

login
register
mail settings
Submitter Samuel Martin
Date July 16, 2012, 9:38 p.m.
Message ID <1342474686-10167-1-git-send-email-s.martin49@gmail.com>
Download mbox | patch
Permalink /patch/171269/
State Rejected
Headers show

Comments

Samuel Martin - July 16, 2012, 9:38 p.m.
Some distros choose to change the /usr/bin/python binary, making it pointed
to python3 instead of python2.

This may have some bad consequences for packages that uses some
non-python3-compliant python scripts in their build system (eg. in install
or post-install scripts).

This patch checks for a suitable python2 version (2.6 or 2.7) on the host
system, and declares the following variables:
- PYTHON2: pointing to the host python2 binary;
- NEED_PYTHON2: sets to "host-python" if no python2 binary has been found.

This way, a package using some python2 scripts must:
- adds $(NEED_PYTHON2) to its dependency list;
- sets $(PYTHON2) as the python binary to be used.

A side effect of this patch is getting rid of any host python. Buildroot
can runs on a host without python, or with a too old python2 version, or
with only python3; in such case, $(NEED_PYTHON2) should be added to the
dependency list. So, we can get rid of the python dependency check.

Signed-off-by: Samuel Martin <s.martin49@gmail.com>

---

Changelog:

Changes since v3:
- minor fix

Changes since v2:
- misc. fixes and cleanup

Changes since v1:
- use support/dependency infrastructure
- rename some symbols


 create mode 100644 support/dependencies/check-host-python2.mk
 create mode 100755 support/dependencies/check-host-python2.sh
Samuel Martin - Oct. 21, 2012, 9:04 p.m.
Hi all,

Reviving an old thread...

2012/7/16 Samuel Martin <s.martin49@gmail.com>:
> Some distros choose to change the /usr/bin/python binary, making it pointed
> to python3 instead of python2.
>
> This may have some bad consequences for packages that uses some
> non-python3-compliant python scripts in their build system (eg. in install
> or post-install scripts).
>
> This patch checks for a suitable python2 version (2.6 or 2.7) on the host
> system, and declares the following variables:
> - PYTHON2: pointing to the host python2 binary;
> - NEED_PYTHON2: sets to "host-python" if no python2 binary has been found.
>
> This way, a package using some python2 scripts must:
> - adds $(NEED_PYTHON2) to its dependency list;
> - sets $(PYTHON2) as the python binary to be used.
>
> A side effect of this patch is getting rid of any host python. Buildroot
> can runs on a host without python, or with a too old python2 version, or
> with only python3; in such case, $(NEED_PYTHON2) should be added to the
> dependency list. So, we can get rid of the python dependency check.
>

Just to let you know that this patch may also fix some issues with
scons, which does not seem to support python3 yet.
Any comment about this?


Regards,

Patch

diff --git a/support/dependencies/check-host-python2.mk b/support/dependencies/check-host-python2.mk
new file mode 100644
index 0000000..ddae701
--- /dev/null
+++ b/support/dependencies/check-host-python2.mk
@@ -0,0 +1,6 @@ 
+PYTHON2 = $(call suitable-host-package,python2)
+
+ifeq ($(PYTHON2),)
+  NEED_PYTHON2 = host-python
+  PYTHON2 = $(HOST_DIR)/usr/bin/python
+endif
diff --git a/support/dependencies/check-host-python2.sh b/support/dependencies/check-host-python2.sh
new file mode 100755
index 0000000..6ad4b3a
--- /dev/null
+++ b/support/dependencies/check-host-python2.sh
@@ -0,0 +1,13 @@ 
+#!/bin/sh
+
+candidates="python python2"
+
+for candidate in ${candidates} ; do
+  which ${candidate} &>/dev/null || continue
+  # restrict version of python2 to 2.6 or 2.7
+  if ${candidate} --version 2>&1 | grep -q 'Python 2\.[6-7].*' ; then
+    # found a valid candidate, so quit now
+    echo $(which ${candidate})
+    exit
+  fi
+done
diff --git a/support/dependencies/dependencies.sh b/support/dependencies/dependencies.sh
index 9f0f6a9..ec175f5 100755
--- a/support/dependencies/dependencies.sh
+++ b/support/dependencies/dependencies.sh
@@ -131,7 +131,7 @@  if ! $SHELL --version 2>&1 | grep -q '^GNU bash'; then
 fi;
 
 # Check that a few mandatory programs are installed
-for prog in awk bison flex msgfmt makeinfo patch gzip bzip2 perl tar wget cpio python unzip rsync ${DL_TOOLS} ; do
+for prog in awk bison flex msgfmt makeinfo patch gzip bzip2 perl tar wget cpio unzip rsync ${DL_TOOLS} ; do
     if ! which $prog > /dev/null ; then
 	/bin/echo -e "\nYou must install '$prog' on your build machine";
 	if test $prog = "makeinfo" ; then