Skip to contentSkip to conversation

Ensure host python is python2

PATCH New Samuel Martin 2 participants 9 messages May 8, 2012 – May 15, 2012

lore
Share & tools
lore
#0 lore raw

cover Ensure host python is python2

This patch series ensures that host python is python2.

This fixes some distro weirdnesses that makes /usr/bin/python pointed to python3 instead of python2, with some bad consequences for some install/post-install python scripts.

Samuel Martin (2):
Makefile.in: add host python2 binary detection
libglib2: fix install even if the host python binary refers to
python3

 package/Makefile.in          |   12 ++++++++++++
 package/libglib2/libglib2.mk |   19 ++++++++++++++++---
 2 files changed, 28 insertions(+), 3 deletions(-)

--
1.7.10.1

#1 lore raw

PATCH 1/2 Makefile.in: add host python2 binary detection

package/Makefile.in +12 -0
index df7042c..84968da 100644
@@ -151,6 +151,18 @@ FLEX:=$(shell which flex || type -p flex)
 BISON:=$(shell which bison || type -p bison)
 SED:=$(shell which sed || type -p sed) -i -e
 
+PYTHON2:=$(shell \
+	which python &>/dev/null && \
+		python --version 2>&1 | grep -qE 'Python 2\.[6-7]*' && \
+		which python || \
+	which python2 &>/dev/null && \
+		python2 --version 2>&1 | grep -qE 'Python 2\.[6-7]*' && \
+		which python2 || \
+	echo $(HOST_DIR)/usr/bin/python)
+HOST_PYTHON2:=$(shell \
+	test $(PYTHON2) != $(HOST_DIR)/usr/bin/python || \
+	echo host-python)
+
 HOST_CFLAGS   ?= -O2
 HOST_CFLAGS   += -I$(HOST_DIR)/include -I$(HOST_DIR)/usr/include
 HOST_CXXFLAGS += -I$(HOST_DIR)/include -I$(HOST_DIR)/usr/include
Signature · 1 line
1.7.10.1
#2 lore raw

PATCH 1/2 Makefile.in: add host python2 binary detection

Quoted 13 lines · Samuel Martin
package/Makefile.in +2 -0
index df7042c..84968da 100644
@@ -151,6 +151,18 @@ FLEX:=$(shell which flex || type -p flex)
  BISON:=$(shell which bison || type -p bison)
  SED:=$(shell which sed || type -p sed) -i -e
 
+PYTHON2:=$(shell \
+	which python&>/dev/null&&  \

package/Makefile.in FLEX:=$(shell which flex || type -p flex) · line 165

Quoted 10 lines
package/Makefile.in +10 -0
+		python --version 2>&1 | grep -qE 'Python 2\.[6-7]*'&&  \
+		which python || \
+	which python2&>/dev/null&&  \
+		python2 --version 2>&1 | grep -qE 'Python 2\.[6-7]*'&&  \
+		which python2 || \
+	echo $(HOST_DIR)/usr/bin/python)
+HOST_PYTHON2:=$(shell \
+	test $(PYTHON2) != $(HOST_DIR)/usr/bin/python || \
+	echo host-python)
+

This is probably better placed in support/dependencies, using the
suitable-host-package infrastructure. Put the PYTHON2 script in support/dependencies/check-host-python2.sh, and create a support/dependencies/check-host-python2.mk containing:

PYTHON2 := python python2
PYTHON2 := $(call suitable-host-package,$(PYTHON2)) ifeq ($(PYTHON2),$(HOST_DIR)/usr/bin/python)
HOST_PYTHON2 = host-python
endif

Actually, maybe DEP_PYTHON2 is a better name for the dependency. Or
NEEDS_PYTHON2.

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                               arnout at mind be
Senior Embedded Software Architect                 +32-16-286540
Essensium/Mind                                     http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium                BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#3 lore raw

PATCH 1/2 Makefile.in: add host python2 binary detection

Hi,

2012/5/12 Arnout Vandecappelle <[email protected]>:

Quoted 32 lines · Samuel Martin
Quoted 14 lines
package/Makefile.in +0 -0
index df7042c..84968da 100644
@@ -151,6 +151,18 @@ FLEX:=$(shell which flex || type -p flex)
 ?BISON:=$(shell which bison || type -p bison)

?SED:=$(shell which sed || type -p sed) -i -e

package/Makefile.in +2 -0
+PYTHON2:=$(shell \
+ ? ? ? which python&>/dev/null&& ?\

package/Makefile.in

Quoted 10 lines
package/Makefile.in +10 -0
+ ? ? ? ? ? ? ? python --version 2>&1 | grep -qE 'Python 2\.[6-7]*'&& ?\
+ ? ? ? ? ? ? ? which python || \
+ ? ? ? which python2&>/dev/null&& ?\
+ ? ? ? ? ? ? ? python2 --version 2>&1 | grep -qE 'Python 2\.[6-7]*'&& ?\
+ ? ? ? ? ? ? ? which python2 || \
+ ? ? ? echo $(HOST_DIR)/usr/bin/python)
+HOST_PYTHON2:=$(shell \
+ ? ? ? test $(PYTHON2) != $(HOST_DIR)/usr/bin/python || \
+ ? ? ? echo host-python)
+

?This is probably better placed in support/dependencies, using the suitable-host-package infrastructure. ?Put the PYTHON2 script in support/dependencies/check-host-python2.sh, and create a support/dependencies/check-host-python2.mk containing:

Quoted 9 lines

PYTHON2 := python python2
PYTHON2 := $(call suitable-host-package,$(PYTHON2)) ifeq ($(PYTHON2),$(HOST_DIR)/usr/bin/python) ?HOST_PYTHON2 = host-python
endif

?Actually, maybe DEP_PYTHON2 is a better name for the dependency. ?Or NEEDS_PYTHON2.

I've never noticed this stuff before.
Looks like exactly what I wanted to do!

Thx for the tip.

Quoted 10 lines

?Regards,
?Arnout

--
Arnout Vandecappelle ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? arnout at mind be Senior Embedded Software Architect ? ? ? ? ? ? ? ? +32-16-286540 Essensium/Mind ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium ? ? ? ? ? ? ? ?BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: ?7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F

Cheers,

Sam

#4 lore raw

PATCH v2 1/2 dependencies: build a host python2 if no suitable one can be found

In reply to Arnout Vandecappelle

Some distros choose to change the /usr/bin/python binary, make 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 requirement. Buildroot can runs on a host without python, or with a too old python2 version, or with only python3.

 create mode 100644 support/dependencies/check-host-python2.mk
 create mode 100755 support/dependencies/check-host-python2.sh
support/dependencies/check-host-python2.mk new file +7 -0
new file mode 100644
index 0000000..79197cb
@@ -0,0 +1,7 @@
+PYTHON2 := $(call suitable-host-package,python2)
+NEED_PYTHON2 :=
+
+ifeq (,$(PYTHON2))
+  NEED_PYTHON2 = host-python
+  PYTHON2 = $(HOST_DIR)/usr/bin/python
+endif
support/dependencies/check-host-python2.sh new file +13 -0
new file mode 100755
index 0000000..6adb328
@@ -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 -qE 'Python 2\.[6-7]*' ; then
+    # found a valid candidate, so quit now
+    echo $(which ${candidate})
+    exit
+  fi
+done

--
1.7.10.2

#5 lore raw

PATCH v2 2/2 libglib2: fix install even if the host python binary refers to python3

The libglib2's build system uses some python2 scripts in the install rules.

This patch ensures to have a valid host python2 binary and enforces this python2 binary at configure-time.

package/libglib2/libglib2.mk +7 -2
index d2445a1..500f309 100644
@@ -42,7 +42,10 @@ LIBGLIB2_CONF_ENV = \
 		ac_use_included_regex=no gl_cv_c_restrict=no \
 		ac_cv_path_GLIB_GENMARSHAL=$(HOST_DIR)/usr/bin/glib-genmarshal ac_cv_prog_F77=no \
 		ac_cv_func_posix_getgrgid_r=no \
-		gt_cv_c_wchar_t=$(if $(BR2_USE_WCHAR),yes,no)
+		gt_cv_c_wchar_t=$(if $(BR2_USE_WCHAR),yes,no) \
+		ac_cv_path_PYTHON=$(PYTHON2)
+
+HOST_LIBGLIB2_CONF_ENV += ac_cv_path_PYTHON=$(PYTHON2)
 
 # old uClibc versions don't provide qsort_r
 ifeq ($(BR2_UCLIBC_VERSION_0_9_31)$(BR2_UCLIBC_VERSION_0_9_32)$(BR2_TOOLCHAIN_CTNG_uClibc)$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC),y)
@@ -57,7 +60,9 @@ HOST_LIBGLIB2_CONF_OPT = \
 
 LIBGLIB2_DEPENDENCIES = host-pkg-config host-libglib2 libffi zlib $(if $(BR2_NEEDS_GETTEXT),gettext libintl)
 
-HOST_LIBGLIB2_DEPENDENCIES = host-pkg-config host-libffi host-zlib
+HOST_LIBGLIB2_DEPENDENCIES = host-pkg-config host-libffi host-zlib $(NEED_PYTHON2)
+
+LIBGLIB2_DEPENDENCIES += $(NEED_PYTHON2)
 
 ifneq ($(BR2_ENABLE_LOCALE),y)
 LIBGLIB2_DEPENDENCIES += libiconv
Signature · 1 line
1.7.10.2
#6 lore raw

PATCH v2 1/2 dependencies: build a host python2 if no suitable one can be found

In reply to Samuel Martin

support/dependencies/check-host-python2.mk line 2

Quoted 8 lines · Samuel Martin
support/dependencies/check-host-python2.mk new file +2 -0
new file mode 100644
index 0000000..79197cb
@@ -0,0 +1,7 @@
+PYTHON2 := $(call suitable-host-package,python2)
+NEED_PYTHON2 :=

This can be removed, empty is the default.

support/dependencies/check-host-python2.mk line 7

Quoted 5 lines
support/dependencies/check-host-python2.mk new file +5 -0
+
+ifeq (,$(PYTHON2))
+  NEED_PYTHON2 = host-python
+  PYTHON2 = $(HOST_DIR)/usr/bin/python
+endif

Does this work? I thought it wasn't allowed to mix := and = assignments.

Quoted 6 lines
support/dependencies/check-host-python2.sh new file +0 -0
new file mode 100755
index 0000000..6adb328

support/dependencies/check-host-python2.sh line 8

Quoted 8 lines
support/dependencies/check-host-python2.sh new file +8 -0
@@ -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 -qE 'Python 2\.[6-7]*' ; then

The * is a mistake, I think. This way, 2.5 also matches (zero repetitions).
The -E is also a redundant since you're not using extended regexp.

Regards,
Arnout

Quoted 5 lines
support/dependencies/check-host-python2.sh new file +5 -0
+    # found a valid candidate, so quit now
+    echo $(which ${candidate})
+    exit
+  fi
+done
Signature · 6 lines
Arnout Vandecappelle                               arnout at mind be
Senior Embedded Software Architect                 +32-16-286540
Essensium/Mind                                     http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium                BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
#7 lore raw

PATCH v2 1/2 dependencies: build a host python2 if no suitable one can be found

2012/5/15 Arnout Vandecappelle <[email protected]>:

Quoted 14 lines · Samuel Martin

support/dependencies/check-host-python2.mk line 2

Quoted 10 lines
support/dependencies/check-host-python2.mk new file +2 -0
new file mode 100644
index 0000000..79197cb
@@ -0,0 +1,7 @@
+PYTHON2 := $(call suitable-host-package,python2)
+NEED_PYTHON2 :=

?This can be removed, empty is the default.

Fair enough

Quoted 10 lines

support/dependencies/check-host-python2.mk line 7

Quoted 7 lines
support/dependencies/check-host-python2.mk new file +5 -0
+
+ifeq (,$(PYTHON2))
+ ?NEED_PYTHON2 = host-python
+ ?PYTHON2 = $(HOST_DIR)/usr/bin/python
+endif

?Does this work? ?I thought it wasn't allowed to mix := and = assignments.

In my test runs, it does, though I can get rid of the immediat assignment I think.

Quoted 13 lines
Quoted 13 lines
support/dependencies/check-host-python2.sh new file +4 -0
new file mode 100755
index 0000000..6adb328
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+candidates="python python2"
+
Quoted 8 lines

support/dependencies/check-host-python2.sh line 8

Quoted 4 lines
support/dependencies/check-host-python2.sh new file +4 -0
+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 -qE 'Python 2\.[6-7]*' ; then

?The * is a mistake, I think. ?This way, 2.5 also matches (zero repetitions).

You're right, .* will fix that.

Quoted 1 line

The -E is also a redundant since you're not using extended regexp.

ok

Cheers,

Sam

#8 lore raw

PATCH 2/2 libglib2: fix install even if the host python binary refers to python3

In reply to Samuel Martin
package/libglib2/libglib2.mk +16 -3
index d2445a1..4c372d8 100644
@@ -42,7 +42,10 @@ LIBGLIB2_CONF_ENV = \
 		ac_use_included_regex=no gl_cv_c_restrict=no \
 		ac_cv_path_GLIB_GENMARSHAL=$(HOST_DIR)/usr/bin/glib-genmarshal ac_cv_prog_F77=no \
 		ac_cv_func_posix_getgrgid_r=no \
-		gt_cv_c_wchar_t=$(if $(BR2_USE_WCHAR),yes,no)
+		gt_cv_c_wchar_t=$(if $(BR2_USE_WCHAR),yes,no) \
+		ac_cv_path_PYTHON=$(PYTHON2)
+
+HOST_LIBGLIB2_CONF_ENV += ac_cv_path_PYTHON=$(PYTHON2)
 
 # old uClibc versions don't provide qsort_r
 ifeq ($(BR2_UCLIBC_VERSION_0_9_31)$(BR2_UCLIBC_VERSION_0_9_32)$(BR2_TOOLCHAIN_CTNG_uClibc)$(BR2_TOOLCHAIN_EXTERNAL_UCLIBC),y)
@@ -55,9 +58,19 @@ HOST_LIBGLIB2_CONF_OPT = \
 		--disable-gtk-doc \
 		--enable-debug=no \
 
-LIBGLIB2_DEPENDENCIES = host-pkg-config host-libglib2 libffi zlib $(if $(BR2_NEEDS_GETTEXT),gettext libintl)
+LIBGLIB2_DEPENDENCIES = \
+		host-pkg-config \
+		host-libglib2 \
+		$(HOST_PYTHON2) \
+		libffi \
+		zlib \
+		$(if $(BR2_NEEDS_GETTEXT),gettext libintl)
 
-HOST_LIBGLIB2_DEPENDENCIES = host-pkg-config host-libffi host-zlib
+HOST_LIBGLIB2_DEPENDENCIES = \
+		host-pkg-config \
+		host-libffi \
+		host-zlib \
+		$(HOST_PYTHON2)
 
 ifneq ($(BR2_ENABLE_LOCALE),y)
 LIBGLIB2_DEPENDENCIES += libiconv
Signature · 1 line
1.7.10.1