define $(2)_INSTALL_TARGET_CMDS
(cd $$($$(PKG)_BUILDDIR)/; \
$$($$(PKG)_BASE_ENV) $$($$(PKG)_ENV) \
- $$($(2)_PYTHON_INTERPRETER) setup.py install \
+ $$($(2)_PYTHON_INTERPRETER) setup.py install --no-compile \
$$($$(PKG)_BASE_INSTALL_TARGET_OPTS) \
$$($$(PKG)_INSTALL_TARGET_OPTS))
endef
--disable-tk \
--disable-nis \
--disable-dbm \
- --disable-pyo-build
+ --disable-pyo-build \
+ --disable-pyc-build
# This is needed to make sure the Python build process doesn't try to
# regenerate those files with the pgen program. Otherwise, it builds
$(eval $(autotools-package))
$(eval $(host-autotools-package))
+define PYTHON_CREATE_PYC_FILES
+ PYTHONPATH="$(PYTHON_PATH)" \
+ $(HOST_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR) \
+ support/scripts/pycompile.py \
+ $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)
+endef
+
+ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY)$(BR2_PACKAGE_PYTHON_PY_PYC),y)
+TARGET_FINALIZE_HOOKS += PYTHON_CREATE_PYC_FILES
+endif
+
ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY),y)
define PYTHON_REMOVE_PY_FILES
find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | \
TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PY_FILES
endif
+# Normally, *.pyc files should not have been compiled, but just in
+# case, we make sure we remove all of them.
ifeq ($(BR2_PACKAGE_PYTHON_PY_ONLY),y)
define PYTHON_REMOVE_PYC_FILES
find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyc' -print0 | \
PYTHON3_CONF_OPTS += --enable-old-stdlib-cache
endif
-ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
-PYTHON3_CONF_OPTS += --disable-pyc-build
-endif
-
ifeq ($(BR2_PACKAGE_PYTHON3_SQLITE),y)
PYTHON3_DEPENDENCIES += sqlite
else
--disable-lib2to3 \
--disable-tk \
--disable-nis \
- --disable-idle3
+ --disable-idle3 \
+ --disable-pyc-build
# Python builds two tools to generate code: 'pgen' and
# '_freeze_importlib'. Unfortunately, for the target Python, they are
$(eval $(autotools-package))
$(eval $(host-autotools-package))
+define PYTHON3_CREATE_PYC_FILES
+ PYTHONPATH="$(PYTHON3_PATH)" \
+ $(HOST_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR) \
+ support/scripts/pycompile.py \
+ $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)
+endef
+
+ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY)$(BR2_PACKAGE_PYTHON3_PY_PYC),y)
+TARGET_FINALIZE_HOOKS += PYTHON3_CREATE_PYC_FILES
+endif
+
ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
define PYTHON3_REMOVE_PY_FILES
find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.py' -print0 | \
TARGET_FINALIZE_HOOKS += PYTHON3_REMOVE_PY_FILES
endif
+# Normally, *.pyc files should not have been compiled, but just in
+# case, we make sure we remove all of them.
ifeq ($(BR2_PACKAGE_PYTHON3_PY_ONLY),y)
define PYTHON3_REMOVE_PYC_FILES
find $(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR) -name '*.pyc' -print0 | \
--- /dev/null
+#!/usr/bin/env python
+
+# Wrapper for python2 and python3 around compileall to raise exception
+# when a python byte code generation failed.
+#
+# Inspired from:
+# http://stackoverflow.com/questions/615632/how-to-detect-errors-from-compileall-compile-dir
+
+from __future__ import print_function
+import sys
+import py_compile
+import compileall
+
+class ReportProblem:
+ def __nonzero__(self):
+ type, value, traceback = sys.exc_info()
+ if type is not None and issubclass(type, py_compile.PyCompileError):
+ print("Cannot compile %s" %value.file)
+ raise value
+ return 1
+
+report_problem = ReportProblem()
+
+compileall.compile_dir(sys.argv[1], quiet=report_problem)