Marcel Telka
2022-10-22 6aefa37c31232291c87d0fb94ac023408ed286a4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
#
 
define python-rule
$(BUILD_DIR)/%-$(1)/.built:        PYTHON_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.installed:        PYTHON_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.tested:        PYTHON_VERSION=$(1)
$(BUILD_DIR)/%-$(1)/.tested-and-compared:    PYTHON_VERSION=$(1)
endef
 
$(foreach pyver, $(PYTHON_VERSIONS), $(eval $(call python-rule,$(pyver))))
 
$(BUILD_DIR)/$(MACH32)-%/.built:    BITS=32
$(BUILD_DIR)/$(MACH64)-%/.built:    BITS=64
$(BUILD_DIR)/$(MACH32)-%/.installed:    BITS=32
$(BUILD_DIR)/$(MACH64)-%/.installed:    BITS=64
$(BUILD_DIR)/$(MACH32)-%/.tested:    BITS=32
$(BUILD_DIR)/$(MACH64)-%/.tested:    BITS=64
$(BUILD_DIR)/$(MACH32)-%/.tested-and-compared:    BITS=32
$(BUILD_DIR)/$(MACH64)-%/.tested-and-compared:    BITS=64
 
PYTHON_32_VERSIONS = $(filter-out $(PYTHON_64_ONLY_VERSIONS), $(PYTHON_VERSIONS))
 
BUILD_32 = $(PYTHON_32_VERSIONS:%=$(BUILD_DIR)/$(MACH32)-%/.built)
BUILD_64 = $(PYTHON_VERSIONS:%=$(BUILD_DIR)/$(MACH64)-%/.built)
BUILD_NO_ARCH = $(PYTHON_VERSIONS:%=$(BUILD_DIR)/$(MACH)-%/.built)
 
ifeq ($(filter-out $(PYTHON_64_ONLY_VERSIONS), $(PYTHON_VERSION)),)
BUILD_32_and_64 = $(BUILD_64)
endif
 
INSTALL_32 = $(PYTHON_32_VERSIONS:%=$(BUILD_DIR)/$(MACH32)-%/.installed)
INSTALL_64 = $(PYTHON_VERSIONS:%=$(BUILD_DIR)/$(MACH64)-%/.installed)
INSTALL_NO_ARCH = $(PYTHON_VERSIONS:%=$(BUILD_DIR)/$(MACH)-%/.installed)
 
PYTHON_ENV =    CC="$(CC)"
PYTHON_ENV +=    CFLAGS="$(CFLAGS)"
PYTHON_ENV +=    PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)"
 
COMPONENT_BUILD_ENV += $(PYTHON_ENV)
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
# other overlapping files.
define python-order-rule
$(BUILD_DIR)/%-$(PYTHON_VERSION)/.installed:    $(BUILD_DIR)/%-$(1)/.installed
endef
$(foreach pyver,$(filter-out $(PYTHON_VERSION),$(PYTHON_VERSIONS)),$(eval $(call python-order-rule,$(pyver))))
 
# We need to copy the source dir to avoid its modification by install target
# where egg-info is re-generated
CLONEY_ARGS = CLONEY_MODE="copy"
 
# 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_POST_BUILD_ACTION)
    $(TOUCH) $@
 
 
COMPONENT_INSTALL_ARGS +=    --root $(PROTO_DIR) 
COMPONENT_INSTALL_ARGS +=    --install-lib=$(PYTHON_LIB)
COMPONENT_INSTALL_ARGS +=    --install-data=$(PYTHON_DATA)
COMPONENT_INSTALL_ARGS +=    --skip-build
COMPONENT_INSTALL_ARGS +=    --force
 
# install the built source into a prototype area
$(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_POST_INSTALL_ACTION)
    $(TOUCH) $@
 
# Rename binaries in /usr/bin to contain version number
COMPONENT_POST_INSTALL_ACTION += \
    for f in $(PROTOUSRBINDIR)/* ; do \
        [[ -f $$f ]] || continue ; \
        for v in $(PYTHON_VERSIONS) ; do \
            [[ "$$f" == "$${f%%-$$v}" ]] || continue 2 ; \
        done ; \
        $(MV) $$f $$f-$(PYTHON_VERSION) ; \
    done ;
 
# Define Python version specific filenames for tests.
ifeq ($(strip $(USE_COMMON_TEST_MASTER)),no)
COMPONENT_TEST_MASTER =    $(COMPONENT_TEST_RESULTS_DIR)/results-$(PYTHON_VERSION).master
endif
COMPONENT_TEST_BUILD_DIR = $(BUILD_DIR)/test
COMPONENT_TEST_OUTPUT =    $(COMPONENT_TEST_BUILD_DIR)/test-$(PYTHON_VERSION)-results
COMPONENT_TEST_DIFFS =    $(COMPONENT_TEST_BUILD_DIR)/test-$(PYTHON_VERSION)-diffs
COMPONENT_TEST_SNAPSHOT = $(COMPONENT_TEST_BUILD_DIR)/results-$(PYTHON_VERSION).snapshot
COMPONENT_TEST_TRANSFORM_CMD = $(COMPONENT_TEST_BUILD_DIR)/transform-$(PYTHON_VERSION)-results
 
# Normalize Python test results.
COMPONENT_TEST_TRANSFORMS += "-e 's/^\(Ran [0-9]\{1,\} tests\) in .*$$/\1/'"    # delete timing from test results
 
COMPONENT_TEST_DEP =    $(BUILD_DIR)/%/.installed
COMPONENT_TEST_ENV +=    PYTHONPATH=$(PROTO_DIR)$(PYTHON_VENDOR_PACKAGES)
 
# determine the type of tests we want to run.
ifeq ($(strip $(wildcard $(COMPONENT_TEST_RESULTS_DIR)/results-*.master)),)
TEST_32 = $(PYTHON_32_VERSIONS:%=$(BUILD_DIR)/$(MACH32)-%/.tested)
TEST_64 = $(PYTHON_VERSIONS:%=$(BUILD_DIR)/$(MACH64)-%/.tested)
TEST_NO_ARCH = $(PYTHON_VERSIONS:%=$(BUILD_DIR)/$(MACH)-%/.tested)
else
TEST_32 = $(PYTHON_32_VERSIONS:%=$(BUILD_DIR)/$(MACH32)-%/.tested-and-compared)
TEST_64 = $(PYTHON_VERSIONS:%=$(BUILD_DIR)/$(MACH64)-%/.tested-and-compared)
TEST_NO_ARCH = $(PYTHON_VERSIONS:%=$(BUILD_DIR)/$(MACH)-%/.tested-and-compared)
endif
 
#
# Warning:
#
# Testing does not work as expected and designed because we test modules from
# build directory containing the cloned source instead of modules installed in
# proto area.  Even explicit PYTHONPATH does not help because current directory
# containing setup.py script is always searched before PYTHONPATH so testing
# finds tested modules there and does not defer to provided PYTHONPATH.
#
# Currently there is no known way how to fix that.
#
 
# test the built source
$(BUILD_DIR)/%/.tested-and-compared:    $(COMPONENT_TEST_DEP)
    $(RM) -rf $(COMPONENT_TEST_BUILD_DIR)
    $(MKDIR) $(COMPONENT_TEST_BUILD_DIR)
    $(COMPONENT_PRE_TEST_ACTION)
    -(cd $(COMPONENT_TEST_DIR) ; \
        $(COMPONENT_TEST_ENV_CMD) $(COMPONENT_TEST_ENV) \
        $(PYTHON) setup.py --no-user-cfg test $(COMPONENT_TEST_ARGS)) \
        &> $(COMPONENT_TEST_OUTPUT)
    $(COMPONENT_POST_TEST_ACTION)
    $(COMPONENT_TEST_CREATE_TRANSFORMS)
    $(COMPONENT_TEST_PERFORM_TRANSFORM)
    $(COMPONENT_TEST_COMPARE)
    $(COMPONENT_TEST_CLEANUP)
    $(TOUCH) $@
 
$(BUILD_DIR)/%/.tested:    $(COMPONENT_TEST_DEP)
    $(COMPONENT_PRE_TEST_ACTION)
    (cd $(COMPONENT_TEST_DIR) ; \
        $(COMPONENT_TEST_ENV_CMD) $(COMPONENT_TEST_ENV) \
        $(PYTHON) setup.py --no-user-cfg test $(COMPONENT_TEST_ARGS))
    $(COMPONENT_POST_TEST_ACTION)
    $(COMPONENT_TEST_CLEANUP)
    $(TOUCH) $@
 
 
# We need to add -$(PYV) to package fmri
GENERATE_EXTRA_CMD += | \
    $(GSED) -e 's/^\(set name=pkg.fmri [^@]*\)\(.*\)$$/\1-$$(PYV)\2/' \
 
 
clean::
    $(RM) -r $(SOURCE_DIR) $(BUILD_DIR)
 
# Make it easy to construct a URL for a pypi source download. This
# construct supports an optional call to a number from
# NUM_EXTRA_ARCHIVES for multiple archive downloads.
pypi_url_multi = pypi:///$(COMPONENT_NAME_$(1))==$(COMPONENT_VERSION_$(1))
pypi_url_single = pypi:///$(COMPONENT_NAME)==$(COMPONENT_VERSION)
pypi_url = $(if $(COMPONENT_NAME_$(1)),$(pypi_url_multi),$(pypi_url_single))