From fe161ff4d63026b1ddf3571ca8866fed579c1044 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 12 Mar 2019 11:35:49 +0000 Subject: [PATCH] py-defs.mk, py-mod.mk: Add support for Python3's __pycache__ Signed-off-by: Jan Lindemann --- make/py-defs.mk | 22 ++++++++++++++++------ make/py-mod.mk | 21 +++++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/make/py-defs.mk b/make/py-defs.mk index 6d6dd211..ac50aa61 100644 --- a/make/py-defs.mk +++ b/make/py-defs.mk @@ -3,9 +3,9 @@ PYTHON ?= python2 #PYTHON = python3 ifneq ($(DEVELOPMENT),true) - PY_SITE_PACKAGES_PATH = $(shell $(PYTHON) -c "import site; print site.getsitepackages()[0]") + PY_SITE_PACKAGES_PATH := $(shell $(PYTHON) -c "import site; print(site.getsitepackages()[0])") else - PY_SITE_PACKAGES_PATH = $(PREFIX)/python2/site-packages + PY_SITE_PACKAGES_PATH := $(PREFIX)/python2/site-packages endif PY_PREREQ_BUILD ?= $(shell $(proj_query_cmd) pkg-requires --subsections jw -d ' ' -p --no-version build $(PROJECT)) @@ -16,7 +16,11 @@ PY_PROJ_MODULES += $(dir $(wildcard $(PY_MODULE_DIRS)/*/__init__.py) PY_MODULES ?= $(PY_PROJ_MODULES) PY_SRC_PY ?= $(wildcard *.py) PY_ALL_PY = $(sort $(PY_SRC_PY) __init__.py) -PY_PYC = $(patsubst %.py,%.pyc,$(PY_ALL_PY)) +ifneq ($(PYTHON),python3) + PY_PYC = $(patsubst %.py,%.pyc,$(PY_ALL_PY)) +else + PY_PYC = $(patsubst %.py,__pycache__/%.cpython-37.pyc,$(PY_ALL_PY)) +endif PY_INSTALL_PKG_MOD ?= $(shell $(PWD) | sed 's%.*/python/%%; s%/.*%%') PY_INSTALL_SUB_MOD ?= $(shell $(PWD) | sed "s%.*/$(PY_INSTALL_PKG_MOD)\(/\|$$\)%%") @@ -26,8 +30,14 @@ else PY_INSTALL_MOD ?= $(PY_INSTALL_PKG_MOD) endif PY_MOD ?= $(subst /,.,$(PY_INSTALL_MOD)) -PY_INSTALL_DIR ?= $(ENV_PREFIX)$(PY_SITE_PACKAGES_PATH)/$(patsubst .,/,$(PY_INSTALL_MOD)) -PY_INSTALLED_REG = $(addprefix $(PY_INSTALL_DIR)/,$(PY_ALL_PY) $(PY_PYC)) +PY_INSTALL_DIR_PY ?= $(ENV_PREFIX)$(PY_SITE_PACKAGES_PATH)/$(patsubst .,/,$(PY_INSTALL_MOD)) +ifeq ($(PYTHON),python3) + PY_INSTALL_DIR_PYC ?= $(PY_INSTALL_DIR_PY)/__pycache__ +endif +PY_INSTALL_DIRS ?= $(PY_INSTALL_DIR_PY) $(PY_INSTALL_DIR_PYC) +PY_INSTALLED_PY = $(addprefix $(PY_INSTALL_DIR_PY)/,$(PY_ALL_PY)) +PY_INSTALLED_PYC = $(addprefix $(PY_INSTALL_DIR_PY)/,$(PY_PYC)) +PY_INSTALLED_REG = $(PY_INSTALLED_PY) $(PY_INSTALLED_PYC) empty := space := $(empty) $(empty) @@ -51,7 +61,7 @@ echo-py: @echo PY_INSTALL_SUB_MOD = $(PY_INSTALL_SUB_MOD) pyc.clean: - $(RM) -f $(wildcard *.pyc) + $(RM) -f $(wildcard *.pyc) __pycache__ libpath: py-libpath py-libpath: @echo export PYTHONPATH=$(PYTHONPATH) diff --git a/make/py-mod.mk b/make/py-mod.mk index d7e91965..69f9068d 100644 --- a/make/py-mod.mk +++ b/make/py-mod.mk @@ -17,21 +17,30 @@ distclean: py.clean: $(RM) -f *.done *.pyc /bin/bash $(MOD_SCRIPT_DIR)/scm.sh clean -f __init__.py + $(RM) -rf __pycache__ install-dirs.done: - $(INSTALL) -d -m $(PYMODDIRMODE) -o $(PYMODDIROWNER) -g $(PYMODDIRGROUP) $(PY_INSTALL_DIR) + $(INSTALL) -d -m $(PYMODDIRMODE) -o $(PYMODDIROWNER) -g $(PYMODDIRGROUP) $(PY_INSTALL_DIRS) touch $@ install-reg.done: install-dirs.done $(PY_INSTALLED_REG) touch $@ -%.pyc: %.py - python2 -c "import py_compile; py_compile.compile(\"$<\")" - -$(PY_INSTALL_DIR)/%.py: %.py +$(PY_INSTALL_DIR_PY)/%.py: %.py $(INSTALL) -p -m $(PYMODMODE) -o $(PYMODOWNER) -g $(PYMODGROUP) $< $@ -$(PY_INSTALL_DIR)/%.pyc: %.pyc +ifneq ($(PYTHON),python3) +%.pyc: %.py +else +__pycache__/%.cpython-37.pyc: %.py +endif + $(PYTHON) -c "import py_compile; py_compile.compile(\"$<\")" + +ifeq ($(PYTHON),python3) +$(PY_INSTALL_DIR_PY)/__pycache__/%.cpython-37.pyc: __pycache__/%.cpython-37.pyc +else +$(PY_INSTALL_DIR_PY)/%.pyc: %.pyc +endif $(INSTALL) -p -m $(PYMODMODE) -o $(PYMODOWNER) -g $(PYMODGROUP) $< $@ __init__.py: $(PY_INIT_TMPL) $(filter-out __init__.py,$(PY_SRC_PY))