1 |
commit: 639e36f7af044be17849c1067a8cd9f831df9095 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Mar 17 10:37:02 2020 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Aug 7 10:39:56 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=639e36f7 |
7 |
|
8 |
python*-r1.eclass: Check for invalid impl patterns |
9 |
|
10 |
Check for invalid implementation patterns passed to python_gen* |
11 |
functions, python_setup, etc. Currently the functions silently ignore |
12 |
pattern mismatches which is fine for patterns matching historical |
13 |
implementations but also hides errors in patterns. |
14 |
|
15 |
After this change, each pattern must match at least one current or |
16 |
historical implementation. If no match is found, the function dies |
17 |
indicating developer's mistake. |
18 |
|
19 |
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> |
20 |
|
21 |
eclass/python-r1.eclass | 6 ++++++ |
22 |
eclass/python-single-r1.eclass | 4 ++++ |
23 |
eclass/python-utils-r1.eclass | 34 ++++++++++++++++++++++++++++++++++ |
24 |
3 files changed, 44 insertions(+) |
25 |
|
26 |
diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass |
27 |
index 8c3ff5b0809..40944684ec8 100644 |
28 |
--- a/eclass/python-r1.eclass |
29 |
+++ b/eclass/python-r1.eclass |
30 |
@@ -297,6 +297,7 @@ _python_gen_usedep() { |
31 |
|
32 |
local impl matches=() |
33 |
|
34 |
+ _python_verify_patterns "${@}" |
35 |
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
36 |
if _python_impl_matches "${impl}" "${@}"; then |
37 |
matches+=( |
38 |
@@ -380,6 +381,7 @@ python_gen_useflags() { |
39 |
|
40 |
local impl matches=() |
41 |
|
42 |
+ _python_verify_patterns "${@}" |
43 |
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
44 |
if _python_impl_matches "${impl}" "${@}"; then |
45 |
matches+=( "python_targets_${impl}" ) |
46 |
@@ -428,6 +430,7 @@ python_gen_cond_dep() { |
47 |
local dep=${1} |
48 |
shift |
49 |
|
50 |
+ _python_verify_patterns "${@}" |
51 |
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
52 |
if _python_impl_matches "${impl}" "${@}"; then |
53 |
# substitute ${PYTHON_USEDEP} if used |
54 |
@@ -486,6 +489,7 @@ python_gen_impl_dep() { |
55 |
local PYTHON_REQ_USE=${1} |
56 |
shift |
57 |
|
58 |
+ _python_verify_patterns "${@}" |
59 |
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
60 |
if _python_impl_matches "${impl}" "${@}"; then |
61 |
local PYTHON_PKG_DEP |
62 |
@@ -564,6 +568,7 @@ python_gen_any_dep() { |
63 |
shift |
64 |
|
65 |
local i PYTHON_PKG_DEP out= |
66 |
+ _python_verify_patterns "${@}" |
67 |
for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
68 |
if _python_impl_matches "${i}" "${@}"; then |
69 |
local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)" |
70 |
@@ -751,6 +756,7 @@ python_setup() { |
71 |
|
72 |
# (reverse iteration -- newest impl first) |
73 |
local found |
74 |
+ _python_verify_patterns "${@}" |
75 |
for (( i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- )); do |
76 |
local impl=${_PYTHON_SUPPORTED_IMPLS[i]} |
77 |
|
78 |
|
79 |
diff --git a/eclass/python-single-r1.eclass b/eclass/python-single-r1.eclass |
80 |
index 6fedc7cdf4e..dc032379cd8 100644 |
81 |
--- a/eclass/python-single-r1.eclass |
82 |
+++ b/eclass/python-single-r1.eclass |
83 |
@@ -291,6 +291,7 @@ _python_gen_usedep() { |
84 |
|
85 |
local impl matches=() |
86 |
|
87 |
+ _python_verify_patterns "${@}" |
88 |
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
89 |
if _python_impl_matches "${impl}" "${@}"; then |
90 |
matches+=( |
91 |
@@ -333,6 +334,7 @@ python_gen_useflags() { |
92 |
|
93 |
local impl matches=() |
94 |
|
95 |
+ _python_verify_patterns "${@}" |
96 |
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
97 |
if _python_impl_matches "${impl}" "${@}"; then |
98 |
matches+=( "python_single_target_${impl}" ) |
99 |
@@ -382,6 +384,7 @@ python_gen_cond_dep() { |
100 |
local dep=${1} |
101 |
shift |
102 |
|
103 |
+ _python_verify_patterns "${@}" |
104 |
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
105 |
if _python_impl_matches "${impl}" "${@}"; then |
106 |
# substitute ${PYTHON_SINGLE_USEDEP} if used |
107 |
@@ -445,6 +448,7 @@ python_gen_impl_dep() { |
108 |
local PYTHON_REQ_USE=${1} |
109 |
shift |
110 |
|
111 |
+ _python_verify_patterns "${@}" |
112 |
for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
113 |
if _python_impl_matches "${impl}" "${@}"; then |
114 |
local PYTHON_PKG_DEP |
115 |
|
116 |
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass |
117 |
index 9bad72a77e9..87cb662c64f 100644 |
118 |
--- a/eclass/python-utils-r1.eclass |
119 |
+++ b/eclass/python-utils-r1.eclass |
120 |
@@ -45,6 +45,18 @@ _PYTHON_ALL_IMPLS=( |
121 |
) |
122 |
readonly _PYTHON_ALL_IMPLS |
123 |
|
124 |
+# @ECLASS-VARIABLE: _PYTHON_HISTORICAL_IMPLS |
125 |
+# @INTERNAL |
126 |
+# @DESCRIPTION: |
127 |
+# All historical Python implementations that are no longer supported. |
128 |
+_PYTHON_HISTORICAL_IMPLS=( |
129 |
+ jython2_7 |
130 |
+ pypy pypy1_{8,9} pypy2_0 |
131 |
+ python2_{5,6} |
132 |
+ python3_{1,2,3,4,5} |
133 |
+) |
134 |
+readonly _PYTHON_HISTORICAL_IMPLS |
135 |
+ |
136 |
# @ECLASS-VARIABLE: PYTHON_COMPAT_NO_STRICT |
137 |
# @INTERNAL |
138 |
# @DESCRIPTION: |
139 |
@@ -89,6 +101,28 @@ _python_impl_supported() { |
140 |
esac |
141 |
} |
142 |
|
143 |
+# @FUNCTION: _python_verify_patterns |
144 |
+# @USAGE: <pattern>... |
145 |
+# @INTERNAL |
146 |
+# @DESCRIPTION: |
147 |
+# Verify whether the patterns passed to the eclass function are correct |
148 |
+# (i.e. can match any valid implementation). Dies on wrong pattern. |
149 |
+_python_verify_patterns() { |
150 |
+ debug-print-function ${FUNCNAME} "${@}" |
151 |
+ |
152 |
+ local impl pattern |
153 |
+ for pattern; do |
154 |
+ [[ ${pattern} == -[23] ]] && continue |
155 |
+ |
156 |
+ for impl in "${_PYTHON_ALL_IMPLS[@]}" "${_PYTHON_HISTORICAL_IMPLS[@]}" |
157 |
+ do |
158 |
+ [[ ${impl} == ${pattern/./_} ]] && continue 2 |
159 |
+ done |
160 |
+ |
161 |
+ die "Invalid implementation pattern: ${pattern}" |
162 |
+ done |
163 |
+} |
164 |
+ |
165 |
# @FUNCTION: _python_set_impls |
166 |
# @INTERNAL |
167 |
# @DESCRIPTION: |