Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: python@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH] python*-r1.eclass: Check for invalid impl patterns
Date: Tue, 17 Mar 2020 12:03:43
Message-Id: 20200317120311.94407-1-mgorny@gentoo.org
1 Check for invalid implementation patterns passed to python_gen*
2 functions, python_setup, etc. Currently the functions silently ignore
3 pattern mismatches which is fine for patterns matching historical
4 implementations but also hides errors in patterns.
5
6 After this change, each pattern must match at least one current or
7 historical implementation. If no match is found, the function dies
8 indicating developer's mistake.
9
10 Signed-off-by: Michał Górny <mgorny@g.o>
11 ---
12 eclass/python-r1.eclass | 6 ++++++
13 eclass/python-single-r1.eclass | 4 ++++
14 eclass/python-utils-r1.eclass | 34 ++++++++++++++++++++++++++++++++++
15 3 files changed, 44 insertions(+)
16
17 diff --git a/eclass/python-r1.eclass b/eclass/python-r1.eclass
18 index 960fed8c451a..5eebd3c79750 100644
19 --- a/eclass/python-r1.eclass
20 +++ b/eclass/python-r1.eclass
21 @@ -293,6 +293,7 @@ _python_gen_usedep() {
22
23 local impl matches=()
24
25 + _python_verify_patterns "${@}"
26 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
27 if _python_impl_matches "${impl}" "${@}"; then
28 matches+=(
29 @@ -376,6 +377,7 @@ python_gen_useflags() {
30
31 local impl matches=()
32
33 + _python_verify_patterns "${@}"
34 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
35 if _python_impl_matches "${impl}" "${@}"; then
36 matches+=( "python_targets_${impl}" )
37 @@ -424,6 +426,7 @@ python_gen_cond_dep() {
38 local dep=${1}
39 shift
40
41 + _python_verify_patterns "${@}"
42 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
43 if _python_impl_matches "${impl}" "${@}"; then
44 # substitute ${PYTHON_USEDEP} if used
45 @@ -482,6 +485,7 @@ python_gen_impl_dep() {
46 local PYTHON_REQ_USE=${1}
47 shift
48
49 + _python_verify_patterns "${@}"
50 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
51 if _python_impl_matches "${impl}" "${@}"; then
52 local PYTHON_PKG_DEP
53 @@ -560,6 +564,7 @@ python_gen_any_dep() {
54 shift
55
56 local i PYTHON_PKG_DEP out=
57 + _python_verify_patterns "${@}"
58 for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
59 if _python_impl_matches "${i}" "${@}"; then
60 local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)"
61 @@ -745,6 +750,7 @@ python_setup() {
62
63 # (reverse iteration -- newest impl first)
64 local found
65 + _python_verify_patterns "${@}"
66 for (( i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- )); do
67 local impl=${_PYTHON_SUPPORTED_IMPLS[i]}
68
69 diff --git a/eclass/python-single-r1.eclass b/eclass/python-single-r1.eclass
70 index f9e26e7c334f..98ab761f39b8 100644
71 --- a/eclass/python-single-r1.eclass
72 +++ b/eclass/python-single-r1.eclass
73 @@ -280,6 +280,7 @@ _python_gen_usedep() {
74
75 local impl matches=()
76
77 + _python_verify_patterns "${@}"
78 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
79 if _python_impl_matches "${impl}" "${@}"; then
80 matches+=(
81 @@ -322,6 +323,7 @@ python_gen_useflags() {
82
83 local impl matches=()
84
85 + _python_verify_patterns "${@}"
86 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
87 if _python_impl_matches "${impl}" "${@}"; then
88 matches+=( "python_single_target_${impl}" )
89 @@ -371,6 +373,7 @@ python_gen_cond_dep() {
90 local dep=${1}
91 shift
92
93 + _python_verify_patterns "${@}"
94 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
95 if _python_impl_matches "${impl}" "${@}"; then
96 # substitute ${PYTHON_SINGLE_USEDEP} if used
97 @@ -433,6 +436,7 @@ python_gen_impl_dep() {
98 local PYTHON_REQ_USE=${1}
99 shift
100
101 + _python_verify_patterns "${@}"
102 for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
103 if _python_impl_matches "${impl}" "${@}"; then
104 local PYTHON_PKG_DEP
105 diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
106 index f144cbbb1279..a3257260f7f0 100644
107 --- a/eclass/python-utils-r1.eclass
108 +++ b/eclass/python-utils-r1.eclass
109 @@ -45,6 +45,18 @@ _PYTHON_ALL_IMPLS=(
110 )
111 readonly _PYTHON_ALL_IMPLS
112
113 +# @ECLASS-VARIABLE: _PYTHON_HISTORICAL_IMPLS
114 +# @INTERNAL
115 +# @DESCRIPTION:
116 +# All historical Python implementations that are no longer supported.
117 +_PYTHON_HISTORICAL_IMPLS=(
118 + jython2_7
119 + pypy pypy1_{8,9} pypy2_0
120 + python2_{5,6}
121 + python3_{1,2,3,4,5}
122 +)
123 +readonly _PYTHON_HISTORICAL_IMPLS
124 +
125 # @ECLASS-VARIABLE: PYTHON_COMPAT_NO_STRICT
126 # @INTERNAL
127 # @DESCRIPTION:
128 @@ -89,6 +101,28 @@ _python_impl_supported() {
129 esac
130 }
131
132 +# @FUNCTION: _python_verify_patterns
133 +# @USAGE: <pattern>...
134 +# @INTERNAL
135 +# @DESCRIPTION:
136 +# Verify whether the patterns passed to the eclass function are correct
137 +# (i.e. can match any valid implementation). Dies on wrong pattern.
138 +_python_verify_patterns() {
139 + debug-print-function ${FUNCNAME} "${@}"
140 +
141 + local impl pattern
142 + for pattern; do
143 + [[ ${pattern} == -[23] ]] && continue
144 +
145 + for impl in "${_PYTHON_ALL_IMPLS[@]}" "${_PYTHON_HISTORICAL_IMPLS[@]}"
146 + do
147 + [[ ${impl} == ${pattern/./_} ]] && continue 2
148 + done
149 +
150 + die "Invalid implementation pattern: ${pattern}"
151 + done
152 +}
153 +
154 # @FUNCTION: _python_set_impls
155 # @INTERNAL
156 # @DESCRIPTION:
157 --
158 2.25.1