Marcel Telka
2022-11-05 c6fba2ed41bcf7e748d6f8708dd642099fae481e
commit | author | age
7589de 1 #
MT 2 # This file and its contents are supplied under the terms of the
3 # Common Development and Distribution License ("CDDL"), version 1.0.
4 # You may only use this file in accordance with the terms of version
5 # 1.0 of the CDDL.
6 #
7 # A full copy of the text of the CDDL should have accompanied this
8 # source.  A copy of the CDDL is also available via the Internet at
9 # http://www.illumos.org/license/CDDL.
10 #
11
12 #
13 # Copyright 2022 Marcel Telka
14 #
15
16 include $(WS_MAKE_RULES)/setup.py.mk
17
18 PYTHON_BOOTSTRAP ?= no
19
c6fba2 20 ifeq ($(strip $(PYTHON_BOOTSTRAP)),yes)
MT 21 #
22 # Both 'build' and 'installer' Python modules used for packaging regular Python
23 # projects (see below) are not part of core Python, so we need to bootstrap
24 # them together with their non-core dependencies.
25 #
26 # There are basically two ways how to bootstrap such projects:
27 #
28 # 1) defer to default 'setup.py' build style for projects that still supports
29 # it.  The 'setup.py' build style usually does not require anything outside
30 # core Python modules.  Also, it is likely that the set of projects that needs
31 # to be bootstrapped (like setuptools) will support the 'setup.py' build style
32 # for very long time (maybe forever).  Anyway, the main problem with the
33 # 'setup.py' build style is that its results are not PEP 376 compliant.
34 #
35 # 2) use something else, preferably as simple as possible, to do the build.
36 # Such tool needs to be PEP 376 and PEP 517 compliant and it also must be able
37 # to build itself without requiring any other non-core Python modules.  We use
38 # pyproject_installer to do the job.
39 #
40
41 ifeq ($(strip $(COMPONENT_NAME)),pyproject_installer)
42 # To bootstrap the bootstrapper we need to make sure it finds its own modules
43 PYTHON_ENV += PYTHONPATH=$(@D)/src
44 endif
45
46 # Since pyproject_installer requires Python >= 3.8 we need to defer to default
47 # setup.py build style for Python 3.7, so we will use pyproject_installer for
48 # Python 3.9 only.  Once we obsolete Python 3.7 we should set
49 # COMPONENT_BUILD_CMD, COMPONENT_BUILD_ARGS, COMPONENT_INSTALL_CMD, and
50 # COMPONENT_INSTALL_ARGS unconditionally below and replace $(PYTHON.3.9) by
51 # $(PYTHON).
52 $(BUILD_DIR)/%-3.9/.built:    COMPONENT_BUILD_CMD =        $(PYTHON.3.9) -m pyproject_installer build
53 $(BUILD_DIR)/%-3.9/.built:    COMPONENT_BUILD_ARGS =
54
55 $(BUILD_DIR)/%-3.9/.installed:    COMPONENT_INSTALL_CMD =        $(PYTHON.3.9) -m pyproject_installer install
56 $(BUILD_DIR)/%-3.9/.installed:    COMPONENT_INSTALL_ARGS =
57 $(BUILD_DIR)/%-3.9/.installed:    COMPONENT_INSTALL_ARGS +=    --destdir $(PROTO_DIR)
58
59 # pyproject_installer does not bytecompile after the install.  Since we need
60 # pyc files we need to force that.
61 #
62 # Since pyproject_installer requires Python >= 3.8 we need to defer to default
63 # setup.py build style for Python 3.7, and so we do not need to compile for
64 # Python 3.7.  Once we obsolete Python 3.7 we should set
65 # COMPONENT_POST_INSTALL_ACTION unconditionally below.
66 $(BUILD_DIR)/%-3.9/.installed:    COMPONENT_POST_INSTALL_ACTION +=    $(PYTHON) -m compileall $(PROTO_DIR)/$(PYTHON_LIB) ;
67
68 # Special transforms needed only until we drop support for Python 3.7
69 PUBLISH_TRANSFORMS +=    $(WS_TOP)/transforms/python-bootstrap
70
71 # We need pyproject_installer to bootstrap other projects, but it is not needed
72 # (and cannot be needed) for its own bootstrap.
73 ifneq ($(strip $(COMPONENT_NAME)),pyproject_installer)
74 # Once we obsolete Python 3.7 this should be changed to
75 # PYTHON_USERLAND_REQUIRED_PACKAGES and '-39' suffix should be removed
76 USERLAND_REQUIRED_PACKAGES += library/python/pyproject_installer-39
77 endif
78 else
7589de 79 COMPONENT_BUILD_CMD =        $(PYTHON) -m build
MT 80 COMPONENT_BUILD_ARGS =
81 COMPONENT_BUILD_ARGS +=        --wheel
82 COMPONENT_BUILD_ARGS +=        --no-isolation
83
84 COMPONENT_INSTALL_CMD =        $(PYTHON) -m installer
85 COMPONENT_INSTALL_ARGS =
86 COMPONENT_INSTALL_ARGS +=    --destdir $(PROTO_DIR)
87 COMPONENT_INSTALL_ARGS +=    $(@D)/dist/*.whl
88
89 PYTHON_USERLAND_REQUIRED_PACKAGES += library/python/build
90 PYTHON_USERLAND_REQUIRED_PACKAGES += library/python/installer
91 endif
92
93 # Move all modules from default site-packages directory to vendor-packages
94 # directory where we place modules shipped by the OS but not included in the
95 # core Python distribution.
96 COMPONENT_POST_INSTALL_ACTION += \
97     if [ -d $(PROTO_DIR)/$(PYTHON_DIR)/site-packages ] ; then \
98         $(RM) -r $(PROTO_DIR)/$(PYTHON_LIB) ; \
99         $(MV) $(PROTO_DIR)/$(PYTHON_DIR)/site-packages $(PROTO_DIR)/$(PYTHON_LIB) ; \
100     fi ;