From 7589de51136b06dc08303fa2ff660cbfac1fffd8 Mon Sep 17 00:00:00 2001
From: Marcel Telka <marcel@telka.sk>
Date: Sun, 30 Oct 2022 07:19:51 +0100
Subject: [PATCH] make-rules: add pyproject build style

---
 make-rules/pyproject-defaults.mk |   16 ++++++++
 make-rules/shared-macros.mk      |    3 +
 make-rules/setup.py.mk           |   11 +++--
 transforms/generate-cleanup      |    3 +
 make-rules/pyproject.mk          |   45 ++++++++++++++++++++++
 5 files changed, 72 insertions(+), 6 deletions(-)

diff --git a/make-rules/pyproject-defaults.mk b/make-rules/pyproject-defaults.mk
new file mode 100644
index 0000000..2e978aa
--- /dev/null
+++ b/make-rules/pyproject-defaults.mk
@@ -0,0 +1,16 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2022 Marcel Telka
+#
+
+include $(WS_MAKE_RULES)/setup.py-defaults.mk
diff --git a/make-rules/pyproject.mk b/make-rules/pyproject.mk
new file mode 100644
index 0000000..48c4ad1
--- /dev/null
+++ b/make-rules/pyproject.mk
@@ -0,0 +1,45 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2022 Marcel Telka
+#
+
+include $(WS_MAKE_RULES)/setup.py.mk
+
+PYTHON_BOOTSTRAP ?= no
+
+# Both build and installer Python modules together with versioned
+# library/python/build and library/python/installer packages are not available
+# during bootstrap.
+ifeq ($(strip $(PYTHON_BOOTSTRAP)),no)
+COMPONENT_BUILD_CMD =		$(PYTHON) -m build
+COMPONENT_BUILD_ARGS =
+COMPONENT_BUILD_ARGS +=		--wheel
+COMPONENT_BUILD_ARGS +=		--no-isolation
+
+COMPONENT_INSTALL_CMD =		$(PYTHON) -m installer
+COMPONENT_INSTALL_ARGS =
+COMPONENT_INSTALL_ARGS +=	--destdir $(PROTO_DIR)
+COMPONENT_INSTALL_ARGS +=	$(@D)/dist/*.whl
+
+PYTHON_USERLAND_REQUIRED_PACKAGES += library/python/build
+PYTHON_USERLAND_REQUIRED_PACKAGES += library/python/installer
+endif
+
+# Move all modules from default site-packages directory to vendor-packages
+# directory where we place modules shipped by the OS but not included in the
+# core Python distribution.
+COMPONENT_POST_INSTALL_ACTION += \
+	if [ -d $(PROTO_DIR)/$(PYTHON_DIR)/site-packages ] ; then \
+		$(RM) -r $(PROTO_DIR)/$(PYTHON_LIB) ; \
+		$(MV) $(PROTO_DIR)/$(PYTHON_DIR)/site-packages $(PROTO_DIR)/$(PYTHON_LIB) ; \
+	fi ;
diff --git a/make-rules/setup.py.mk b/make-rules/setup.py.mk
index 6599fbc..7efaefb 100644
--- a/make-rules/setup.py.mk
+++ b/make-rules/setup.py.mk
@@ -64,9 +64,6 @@
 COMPONENT_INSTALL_ENV += $(PYTHON_ENV)
 COMPONENT_TEST_ENV += $(PYTHON_ENV)
 
-# Reset arguments specified as environmnent variables
-COMPONENT_BUILD_ARGS =
-
 # Make sure the default Python version is installed last and so is the
 # canonical version.  This is needed for components that keep PYTHON_VERSIONS
 # set to more than single value, but deliver unversioned binaries in usr/bin or
@@ -80,16 +77,20 @@
 # where egg-info is re-generated
 CLONEY_ARGS = CLONEY_MODE="copy"
 
+COMPONENT_BUILD_CMD = $(PYTHON) setup.py --no-user-cfg build
+
 # build the configured source
 $(BUILD_DIR)/%/.built:	$(SOURCE_DIR)/.prep
 	$(RM) -r $(@D) ; $(MKDIR) $(@D)
 	$(ENV) $(CLONEY_ARGS) $(CLONEY) $(SOURCE_DIR) $(@D)
 	$(COMPONENT_PRE_BUILD_ACTION)
 	(cd $(@D) ; $(ENV) $(COMPONENT_BUILD_ENV) \
-		$(PYTHON) setup.py --no-user-cfg build $(COMPONENT_BUILD_ARGS))
+		$(COMPONENT_BUILD_CMD) $(COMPONENT_BUILD_ARGS))
 	$(COMPONENT_POST_BUILD_ACTION)
 	$(TOUCH) $@
 
+
+COMPONENT_INSTALL_CMD = $(PYTHON) setup.py --no-user-cfg install
 
 COMPONENT_INSTALL_ARGS +=	--root $(PROTO_DIR) 
 COMPONENT_INSTALL_ARGS +=	--install-lib=$(PYTHON_LIB)
@@ -101,7 +102,7 @@
 $(BUILD_DIR)/%/.installed:	$(BUILD_DIR)/%/.built
 	$(COMPONENT_PRE_INSTALL_ACTION)
 	(cd $(@D) ; $(ENV) $(COMPONENT_INSTALL_ENV) \
-		$(PYTHON) setup.py --no-user-cfg install $(COMPONENT_INSTALL_ARGS))
+		$(COMPONENT_INSTALL_CMD) $(COMPONENT_INSTALL_ARGS))
 	$(COMPONENT_POST_INSTALL_ACTION)
 	$(TOUCH) $@
 
diff --git a/make-rules/shared-macros.mk b/make-rules/shared-macros.mk
index fa331a7..5ae6542 100644
--- a/make-rules/shared-macros.mk
+++ b/make-rules/shared-macros.mk
@@ -714,7 +714,7 @@
 # Modules which are shipped by the OS but not with the core Python distribution
 # belong in vendor-packages.
 PYTHON_DIR= /usr/lib/python$(PYTHON_VERSION)
-PYTHON_LIB= /usr/lib/python$(PYTHON_VERSION)/vendor-packages
+PYTHON_LIB= $(PYTHON_DIR)/vendor-packages
 PYTHON_DATA= $(PYTHON_LIB)
 
 # If the component has python scripts then the first line should probably
@@ -1306,6 +1306,7 @@
 REQUIRED_PACKAGES_SUBST+= GOBJC_RUNTIME_PKG
 
 # Generate requirements on all built python version variants for given packages
+USERLAND_REQUIRED_PACKAGES += $(foreach ver,$(PYTHON_VERSIONS),$(PYTHON_USERLAND_REQUIRED_PACKAGES:%=%-$(shell echo $(ver) | tr -d .)))
 REQUIRED_PACKAGES += $(foreach ver,$(PYTHON_VERSIONS),$(PYTHON_REQUIRED_PACKAGES:%=%-$(shell echo $(ver) | tr -d .)))
 
 # Generate requirements on all built perl version variants for given packages
diff --git a/transforms/generate-cleanup b/transforms/generate-cleanup
index 76980bd..3572387 100644
--- a/transforms/generate-cleanup
+++ b/transforms/generate-cleanup
@@ -73,6 +73,9 @@
 # compliant so this file is no longer needed.
 # See https://github.com/jaraco/backports.entry_points_selectable/issues/5
 <transform dir file link hardlink path=usr\/lib\/python3\.\d+\/vendor-packages\/backports\/__init__\.py$ -> drop>
+# PEP 627 made the RECORD file optional.  Since we do not need the file and it
+# could contain inaccurate info we simply drop it.
+<transform dir file link hardlink path=usr\/lib\/python3\.\d+\/vendor-packages\/[^/]+\.dist-info/RECORD$ -> drop>
 <transform dir file link hardlink -> \
 	edit path "^(usr/bin/[^/]+-)3\.\d+$" "\1$!(PYVER)">
 <transform dir file link hardlink -> \

--
Gitblit v1.9.3