1 |
Deprecate python_gen_usedep() in favor of python_gen_cond_dep(). |
2 |
The latter is a newer API that generates full USE-conditional blocks |
3 |
rather than pure USE-dependency strings. As such, it can replace all |
4 |
uses of the former, and is safer to use in general. In particular: |
5 |
|
6 |
dev-python/foo[$(python_gen_usedep -2)] |
7 |
dev-python/bar[$(python_gen_usedep -2)] |
8 |
|
9 |
installs the dependency (with no implementation match enforced) even |
10 |
if there's no python2 implementation enabled, while: |
11 |
|
12 |
$(python_gen_cond_dep ' |
13 |
dev-python/foo[${PYTHON_USEDEP}] |
14 |
dev-python/bar[${PYTHON_USEDEP}] |
15 |
' -2) |
16 |
|
17 |
installs it only if there's at least one implementation requiring it. |
18 |
|
19 |
Since the functions are used in global scope only, a deprecation warning |
20 |
is emitted only once, during the sourcing for pkg_setup phase. This |
21 |
avoids having it output during metadata cache regeneration. |
22 |
|
23 |
Signed-off-by: Michał Górny <mgorny@g.o> |
24 |
--- |
25 |
eclass/python-r1.eclass | 59 +++++++++++++++++++++++++--------- |
26 |
eclass/python-single-r1.eclass | 59 +++++++++++++++++++++++++--------- |
27 |
2 files changed, 88 insertions(+), 30 deletions(-) |
28 |
|
29 |
diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass |
30 |
index 7665edbd87e3..1d23cfa9177c 100644 |
31 |
--- a/eclass/python-r1.eclass |
32 |
+++ b/eclass/python-r1.eclass |
33 |
@@ -276,9 +276,47 @@ _python_validate_useflags() { |
34 |
die "No supported Python implementation in PYTHON_TARGETS." |
35 |
} |
36 |
|
37 |
+# @FUNCTION: _python_gen_usedep |
38 |
+# @INTERNAL |
39 |
+# @USAGE: <pattern> [...] |
40 |
+# @DESCRIPTION: |
41 |
+# Output a USE dependency string for Python implementations which |
42 |
+# are both in PYTHON_COMPAT and match any of the patterns passed |
43 |
+# as parameters to the function. |
44 |
+# |
45 |
+# The patterns can be either fnmatch-style patterns (matched via bash |
46 |
+# == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate |
47 |
+# appropriately all enabled Python 2/3 implementations (alike |
48 |
+# python_is_python3). Remember to escape or quote the fnmatch patterns |
49 |
+# to prevent accidental shell filename expansion. |
50 |
+# |
51 |
+# This is an internal function used to implement python_gen_cond_dep |
52 |
+# and deprecated python_gen_usedep. |
53 |
+_python_gen_usedep() { |
54 |
+ debug-print-function ${FUNCNAME} "${@}" |
55 |
+ |
56 |
+ local impl matches=() |
57 |
+ |
58 |
+ for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
59 |
+ if _python_impl_matches "${impl}" "${@}"; then |
60 |
+ matches+=( |
61 |
+ "python_targets_${impl}(-)?" |
62 |
+ "-python_single_target_${impl}(-)" |
63 |
+ ) |
64 |
+ fi |
65 |
+ done |
66 |
+ |
67 |
+ [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}" |
68 |
+ |
69 |
+ local out=${matches[@]} |
70 |
+ echo "${out// /,}" |
71 |
+} |
72 |
+ |
73 |
# @FUNCTION: python_gen_usedep |
74 |
# @USAGE: <pattern> [...] |
75 |
# @DESCRIPTION: |
76 |
+# DEPRECATED. Please use python_gen_cond_dep instead. |
77 |
+# |
78 |
# Output a USE dependency string for Python implementations which |
79 |
# are both in PYTHON_COMPAT and match any of the patterns passed |
80 |
# as parameters to the function. |
81 |
@@ -306,21 +344,12 @@ _python_validate_useflags() { |
82 |
python_gen_usedep() { |
83 |
debug-print-function ${FUNCNAME} "${@}" |
84 |
|
85 |
- local impl matches=() |
86 |
- |
87 |
- for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
88 |
- if _python_impl_matches "${impl}" "${@}"; then |
89 |
- matches+=( |
90 |
- "python_targets_${impl}(-)?" |
91 |
- "-python_single_target_${impl}(-)" |
92 |
- ) |
93 |
- fi |
94 |
- done |
95 |
- |
96 |
- [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}" |
97 |
- |
98 |
- local out=${matches[@]} |
99 |
- echo "${out// /,}" |
100 |
+ # output only once, during some reasonable phase |
101 |
+ # (avoid spamming cache regen runs) |
102 |
+ if [[ ${EBUILD_PHASE} == setup ]]; then |
103 |
+ eqawarn "python_gen_usedep() is deprecated. Please use python_gen_cond_dep instead." |
104 |
+ fi |
105 |
+ _python_gen_usedep "${@}" |
106 |
} |
107 |
|
108 |
# @FUNCTION: python_gen_useflags |
109 |
diff --git a/eclass/python-single-r1.eclass b/eclass/python-single-r1.eclass |
110 |
index 8ac17b7815e2..6abaf1923d20 100644 |
111 |
--- a/eclass/python-single-r1.eclass |
112 |
+++ b/eclass/python-single-r1.eclass |
113 |
@@ -265,9 +265,47 @@ unset -f _python_single_set_globals |
114 |
|
115 |
if [[ ! ${_PYTHON_SINGLE_R1} ]]; then |
116 |
|
117 |
+# @FUNCTION: _python_gen_usedep |
118 |
+# @INTERNAL |
119 |
+# @USAGE: <pattern> [...] |
120 |
+# @DESCRIPTION: |
121 |
+# Output a USE dependency string for Python implementations which |
122 |
+# are both in PYTHON_COMPAT and match any of the patterns passed |
123 |
+# as parameters to the function. |
124 |
+# |
125 |
+# The patterns can be either fnmatch-style patterns (matched via bash |
126 |
+# == operator against PYTHON_COMPAT values) or '-2' / '-3' to indicate |
127 |
+# appropriately all enabled Python 2/3 implementations (alike |
128 |
+# python_is_python3). Remember to escape or quote the fnmatch patterns |
129 |
+# to prevent accidental shell filename expansion. |
130 |
+# |
131 |
+# This is an internal function used to implement python_gen_cond_dep |
132 |
+# and deprecated python_gen_usedep. |
133 |
+_python_gen_usedep() { |
134 |
+ debug-print-function ${FUNCNAME} "${@}" |
135 |
+ |
136 |
+ local impl matches=() |
137 |
+ |
138 |
+ for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
139 |
+ if _python_impl_matches "${impl}" "${@}"; then |
140 |
+ matches+=( |
141 |
+ "python_targets_${impl}(-)?" |
142 |
+ "python_single_target_${impl}(+)?" |
143 |
+ ) |
144 |
+ fi |
145 |
+ done |
146 |
+ |
147 |
+ [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}" |
148 |
+ |
149 |
+ local out=${matches[@]} |
150 |
+ echo "${out// /,}" |
151 |
+} |
152 |
+ |
153 |
# @FUNCTION: python_gen_usedep |
154 |
# @USAGE: <pattern> [...] |
155 |
# @DESCRIPTION: |
156 |
+# DEPRECATED. Please use python_gen_cond_dep instead. |
157 |
+# |
158 |
# Output a USE dependency string for Python implementations which |
159 |
# are both in PYTHON_COMPAT and match any of the patterns passed |
160 |
# as parameters to the function. |
161 |
@@ -295,21 +333,12 @@ if [[ ! ${_PYTHON_SINGLE_R1} ]]; then |
162 |
python_gen_usedep() { |
163 |
debug-print-function ${FUNCNAME} "${@}" |
164 |
|
165 |
- local impl matches=() |
166 |
- |
167 |
- for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
168 |
- if _python_impl_matches "${impl}" "${@}"; then |
169 |
- matches+=( |
170 |
- "python_targets_${impl}(-)?" |
171 |
- "python_single_target_${impl}(+)?" |
172 |
- ) |
173 |
- fi |
174 |
- done |
175 |
- |
176 |
- [[ ${matches[@]} ]] || die "No supported implementations match python_gen_usedep patterns: ${@}" |
177 |
- |
178 |
- local out=${matches[@]} |
179 |
- echo "${out// /,}" |
180 |
+ # output only once, during some reasonable phase |
181 |
+ # (avoid spamming cache regen runs) |
182 |
+ if [[ ${EBUILD_PHASE} == setup ]]; then |
183 |
+ eqawarn "python_gen_usedep() is deprecated. Please use python_gen_cond_dep instead." |
184 |
+ fi |
185 |
+ _python_gen_usedep "${@}" |
186 |
} |
187 |
|
188 |
# @FUNCTION: python_gen_useflags |
189 |
-- |
190 |
2.24.0 |