package/pkg-python.mk: replace $(_BASE_BUILD_CMD) with $($(SETUP_TYPE)_BUILD_CMD)

The _BASE_BUILD_CMD variable is set based on the setup type, and only
based on the setup type. Because of this, we have a large conditional
tree in inner-python-package which makes things hard to read.

Rather than conditions, it's also possible to use indirect variables.
Concretely, we can define PKG_PYTHON_DISTUTILS_BUILD_CMD etc., and use
$(PKG_PYTHON_$($(PKG)_SETUP_TYPE)_BUILD_CMD) instead of
$($(PKG)_BASE_BUILD_CMD) to dispatch to the right _BUILD_CMD variable.

Once we do the same for all other variables that are set in the
condition tree, we'll be able to remove the condition tree entirely.

setuptools-rust, flit and maturin didn't have their own definition of
_BUILD_CMD but were under the setuptools resp. pep517 condition. For
these, we have to define new variables that copy the value from
PKG_PYTHON_SETUPTOOLS_BUILD_CMD resp. PKG_PYTHON_PEP517_BUILD_CMD.

Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
This commit is contained in:
Arnout Vandecappelle 2023-10-01 00:16:29 +02:00 committed by Yann E. MORIN
parent 9e447e8b2f
commit b28b95d1e4

View File

@ -57,7 +57,8 @@ PKG_PYTHON_DISTUTILS_ENV = \
$(PKG_PYTHON_ENV) \
LDSHARED="$(TARGET_CROSS)gcc -shared"
PKG_PYTHON_DISTUTILS_BUILD_OPTS = \
PKG_PYTHON_DISTUTILS_BUILD_CMD = \
setup.py build \
--executable=/usr/bin/python
PKG_PYTHON_DISTUTILS_INSTALL_OPTS = \
@ -76,6 +77,9 @@ PKG_PYTHON_DISTUTILS_INSTALL_STAGING_OPTS = \
HOST_PKG_PYTHON_DISTUTILS_ENV = \
$(HOST_PKG_PYTHON_ENV)
HOST_PKG_PYTHON_DISTUTILS_BUILD_CMD = \
setup.py build \
HOST_PKG_PYTHON_DISTUTILS_INSTALL_OPTS = \
--prefix=$(HOST_DIR)
@ -86,6 +90,9 @@ PKG_PYTHON_SETUPTOOLS_ENV = \
PKG_PYTHON_SETUPTOOLS_CMD = \
$(if $(wildcard $($(PKG)_BUILDDIR)/setup.py),setup.py,-c 'from setuptools import setup;setup()')
PKG_PYTHON_SETUPTOOLS_BUILD_CMD = \
$(PKG_PYTHON_SETUPTOOLS_CMD) build
PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS = \
--install-headers=/usr/include/python$(PYTHON3_VERSION_MAJOR) \
--prefix=/usr \
@ -104,6 +111,9 @@ PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_OPTS = \
HOST_PKG_PYTHON_SETUPTOOLS_ENV = \
$(HOST_PKG_PYTHON_ENV)
HOST_PKG_PYTHON_SETUPTOOLS_BUILD_CMD = \
$(PKG_PYTHON_SETUPTOOLS_CMD) build
HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS = \
--prefix=$(HOST_DIR) \
--root=/ \
@ -115,16 +125,25 @@ PKG_PYTHON_SETUPTOOLS_RUST_ENV = \
$(PKG_CARGO_ENV) \
PYO3_CROSS_LIB_DIR="$(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)"
PKG_PYTHON_SETUPTOOLS_RUST_BUILD_CMD = \
$(PKG_PYTHON_SETUPTOOLS_BUILD_CMD)
# Host setuptools-rust-based packages
HOST_PKG_PYTHON_SETUPTOOLS_RUST_ENV = \
$(HOST_PKG_PYTHON_SETUPTOOLS_ENV) \
$(HOST_PKG_CARGO_ENV) \
PYO3_CROSS_LIB_DIR="$(HOST_DIR)/lib/python$(PYTHON3_VERSION_MAJOR)"
HOST_PKG_PYTHON_SETUPTOOLS_RUST_BUILD_CMD = \
$(HOST_PKG_PYTHON_SETUPTOOLS_BUILD_CMD)
# Target pep517-based packages
PKG_PYTHON_PEP517_ENV = \
$(PKG_PYTHON_ENV)
PKG_PYTHON_PEP517_BUILD_CMD = \
-m build -n -w
PKG_PYTHON_PEP517_INSTALL_OPTS = \
--interpreter=/usr/bin/python \
--script-kind=posix
@ -147,6 +166,9 @@ PKG_PYTHON_PEP517_INSTALL_STAGING_OPTS = \
HOST_PKG_PYTHON_PEP517_ENV = \
$(HOST_PKG_PYTHON_ENV)
HOST_PKG_PYTHON_PEP517_BUILD_CMD = \
-m build -n -w
HOST_PKG_PYTHON_PEP517_INSTALL_OPTS = \
--interpreter=$(HOST_DIR)/bin/python \
--script-kind=posix \
@ -162,26 +184,41 @@ HOST_PKG_PYTHON_PEP517_BOOTSTRAP_INSTALL_OPTS = \
PKG_PYTHON_FLIT_ENV = \
$(PKG_PYTHON_PEP517_ENV)
PKG_PYTHON_FLIT_BUILD_CMD = \
$(PKG_PYTHON_PEP517_BUILD_CMD)
# Host flit packages
HOST_PKG_PYTHON_FLIT_ENV = \
$(HOST_PKG_PYTHON_PEP517_ENV)
HOST_PKG_PYTHON_FLIT_BUILD_CMD = \
$(HOST_PKG_PYTHON_PEP517_BUILD_CMD)
# Host flit-bootstrap packages
HOST_PKG_PYTHON_FLIT_BOOTSTRAP_ENV = \
$(HOST_PKG_PYTHON_PEP517_ENV)
HOST_PKG_PYTHON_FLIT_BOOTSTRAP_BUILD_CMD = \
-m flit_core.wheel
# Target maturin packages
PKG_PYTHON_MATURIN_ENV = \
$(PKG_PYTHON_PEP517_ENV) \
$(PKG_CARGO_ENV) \
PYO3_CROSS_LIB_DIR="$(STAGING_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)"
PKG_PYTHON_MATURIN_BUILD_CMD = \
$(PKG_PYTHON_PEP517_BUILD_CMD)
# Host maturin packages
HOST_PKG_PYTHON_MATURIN_ENV = \
$(HOST_PKG_PYTHON_PEP517_ENV) \
$(HOST_PKG_CARGO_ENV) \
PYO3_CROSS_LIB_DIR="$(HOST_DIR)/lib/python$(PYTHON3_VERSION_MAJOR)"
HOST_PKG_PYTHON_MATURIN_BUILD_CMD = \
$(HOST_PKG_PYTHON_PEP517_BUILD_CMD)
################################################################################
# inner-python-package -- defines how the configuration, compilation
# and installation of a Python package should be done, implements a
@ -211,37 +248,30 @@ $(2)_SETUP_TYPE_UPPER = $$(call UPPERCASE,$$($(2)_SETUP_TYPE))
# Distutils
ifeq ($$($(2)_SETUP_TYPE),distutils)
ifeq ($(4),target)
$(2)_BASE_BUILD_CMD = setup.py build $$(PKG_PYTHON_DISTUTILS_BUILD_OPTS)
$(2)_BASE_INSTALL_TARGET_CMD = setup.py install --no-compile $$(PKG_PYTHON_DISTUTILS_INSTALL_TARGET_OPTS)
$(2)_BASE_INSTALL_STAGING_CMD = setup.py install $$(PKG_PYTHON_DISTUTILS_INSTALL_STAGING_OPTS)
else
$(2)_BASE_BUILD_CMD = setup.py build
$(2)_BASE_INSTALL_CMD = setup.py install $$(HOST_PKG_PYTHON_DISTUTILS_INSTALL_OPTS)
endif
# Setuptools
else ifneq ($$(filter setuptools setuptools-rust,$$($(2)_SETUP_TYPE)),)
ifeq ($(4),target)
$(2)_BASE_BUILD_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) build
$(2)_BASE_INSTALL_TARGET_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install --no-compile $$(PKG_PYTHON_SETUPTOOLS_INSTALL_TARGET_OPTS)
$(2)_BASE_INSTALL_STAGING_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install $$(PKG_PYTHON_SETUPTOOLS_INSTALL_STAGING_OPTS)
else
$(2)_BASE_BUILD_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) build
$(2)_BASE_INSTALL_CMD = $$(PKG_PYTHON_SETUPTOOLS_CMD) install $$(HOST_PKG_PYTHON_SETUPTOOLS_INSTALL_OPTS)
endif
else ifneq ($$(filter flit maturin pep517,$$($(2)_SETUP_TYPE)),)
ifeq ($(4),target)
$(2)_BASE_BUILD_CMD = -m build -n -w
$(2)_BASE_INSTALL_TARGET_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(PKG_PYTHON_PEP517_INSTALL_TARGET_OPTS)
$(2)_BASE_INSTALL_STAGING_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(PKG_PYTHON_PEP517_INSTALL_STAGING_OPTS)
else
$(2)_BASE_BUILD_CMD = -m build -n -w
$(2)_BASE_INSTALL_CMD = $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(HOST_PKG_PYTHON_PEP517_INSTALL_OPTS)
endif
else ifeq ($$($(2)_SETUP_TYPE),flit-bootstrap)
ifeq ($(4),target)
$$(error flit-bootstrap setup type only supported for host packages)
else
$(2)_BASE_BUILD_CMD = -m flit_core.wheel
$(2)_BASE_INSTALL_CMD ?= $(TOPDIR)/support/scripts/pyinstaller.py dist/* $$(HOST_PKG_PYTHON_PEP517_INSTALL_OPTS)
endif
else
@ -326,7 +356,7 @@ define $(2)_BUILD_CMDS
$$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
$$($$(PKG)_ENV) \
$$(HOST_DIR)/bin/python3 \
$$($$(PKG)_BASE_BUILD_CMD) \
$$(PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_BUILD_CMD) \
$$($$(PKG)_BUILD_OPTS))
endef
endif
@ -373,7 +403,7 @@ define $(2)_BUILD_CMDS
$$(HOST_PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_ENV) \
$$($$(PKG)_ENV) \
$$(HOST_DIR)/bin/python3 \
$$($$(PKG)_BASE_BUILD_CMD) \
$$(HOST_PKG_PYTHON_$$($$(PKG)_SETUP_TYPE_UPPER)_BUILD_CMD) \
$$($$(PKG)_BUILD_OPTS))
endef
endif