Gentoo Archives: gentoo-dev

From: Andreas Sturmlechner <asturm@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] [PATCH v2 4/5] check-reqs.eclass: Prefix internal functions w/ underscore
Date: Fri, 23 Jul 2021 06:58:06
Message-Id: 4153190.UPlyArG6xL@tuxbook
In Reply to: [gentoo-dev] [PATCH v2 3/5] check-reqs.eclass: Drop obsolete check_reqs(), errored out for >3yrs by Andreas Sturmlechner
1 Signed-off-by: Andreas Sturmlechner <asturm@g.o>
2 ---
3 eclass/check-reqs.eclass | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
4 1 file changed, 123 insertions(+), 17 deletions(-)
5
6 diff --git a/eclass/check-reqs.eclass b/eclass/check-reqs.eclass
7 index 6b11794fbb2..39e4bad1363 100644
8 --- a/eclass/check-reqs.eclass
9 +++ b/eclass/check-reqs.eclass
10 @@ -76,9 +76,9 @@ _CHECK_REQS_ECLASS=1
11 check-reqs_pkg_setup() {
12 debug-print-function ${FUNCNAME} "$@"
13
14 - check-reqs_prepare
15 - check-reqs_run
16 - check-reqs_output
17 + _check-reqs_prepare
18 + _check-reqs_run
19 + _check-reqs_output
20 }
21
22 # @FUNCTION: check-reqs_pkg_pretend
23 @@ -95,6 +95,16 @@ check-reqs_pkg_pretend() {
24 # @DESCRIPTION:
25 # Internal function that checks the variables that should be defined.
26 check-reqs_prepare() {
27 + [[ ${EAPI} == [67] ]] ||
28 + die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
29 + _check-reqs_prepare "$@"
30 +}
31 +
32 +# @FUNCTION: _check-reqs_prepare
33 +# @INTERNAL
34 +# @DESCRIPTION:
35 +# Internal function that checks the variables that should be defined.
36 +_check-reqs_prepare() {
37 debug-print-function ${FUNCNAME} "$@"
38
39 if [[ -z ${CHECKREQS_MEMORY} &&
40 @@ -112,6 +122,16 @@ check-reqs_prepare() {
41 # @DESCRIPTION:
42 # Internal function that runs the check based on variable settings.
43 check-reqs_run() {
44 + [[ ${EAPI} == [67] ]] ||
45 + die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
46 + _check-reqs_run "$@"
47 +}
48 +
49 +# @FUNCTION: _check-reqs_run
50 +# @INTERNAL
51 +# @DESCRIPTION:
52 +# Internal function that runs the check based on variable settings.
53 +_check-reqs_run() {
54 debug-print-function ${FUNCNAME} "$@"
55
56 # some people are *censored*
57 @@ -119,23 +139,23 @@ check-reqs_run() {
58
59 if [[ ${MERGE_TYPE} != binary ]]; then
60 [[ -n ${CHECKREQS_MEMORY} ]] && \
61 - check-reqs_memory \
62 + _check-reqs_memory \
63 ${CHECKREQS_MEMORY}
64
65 [[ -n ${CHECKREQS_DISK_BUILD} ]] && \
66 - check-reqs_disk \
67 + _check-reqs_disk \
68 "${T}" \
69 "${CHECKREQS_DISK_BUILD}"
70 fi
71
72 if [[ ${MERGE_TYPE} != buildonly ]]; then
73 [[ -n ${CHECKREQS_DISK_USR} ]] && \
74 - check-reqs_disk \
75 + _check-reqs_disk \
76 "${EROOT%/}/usr" \
77 "${CHECKREQS_DISK_USR}"
78
79 [[ -n ${CHECKREQS_DISK_VAR} ]] && \
80 - check-reqs_disk \
81 + _check-reqs_disk \
82 "${EROOT%/}/var" \
83 "${CHECKREQS_DISK_VAR}"
84 fi
85 @@ -147,6 +167,17 @@ check-reqs_run() {
86 # Internal function that returns number in KiB.
87 # Returns 1024**2 for 1G or 1024**3 for 1T.
88 check-reqs_get_kibibytes() {
89 + [[ ${EAPI} == [67] ]] ||
90 + die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
91 + _check-reqs_get_kibibytes "$@"
92 +}
93 +
94 +# @FUNCTION: _check-reqs_get_kibibytes
95 +# @INTERNAL
96 +# @DESCRIPTION:
97 +# Internal function that returns number in KiB.
98 +# Returns 1024**2 for 1G or 1024**3 for 1T.
99 +_check-reqs_get_kibibytes() {
100 debug-print-function ${FUNCNAME} "$@"
101
102 [[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
103 @@ -170,6 +201,17 @@ check-reqs_get_kibibytes() {
104 # Internal function that returns the numerical value without the unit.
105 # Returns "1" for "1G" or "150" for "150T".
106 check-reqs_get_number() {
107 + [[ ${EAPI} == [67] ]] ||
108 + die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
109 + _check-reqs_get_number "$@"
110 +}
111 +
112 +# @FUNCTION: _check-reqs_get_number
113 +# @INTERNAL
114 +# @DESCRIPTION:
115 +# Internal function that returns the numerical value without the unit.
116 +# Returns "1" for "1G" or "150" for "150T".
117 +_check-reqs_get_number() {
118 debug-print-function ${FUNCNAME} "$@"
119
120 [[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
121 @@ -186,6 +228,17 @@ check-reqs_get_number() {
122 # Internal function that returns the unit without the numerical value.
123 # Returns "GiB" for "1G" or "TiB" for "150T".
124 check-reqs_get_unit() {
125 + [[ ${EAPI} == [67] ]] ||
126 + die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
127 + _check-reqs_get_unit "$@"
128 +}
129 +
130 +# @FUNCTION: _check-reqs_get_unit
131 +# @INTERNAL
132 +# @DESCRIPTION:
133 +# Internal function that returns the unit without the numerical value.
134 +# Returns "GiB" for "1G" or "TiB" for "150T".
135 +_check-reqs_get_unit() {
136 debug-print-function ${FUNCNAME} "$@"
137
138 [[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
139 @@ -208,6 +261,17 @@ check-reqs_get_unit() {
140 # Internal function that prints the warning and dies if required based on
141 # the test results.
142 check-reqs_output() {
143 + [[ ${EAPI} == [67] ]] ||
144 + die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
145 + _check-reqs_get_unit "$@"
146 +}
147 +
148 +# @FUNCTION: _check-reqs_output
149 +# @INTERNAL
150 +# @DESCRIPTION:
151 +# Internal function that prints the warning and dies if required based on
152 +# the test results.
153 +_check-reqs_output() {
154 debug-print-function ${FUNCNAME} "$@"
155
156 local msg="ewarn"
157 @@ -230,6 +294,16 @@ check-reqs_output() {
158 # @DESCRIPTION:
159 # Internal function that checks size of RAM.
160 check-reqs_memory() {
161 + [[ ${EAPI} == [67] ]] ||
162 + die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
163 + _check-reqs_memory "$@"
164 +}
165 +
166 +# @FUNCTION: _check-reqs_memory
167 +# @INTERNAL
168 +# @DESCRIPTION:
169 +# Internal function that checks size of RAM.
170 +_check-reqs_memory() {
171 debug-print-function ${FUNCNAME} "$@"
172
173 [[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
174 @@ -238,7 +312,7 @@ check-reqs_memory() {
175 local actual_memory
176 local actual_swap
177
178 - check-reqs_start_phase \
179 + _check-reqs_start_phase \
180 ${size} \
181 "RAM"
182
183 @@ -254,17 +328,17 @@ check-reqs_memory() {
184 | sed -e 's/^[^:=]*[:=][[:space:]]*//')
185 fi
186 if [[ -n ${actual_memory} ]] ; then
187 - if [[ ${actual_memory} -ge $(check-reqs_get_kibibytes ${size}) ]] ; then
188 + if [[ ${actual_memory} -ge $(_check-reqs_get_kibibytes ${size}) ]] ; then
189 eend 0
190 elif [[ -n ${actual_swap} && $((${actual_memory} + ${actual_swap})) \
191 - -ge $(check-reqs_get_kibibytes ${size}) ]] ; then
192 + -ge $(_check-reqs_get_kibibytes ${size}) ]] ; then
193 ewarn "Amount of main memory is insufficient, but amount"
194 ewarn "of main memory combined with swap is sufficient."
195 ewarn "Build process may make computer very slow!"
196 eend 0
197 else
198 eend 1
199 - check-reqs_unsatisfied \
200 + _check-reqs_unsatisfied \
201 ${size} \
202 "RAM"
203 fi
204 @@ -279,6 +353,16 @@ check-reqs_memory() {
205 # @DESCRIPTION:
206 # Internal function that checks space on the harddrive.
207 check-reqs_disk() {
208 + [[ ${EAPI} == [67] ]] ||
209 + die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
210 + _check-reqs_disk "$@"
211 +}
212 +
213 +# @FUNCTION: _check-reqs_disk
214 +# @INTERNAL
215 +# @DESCRIPTION:
216 +# Internal function that checks space on the harddrive.
217 +_check-reqs_disk() {
218 debug-print-function ${FUNCNAME} "$@"
219
220 [[ -z ${2} ]] && die "Usage: ${FUNCNAME} [path] [size]"
221 @@ -287,16 +371,16 @@ check-reqs_disk() {
222 local size=${2}
223 local space_kbi
224
225 - check-reqs_start_phase \
226 + _check-reqs_start_phase \
227 ${size} \
228 "disk space at \"${path}\""
229
230 space_kbi=$(df -Pk "${1}" 2>/dev/null | awk 'FNR == 2 {print $4}')
231
232 if [[ $? == 0 && -n ${space_kbi} ]] ; then
233 - if [[ ${space_kbi} -lt $(check-reqs_get_kibibytes ${size}) ]] ; then
234 + if [[ ${space_kbi} -lt $(_check-reqs_get_kibibytes ${size}) ]] ; then
235 eend 1
236 - check-reqs_unsatisfied \
237 + _check-reqs_unsatisfied \
238 ${size} \
239 "disk space at \"${path}\""
240 else
241 @@ -313,13 +397,23 @@ check-reqs_disk() {
242 # @DESCRIPTION:
243 # Internal function that inform about started check
244 check-reqs_start_phase() {
245 + [[ ${EAPI} == [67] ]] ||
246 + die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
247 + _check-reqs_start_phase "$@"
248 +}
249 +
250 +# @FUNCTION: _check-reqs_start_phase
251 +# @INTERNAL
252 +# @DESCRIPTION:
253 +# Internal function that inform about started check
254 +_check-reqs_start_phase() {
255 debug-print-function ${FUNCNAME} "$@"
256
257 [[ -z ${2} ]] && die "Usage: ${FUNCNAME} [size] [location]"
258
259 local size=${1}
260 local location=${2}
261 - local sizeunit="$(check-reqs_get_number ${size}) $(check-reqs_get_unit ${size})"
262 + local sizeunit="$(_check-reqs_get_number ${size}) $(_check-reqs_get_unit ${size})"
263
264 ebegin "Checking for at least ${sizeunit} ${location}"
265 }
266 @@ -327,10 +421,22 @@ check-reqs_start_phase() {
267 # @FUNCTION: check-reqs_unsatisfied
268 # @INTERNAL
269 # @DESCRIPTION:
270 -# Internal function that inform about check result.
271 +# Internal function that informs about check result.
272 # It has different output between pretend and setup phase,
273 # where in pretend phase it is fatal.
274 check-reqs_unsatisfied() {
275 + [[ ${EAPI} == [67] ]] ||
276 + die "Internal function ${FUNCNAME} is not available in EAPI ${EAPI}."
277 + _check-reqs_unsatisfied "$@"
278 +}
279 +
280 +# @FUNCTION: _check-reqs_unsatisfied
281 +# @INTERNAL
282 +# @DESCRIPTION:
283 +# Internal function that informs about check result.
284 +# It has different output between pretend and setup phase,
285 +# where in pretend phase it is fatal.
286 +_check-reqs_unsatisfied() {
287 debug-print-function ${FUNCNAME} "$@"
288
289 [[ -z ${2} ]] && die "Usage: ${FUNCNAME} [size] [location]"
290 @@ -338,7 +444,7 @@ check-reqs_unsatisfied() {
291 local msg="ewarn"
292 local size=${1}
293 local location=${2}
294 - local sizeunit="$(check-reqs_get_number ${size}) $(check-reqs_get_unit ${size})"
295 + local sizeunit="$(_check-reqs_get_number ${size}) $(_check-reqs_get_unit ${size})"
296
297 [[ ${EBUILD_PHASE} == "pretend" && -z ${I_KNOW_WHAT_I_AM_DOING} ]] && msg="eerror"
298 ${msg} "There is NOT at least ${sizeunit} ${location}"

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies