1 |
Introduce a new API that replaces PYTHON_USEDEP with |
2 |
PYTHON_SINGLE_USEDEP variable and PYTHON_MULTI_USEDEP placeholder. |
3 |
The former can be used directly (or via python_gen_cond_dep) when |
4 |
depending on other python-single-r1 packages, the latter can be used |
5 |
via python_gen_cond_dep when depending on python-r1 packages. |
6 |
|
7 |
Long term, the new API will enable us to remove redundant PYTHON_TARGETS |
8 |
flags from python-single-r1 packages. |
9 |
|
10 |
Signed-off-by: Michał Górny <mgorny@g.o> |
11 |
--- |
12 |
eclass/python-single-r1.eclass | 109 ++++++++++++++++++++++++++++----- |
13 |
1 file changed, 93 insertions(+), 16 deletions(-) |
14 |
|
15 |
diff --git a/eclass/python-single-r1.eclass b/eclass/python-single-r1.eclass |
16 |
index f42c0fb6197a..ad7e39558cf1 100644 |
17 |
--- a/eclass/python-single-r1.eclass |
18 |
+++ b/eclass/python-single-r1.eclass |
19 |
@@ -12,12 +12,17 @@ |
20 |
# @DESCRIPTION: |
21 |
# An extension of the python-r1 eclass suite for packages which |
22 |
# don't support being installed for multiple Python implementations. |
23 |
-# This mostly includes tools embedding Python. |
24 |
+# This mostly includes tools embedding Python and packages using foreign |
25 |
+# build systems. |
26 |
# |
27 |
-# This eclass extends the IUSE and REQUIRED_USE set by python-r1 |
28 |
-# to request the PYTHON_SINGLE_TARGET when the inheriting ebuild |
29 |
-# can be supported by more than one Python implementation. It also |
30 |
-# replaces PYTHON_USEDEP and PYTHON_DEPS with a more suitable form. |
31 |
+# This eclass sets correct IUSE. It also provides PYTHON_DEPS |
32 |
+# and PYTHON_REQUIRED_USE that need to be added to appropriate ebuild |
33 |
+# metadata variables. |
34 |
+# |
35 |
+# The eclass exports PYTHON_SINGLE_USEDEP that is suitable for depending |
36 |
+# on other packages using the eclass. Dependencies on packages using |
37 |
+# python-r1 should be created via python_gen_cond_dep() function, |
38 |
+# using PYTHON_MULTI_USEDEP placeholder. |
39 |
# |
40 |
# Please note that packages support multiple Python implementations |
41 |
# (using python-r1 eclass) can not depend on packages not supporting |
42 |
@@ -136,6 +141,9 @@ EXPORT_FUNCTIONS pkg_setup |
43 |
|
44 |
# @ECLASS-VARIABLE: PYTHON_USEDEP |
45 |
# @DESCRIPTION: |
46 |
+# DEPRECATED. Use PYTHON_SINGLE_USEDEP or python_gen_cond_dep with |
47 |
+# PYTHON_MULTI_USEDEP placeholder instead. |
48 |
+# |
49 |
# This is an eclass-generated USE-dependency string which can be used to |
50 |
# depend on another Python package being built for the same Python |
51 |
# implementations. |
52 |
@@ -154,6 +162,43 @@ EXPORT_FUNCTIONS pkg_setup |
53 |
# python_targets_python2_7(-)?,python_single_target_python3_4(+)? |
54 |
# @CODE |
55 |
|
56 |
+# @ECLASS-VARIABLE: PYTHON_SINGLE_USEDEP |
57 |
+# @DESCRIPTION: |
58 |
+# This is an eclass-generated USE-dependency string which can be used to |
59 |
+# depend on another python-single-r1 package being built for the same |
60 |
+# Python implementations. |
61 |
+# |
62 |
+# If you need to depend on a multi-impl (python-r1) package, use |
63 |
+# python_gen_cond_dep with PYTHON_MULTI_USEDEP placeholder instead. |
64 |
+# |
65 |
+# Example use: |
66 |
+# @CODE |
67 |
+# RDEPEND="dev-python/foo[${PYTHON_SINGLE_USEDEP}]" |
68 |
+# @CODE |
69 |
+# |
70 |
+# Example value: |
71 |
+# @CODE |
72 |
+# python_single_target_python3_4(-)? |
73 |
+# @CODE |
74 |
+ |
75 |
+# @ECLASS-VARIABLE: PYTHON_MULTI_USEDEP |
76 |
+# @DESCRIPTION: |
77 |
+# This is a placeholder variable supported by python_gen_cond_dep, |
78 |
+# in order to depend on python-r1 packages built for the same Python |
79 |
+# implementations. |
80 |
+# |
81 |
+# Example use: |
82 |
+# @CODE |
83 |
+# RDEPEND="$(python_gen_cond_dep ' |
84 |
+# dev-python/foo[${PYTHON_MULTI_USEDEP}] |
85 |
+# ')" |
86 |
+# @CODE |
87 |
+# |
88 |
+# Example value: |
89 |
+# @CODE |
90 |
+# python_targets_python3_4(-) |
91 |
+# @CODE |
92 |
+ |
93 |
# @ECLASS-VARIABLE: PYTHON_REQUIRED_USE |
94 |
# @DESCRIPTION: |
95 |
# This is an eclass-generated required-use expression which ensures the following |
96 |
@@ -194,6 +239,8 @@ _python_single_set_globals() { |
97 |
local requse="^^ ( ${flags[*]} )" |
98 |
local optflags="${flags_mt[@]/%/(-)?},${unflags[@]/%/(-)},${flags[@]/%/(+)?}" |
99 |
local usedep="${optflags// /,}" |
100 |
+ local single_flags="${flags[@]/%/(-)?}" |
101 |
+ local single_usedep=${single_flags// /,} |
102 |
|
103 |
local deps= i PYTHON_PKG_DEP |
104 |
for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
105 |
@@ -234,11 +281,20 @@ _python_single_set_globals() { |
106 |
eerror "Now : ${usedep}" |
107 |
die "PYTHON_USEDEP integrity check failed" |
108 |
fi |
109 |
+ |
110 |
+ if [[ ${PYTHON_SINGLE_USEDEP} != "${single_usedep}" ]]; then |
111 |
+ eerror "PYTHON_SINGLE_USEDEP have changed between inherits!" |
112 |
+ eerror "Before: ${PYTHON_SINGLE_USEDEP}" |
113 |
+ eerror "Now : ${single_usedep}" |
114 |
+ die "PYTHON_SINGLE_USEDEP integrity check failed" |
115 |
+ fi |
116 |
else |
117 |
PYTHON_DEPS=${deps} |
118 |
PYTHON_REQUIRED_USE=${requse} |
119 |
PYTHON_USEDEP=${usedep} |
120 |
- readonly PYTHON_DEPS PYTHON_REQUIRED_USE PYTHON_USEDEP |
121 |
+ PYTHON_SINGLE_USEDEP=${single_usedep} |
122 |
+ readonly PYTHON_DEPS PYTHON_REQUIRED_USE PYTHON_USEDEP \ |
123 |
+ PYTHON_SINGLE_USEDEP |
124 |
fi |
125 |
} |
126 |
_python_single_set_globals |
127 |
@@ -248,12 +304,15 @@ if [[ ! ${_PYTHON_SINGLE_R1} ]]; then |
128 |
|
129 |
# @FUNCTION: _python_gen_usedep |
130 |
# @INTERNAL |
131 |
-# @USAGE: [<pattern>...] |
132 |
+# @USAGE: <-s|-u> [<pattern>...] |
133 |
# @DESCRIPTION: |
134 |
# Output a USE dependency string for Python implementations which |
135 |
# are both in PYTHON_COMPAT and match any of the patterns passed |
136 |
# as parameters to the function. |
137 |
# |
138 |
+# The first argument specifies USE-dependency type: '-s' for new-style |
139 |
+# PYTHON_SINGLE_USEDEP, '-u' for backwards-compatible PYTHON_USEDEP. |
140 |
+# |
141 |
# The patterns can be either fnmatch-style patterns (matched via bash |
142 |
# == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate |
143 |
# appropriately all enabled Python 2/3 implementations (alike |
144 |
@@ -265,14 +324,25 @@ if [[ ! ${_PYTHON_SINGLE_R1} ]]; then |
145 |
_python_gen_usedep() { |
146 |
debug-print-function ${FUNCNAME} "${@}" |
147 |
|
148 |
+ local mode=${1} |
149 |
+ shift |
150 |
local impl matches=() |
151 |
|
152 |
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
153 |
if _python_impl_matches "${impl}" "${@}"; then |
154 |
- matches+=( |
155 |
- "python_targets_${impl}(-)?" |
156 |
- "python_single_target_${impl}(+)?" |
157 |
- ) |
158 |
+ case ${mode} in |
159 |
+ -s) |
160 |
+ matches+=( |
161 |
+ "python_single_target_${impl}(-)?" |
162 |
+ ) |
163 |
+ ;; |
164 |
+ -u) |
165 |
+ matches+=( |
166 |
+ "python_targets_${impl}(-)?" |
167 |
+ "python_single_target_${impl}(+)?" |
168 |
+ ) |
169 |
+ ;; |
170 |
+ esac |
171 |
fi |
172 |
done |
173 |
|
174 |
@@ -319,7 +389,7 @@ python_gen_usedep() { |
175 |
if [[ ${EBUILD_PHASE} == setup ]]; then |
176 |
eqawarn "python_gen_usedep() is deprecated. Please use python_gen_cond_dep instead." |
177 |
fi |
178 |
- _python_gen_usedep "${@}" |
179 |
+ _python_gen_usedep -u "${@}" |
180 |
} |
181 |
|
182 |
# @FUNCTION: python_gen_useflags |
183 |
@@ -373,7 +443,8 @@ python_gen_useflags() { |
184 |
# to prevent accidental shell filename expansion. |
185 |
# |
186 |
# In order to enforce USE constraints on the packages, verbatim |
187 |
-# '${PYTHON_USEDEP}' (quoted!) may be placed in the dependency |
188 |
+# '${PYTHON_USEDEP}', '${PYTHON_SINGLE_USEDEP}' |
189 |
+# and '${PYTHON_MULTI_USEDEP}' (quoted!) may be placed in the dependency |
190 |
# specification. It will get expanded within the function into a proper |
191 |
# USE dependency string. |
192 |
# |
193 |
@@ -381,7 +452,7 @@ python_gen_useflags() { |
194 |
# @CODE |
195 |
# PYTHON_COMPAT=( python{2_7,3_{3,4}} pypy ) |
196 |
# RDEPEND="$(python_gen_cond_dep \ |
197 |
-# 'dev-python/unittest2[${PYTHON_USEDEP}]' python2_7 pypy )" |
198 |
+# 'dev-python/unittest2[${PYTHON_MULTI_USEDEP}]' python2_7 pypy )" |
199 |
# @CODE |
200 |
# |
201 |
# It will cause the variable to look like: |
202 |
@@ -405,11 +476,17 @@ python_gen_cond_dep() { |
203 |
# (since python_gen_usedep() will not return ${PYTHON_USEDEP} |
204 |
# the code is run at most once) |
205 |
if [[ ${dep} == *'${PYTHON_USEDEP}'* ]]; then |
206 |
- local usedep=$(_python_gen_usedep "${@}") |
207 |
+ local usedep=$(_python_gen_usedep -u "${@}") |
208 |
dep=${dep//\$\{PYTHON_USEDEP\}/${usedep}} |
209 |
fi |
210 |
+ if [[ ${dep} == *'${PYTHON_SINGLE_USEDEP}'* ]]; then |
211 |
+ local usedep=$(_python_gen_usedep -s "${@}") |
212 |
+ dep=${dep//\$\{PYTHON_SINGLE_USEDEP\}/${usedep}} |
213 |
+ fi |
214 |
+ local multi_usedep="python_targets_${impl}(-)" |
215 |
|
216 |
- matches+=( "python_single_target_${impl}? ( ${dep} )" ) |
217 |
+ matches+=( "python_single_target_${impl}? ( |
218 |
+ ${dep//\$\{PYTHON_MULTI_USEDEP\}/${multi_usedep}} )" ) |
219 |
fi |
220 |
done |
221 |
|
222 |
-- |
223 |
2.24.0 |