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

Mike Rapoport rppt at linux.vnet.ibm.com
Mon May 14 16:40:19 MSK 2018


On Mon, May 14, 2018 at 01:07:08PM +0000, Adrian Reber wrote:
> From: Adrian Reber <areber at 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 at 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, at version@,$(CRIU_VERSION),' -e 's, at libdir@,$(LIBDIR),' -e 's, at 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 at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
> 

-- 
Sincerely yours,
Mike.



More information about the CRIU mailing list