[2/5] Makefiles: auto-detect python version - prefer python2

Submitted by Adrian Reber on May 14, 2018, 1:07 p.m.

Details

Message ID 1526303231-10750-3-git-send-email-adrian@lisas.de
State New
Series "Series without cover letter"
Headers show

Commit Message

Adrian Reber May 14, 2018, 1:07 p.m.
From: Adrian Reber <areber@redhat.com>

This prepares CRIT for python2/python3 compatibility by auto-detecting
the installed python version. python2 is detected first and then the
variable CRIU_PYTHON is set.

Signed-off-by: Adrian Reber <areber@redhat.com>
---
 Makefile.config        | 9 +++++++++
 lib/Makefile           | 3 +--
 lib/py/images/Makefile | 4 ++--
 3 files changed, 12 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/Makefile.config b/Makefile.config
index 0e55780..cb0fd77 100644
--- a/Makefile.config
+++ b/Makefile.config
@@ -12,6 +12,15 @@  ifeq ($(call pkg-config-check,libselinux),y)
         FEATURE_DEFINES	+= -DCONFIG_HAS_SELINUX
 endif
 
+ifndef CRIU_PYTHON
+	CRIU_PYTHON := $(shell python2 -V 2>/dev/null || echo python3)
+ifneq ($(CRIU_PYTHON),python3)
+	CRIU_PYTHON := python2
+endif
+endif
+
+export CRIU_PYTHON
+
 export LIBS += $(LIBS_FEATURES)
 
 CONFIG_FILE = .config
diff --git a/lib/Makefile b/lib/Makefile
index 26b355a..7c0ab76 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,6 +1,5 @@ 
 CRIU_SO			:= libcriu.so
 UAPI_HEADERS		:= lib/c/criu.h images/rpc.proto
-PYTHON_BIN ?= python2
 
 #
 # File to keep track of files installed by setup.py
@@ -54,7 +53,7 @@  install: lib-c lib-py crit/crit lib/c/criu.pc.in
 	$(Q) sed -e 's,@version@,$(CRIU_VERSION),' -e 's,@libdir@,$(LIBDIR),' -e 's,@includedir@,$(dir $(INCLUDEDIR)/criu/),' lib/c/criu.pc.in > lib/c/criu.pc
 	$(Q) install -m 644 lib/c/criu.pc $(DESTDIR)$(LIBDIR)/pkgconfig
 	$(E) "  INSTALL " crit
-	$(Q) $(PYTHON_BIN) scripts/crit-setup.py install --prefix=$(DESTDIR)$(PREFIX) --record $(CRIT_SETUP_FILES)
+	$(Q) $(CRIU_PYTHON) scripts/crit-setup.py install --prefix=$(DESTDIR)$(PREFIX) --record $(CRIT_SETUP_FILES)
 .PHONY: install
 
 uninstall:
diff --git a/lib/py/images/Makefile b/lib/py/images/Makefile
index cb328ec..06e1aee 100644
--- a/lib/py/images/Makefile
+++ b/lib/py/images/Makefile
@@ -12,11 +12,11 @@  images:
 
 magic.py: scripts/magic-gen.py criu/include/magic.h
 	$(call msg-gen, $@)
-	$(Q) python $^ $(obj)/$@
+	$(CRIU_PYTHON) $^ $(obj)/$@
 
 pb.py: images
 	$(Q) echo "# Autogenerated. Do not edit!" > $(obj)/$@
-	$(Q) for m in $(proto-py-modules); do \
+	$(Q) for m in $(filter-out opts_pb2, $(proto-py-modules)); do \
 		echo "from .$$m import *" >> $(obj)/$@ ;\
 	done
 .PHONY: pb.py

Comments

Mike Rapoport May 14, 2018, 1:40 p.m.
On Mon, May 14, 2018 at 01:07:08PM +0000, Adrian Reber wrote:
> From: Adrian Reber <areber@redhat.com>
> 
> This prepares CRIT for python2/python3 compatibility by auto-detecting
> the installed python version. python2 is detected first and then the
> variable CRIU_PYTHON is set.
> 
> Signed-off-by: Adrian Reber <areber@redhat.com>
> ---
>  Makefile.config        | 9 +++++++++
>  lib/Makefile           | 3 +--
>  lib/py/images/Makefile | 4 ++--
>  3 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/Makefile.config b/Makefile.config
> index 0e55780..cb0fd77 100644
> --- a/Makefile.config
> +++ b/Makefile.config
> @@ -12,6 +12,15 @@ ifeq ($(call pkg-config-check,libselinux),y)
>          FEATURE_DEFINES	+= -DCONFIG_HAS_SELINUX
>  endif
> 
> +ifndef CRIU_PYTHON
> +	CRIU_PYTHON := $(shell python2 -V 2>/dev/null || echo python3)

Maybe
	CRIU_PYTHON := $(shell which python2 || which python3)


> +ifneq ($(CRIU_PYTHON),python3)
> +	CRIU_PYTHON := python2
> +endif
> +endif
> +
> +export CRIU_PYTHON
> +
>  export LIBS += $(LIBS_FEATURES)
> 
>  CONFIG_FILE = .config
> diff --git a/lib/Makefile b/lib/Makefile
> index 26b355a..7c0ab76 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -1,6 +1,5 @@
>  CRIU_SO			:= libcriu.so
>  UAPI_HEADERS		:= lib/c/criu.h images/rpc.proto
> -PYTHON_BIN ?= python2
> 
>  #
>  # File to keep track of files installed by setup.py
> @@ -54,7 +53,7 @@ install: lib-c lib-py crit/crit lib/c/criu.pc.in
>  	$(Q) sed -e 's,@version@,$(CRIU_VERSION),' -e 's,@libdir@,$(LIBDIR),' -e 's,@includedir@,$(dir $(INCLUDEDIR)/criu/),' lib/c/criu.pc.in > lib/c/criu.pc
>  	$(Q) install -m 644 lib/c/criu.pc $(DESTDIR)$(LIBDIR)/pkgconfig
>  	$(E) "  INSTALL " crit
> -	$(Q) $(PYTHON_BIN) scripts/crit-setup.py install --prefix=$(DESTDIR)$(PREFIX) --record $(CRIT_SETUP_FILES)
> +	$(Q) $(CRIU_PYTHON) scripts/crit-setup.py install --prefix=$(DESTDIR)$(PREFIX) --record $(CRIT_SETUP_FILES)
>  .PHONY: install
> 
>  uninstall:
> diff --git a/lib/py/images/Makefile b/lib/py/images/Makefile
> index cb328ec..06e1aee 100644
> --- a/lib/py/images/Makefile
> +++ b/lib/py/images/Makefile
> @@ -12,11 +12,11 @@ images:
> 
>  magic.py: scripts/magic-gen.py criu/include/magic.h
>  	$(call msg-gen, $@)
> -	$(Q) python $^ $(obj)/$@
> +	$(CRIU_PYTHON) $^ $(obj)/$@

$(Q) $(CRIU_PYTHON)

>  pb.py: images
>  	$(Q) echo "# Autogenerated. Do not edit!" > $(obj)/$@
> -	$(Q) for m in $(proto-py-modules); do \
> +	$(Q) for m in $(filter-out opts_pb2, $(proto-py-modules)); do \
>  		echo "from .$$m import *" >> $(obj)/$@ ;\
>  	done
>  .PHONY: pb.py
> -- 
> 1.8.3.1
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
>
Dmitry Safonov May 14, 2018, 2:55 p.m.
2018-05-14 14:40 GMT+01:00 Mike Rapoport <rppt@linux.vnet.ibm.com>:
> On Mon, May 14, 2018 at 01:07:08PM +0000, Adrian Reber wrote:
>> From: Adrian Reber <areber@redhat.com>
>>
>> This prepares CRIT for python2/python3 compatibility by auto-detecting
>> the installed python version. python2 is detected first and then the
>> variable CRIU_PYTHON is set.
>>
>> Signed-off-by: Adrian Reber <areber@redhat.com>
>> ---
>>  Makefile.config        | 9 +++++++++
>>  lib/Makefile           | 3 +--
>>  lib/py/images/Makefile | 4 ++--
>>  3 files changed, 12 insertions(+), 4 deletions(-)
>>
>> diff --git a/Makefile.config b/Makefile.config
>> index 0e55780..cb0fd77 100644
>> --- a/Makefile.config
>> +++ b/Makefile.config
>> @@ -12,6 +12,15 @@ ifeq ($(call pkg-config-check,libselinux),y)
>>          FEATURE_DEFINES      += -DCONFIG_HAS_SELINUX
>>  endif
>>
>> +ifndef CRIU_PYTHON
>> +     CRIU_PYTHON := $(shell python2 -V 2>/dev/null || echo python3)
>
> Maybe
>         CRIU_PYTHON := $(shell which python2 || which python3)

Hmm, can we define it as just $(PYTHON) and in scripts/nmk/scripts/tools.mk
near other tools definitions?
It's already weakly defined there, but not used anywhere, so we can just
fix definition to python2/python3.

Thanks,
             Dmitry