Explorar el Código

HUE-8737 [core] make Hue can be built on both py2 and py3

Ying Chen hace 6 años
padre
commit
f7045b0590
Se han modificado 1 ficheros con 23 adiciones y 6 borrados
  1. 23 6
      Makefile.vars

+ 23 - 6
Makefile.vars

@@ -36,19 +36,36 @@ ifneq ($(wildcard $(ROOT)/Makefile.buildvars),)
   include $(ROOT)/Makefile.buildvars
 endif
 
-PYTHON_H ?= $(shell ls /usr/include/python2.7/Python.h 2>/dev/null || ls /usr/local/python27/include/python2.7/Python.h 2>/dev/null || ls /opt/rh/python27/root/usr/include/python2.7/Python.h 2>/dev/null)
+
+VER_ERR_MSG = "Variable PYTHON_VER is $(PYTHON_VER) but it only supports python2.7 or >= python3.5. If not set, defaults to python2.7."
+
+PYTHON_VER ?= python2.7
+PYTHON_EXE = $(shell echo $(PYTHON_VER) | sed "s/\.//")
+
+ifeq ($(PYTHON_VER),python2.7)
+  $(info "PYTHNON_VER is $(PYTHON_VER)")
+else ifeq ($(shell echo $(PYTHON_VER) | head -c 8),python3.)
+  PYTHON_VER := $(shell echo $(PYTHON_VER) | head -c 9)
+  MINOR_VER = $(shell echo -n $(PYTHON_VER) | tail -c 1)
+  ifeq ($(shell test $(MINOR_VER) -lt 5; echo $$?),0)
+    $(error "$(VER_ERR_MSG)")
+  endif
+else
+  $(error "$(VER_ERR_MSG)")
+endif
+
+PYTHON_H ?= $(shell ls /usr/include/$(PYTHON_VER)/Python.h 2>/dev/null || find /usr/local/$(PYTHON_EXE)/include/$(PYTHON_VER)* -name Python.h 2>/dev/null || find /opt/rh/rh-$(PYTHON_EXE)/root/usr/include/$(PYTHON_VER)* -name Python.h 2>/dev/null)
 ifndef SKIP_PYTHONDEV_CHECK
   ifeq ($(PYTHON_H),)
-    $(error "Error: must have python development packages for 2.7. Could not find Python.h. Please install python2.7-devel")
+    $(error "Error: must have python development packages for $(PYTHON_VER). Could not find Python.h. Please install $(PYTHON_VER)-devel")
   endif
-  PYTHON_VER := $(shell echo $(PYTHON_H) | grep -o python2.7)
-  SYS_PYTHON ?= $(shell ls /usr/bin/$(PYTHON_VER) 2>/dev/null || ls /usr/local/python27/bin/$(PYTHON_VER) 2>/dev/null || ls /opt/rh/python27/root/usr/bin/$(PYTHON_VER) 2>/dev/null)
+  SYS_PYTHON ?= $(shell ls /usr/bin/$(PYTHON_VER) 2>/dev/null || ls /usr/local/$(PYTHON_EXE)/bin/$(PYTHON_VER) 2>/dev/null || ls /opt/rh/$(PYTHON_EXE)/root/usr/bin/$(PYTHON_VER) 2>/dev/null || ls /opt/rh/rh-$(PYTHON_EXE)/root/usr/bin/$(PYTHON_VER) 2>/dev/null)
 else
-  SYS_PYTHON ?= $(shell which python2.7)
+  SYS_PYTHON ?= $(shell which $(PYTHON_VER))
 endif
 
 ifeq ($(SYS_PYTHON),)
-  $(error "Error: Need python version 2.7.")
+  $(error "Error: Need python version 2.7 or >= 3.5")
 endif
 
 HADOOP_HOME ?= /usr/lib/hadoop