Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: scarabeus@g.o
Subject: Re: [gentoo-dev] [RFC] check-reqs.eclass.patch
Date: Tue, 30 Aug 2011 07:34:10
Message-Id: 20110830093509.0e6eca66@pomiocik.lan
In Reply to: [gentoo-dev] [RFC] check-reqs.eclass.patch by "Tomáš Chvátal"
1 On Tue, 30 Aug 2011 09:11:40 +0200
2 Tomáš Chvátal <scarabeus@g.o> wrote:
3
4 > @@ -66,80 +52,234 @@
5 >
6 > # @ECLASS-VARIABLE: CHECKREQS_MEMORY
7 > # @DESCRIPTION:
8 > -# How much RAM is needed in MB?
9 > +# @DEAULT_UNSET
10 > +# How much RAM is needed?
11
12 Typo. Also, shouldn't defaults go before @DESCRIPTION: ?
13
14 > # @ECLASS-VARIABLE: CHECKREQS_DISK_BUILD
15 > # @DESCRIPTION:
16 > -# How much diskspace is needed to build the package? In MB
17 > +# @DEAULT_UNSET
18 > +# How much diskspace is needed to build the package?
19
20 Ditto.
21
22 > # @ECLASS-VARIABLE: CHECKREQS_DISK_USR
23 > # @DESCRIPTION:
24 > -# How much space in /usr is needed to install the package? In MB
25 > +# @DEAULT_UNSET
26 > +# How much space in /usr is needed to install the package?
27
28 Ditto.
29
30 > # @ECLASS-VARIABLE: CHECKREQS_DISK_VAR
31 > # @DESCRIPTION:
32 > -# How much space is needed in /var? In MB
33 > +# @DEAULT_UNSET
34 > +# How much space is needed in /var?
35
36 Ditto.
37
38 > +CHECKREQS_EXPORTED_FUNCTIONS="pkg_setup"
39 > +case "${EAPI:-0}" in
40 > + 0|1|2|3) ;;
41 > + 4) CHECKREQS_EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS}
42 > pkg_pretend" ;;
43
44 Not the same var.
45
46 > + *) die "EAPI=${EAPI} is not supported" ;;
47 > +esac
48
49 CHECKREQS_EXPORTED_FUNCTIONS is not used anywhere.
50
51 > # @FUNCTION: check_reqs
52 > # @DESCRIPTION:
53 > -# Checks the requirements given in the specific variables. If not
54 > reached, -# either prints a warning or dies.
55 > +# Obsolete function executing all the checks and priting out results
56 > check_reqs() {
57 > - [[ -n "${1}" ]] && die "Usage: check_reqs"
58 > + debug-print-function ${FUNCNAME} "$@"
59 > +
60 > + echo
61 > + ewarn "QA: Package calling old ${FUNCNAME} function."
62 > + ewarn "QA: Please file a bug against the package."
63 > + ewarn "QA: It should call check-reqs_pkg_pretend and
64 > check-reqs_pkg_setup"
65 > + ewarn "QA: and possibly use EAPI=4 or later."
66 > + echo
67 > +
68 > + check-reqs_pkg_setup "$@"
69 > +}
70 >
71 > - export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE=""
72 > - if [[ "$CHECKREQS_ACTION" != "ignore" ]] ; then
73 > - [[ -n "$CHECKREQS_MEMORY" ]] && check_build_memory
74 > - [[ -n "$CHECKREQS_DISK_BUILD" ]] && check_build_disk
75 > \
76 > - "${T}" "${CHECKREQS_DISK_BUILD}"
77 > - [[ -n "$CHECKREQS_DISK_USR" ]] && check_build_disk \
78 > - "${ROOT}/usr" "${CHECKREQS_DISK_USR}"
79 > - [[ -n "$CHECKREQS_DISK_VAR" ]] && check_build_disk \
80 > - "${ROOT}/var" "${CHECKREQS_DISK_VAR}"
81 > +# @FUNCTION: check-reqs_pkg_setup
82 > +# @DESCRIPTION:
83 > +# Exported function running the resources checks in pkg_setup phase.
84 > +# It should be run in both phases to ensure condition changes between
85 > +# pkg_pretend and pkg_setup won't affect the build.
86 > +check-reqs_pkg_setup() {
87 > + debug-print-function ${FUNCNAME} "$@"
88 > +
89 > + check-reqs_prepare
90 > + check-reqs_run
91 > + check-reqs_output
92 > +}
93 > +
94 > +# @FUNCTION: check-reqs_pkg_pretend
95 > +# @DESCRIPTION:
96 > +# Exported function running the resources checks in pkg_pretend
97 > phase. +check-reqs_pkg_pretend() {
98 > + debug-print-function ${FUNCNAME} "$@"
99 > +
100 > + check-reqs_pkg_setup "$@"
101 > +}
102 > +
103 > +# @FUNCTION: check-reqs_prepare
104 > +# @DESCRIPTION:
105 > +# Internal function that checks the variables that should be defined.
106 > +check-reqs_prepare() {
107 > + debug-print-function ${FUNCNAME} "$@"
108 > +
109 > + if [[ -z ${CHECKREQS_MEMORY} &&
110 > + -z ${CHECKREQS_DISK_BUILD} &&
111 > + -z ${CHECKREQS_DISK_USR} &&
112 > + -z ${CHECKREQS_DISK_VAR} ]]; then
113 > + eerror "Set some check-reqs eclass variables if you
114 > want to use it."
115 > + eerror "If you are user and see this message fill a
116 > bug against the package."
117 > + die "${FUNCNAME}: check-reqs eclass called but not
118 > actualy used!" fi
119 > +}
120 >
121 > - if [[ -n "${CHECKREQS_NEED_SLEEP}" ]] ; then
122 > - echo
123 > - ewarn "Bad things may happen! You may abort the
124 > build by pressing ctrl+c in"
125 > - ewarn "the next 15 seconds."
126 > - ewarn " "
127 > - einfo "To make this kind of warning a fatal error,
128 > add a line to /etc/make.conf"
129 > - einfo "setting CHECKREQS_ACTION=\"error\". To skip
130 > build requirements checking,"
131 > - einfo "set CHECKREQS_ACTION=\"ignore\"."
132 > - epause 15
133 > +# @FUNCTION: check-reqs_run
134 > +# @DESCRIPTION:
135 > +# Internal function that runs the check based on variable settings.
136 > +check-reqs_run() {
137 > + debug-print-function ${FUNCNAME} "$@"
138 > +
139 > + # some people are *censored*
140 > + unset CHECKREQS_FAILED
141 > +
142 > + [[ -n ${CHECKREQS_MEMORY} ]] && \
143 > + check-reqs_memory \
144 > + ${CHECKREQS_MEMORY}
145 > +
146 > + [[ -n ${CHECKREQS_DISK_BUILD} ]] && \
147 > + check-reqs_disk \
148 > + "${T}" \
149 > + "${CHECKREQS_DISK_BUILD}"
150
151 Why not WORKDIR?
152
153 > +
154 > + [[ -n ${CHECKREQS_DISK_USR} ]] && \
155 > + check-reqs_disk \
156 > + "${EROOT}/usr" \
157 > + "${CHECKREQS_DISK_USR}"
158 > +
159 > + [[ -n ${CHECKREQS_DISK_VAR} ]] && \
160 > + check-reqs_disk \
161 > + "${EROOT}/var" \
162 > + "${CHECKREQS_DISK_VAR}"
163 > +}
164
165 Also, it may be a good idea to add some kind of generic var for this.
166 Like:
167
168 CHECKREQS_DISK_INSTALLED=( /usr 1234M /var 2345M )
169
170 > +# @FUNCTION: check-reqs_get_mesg
171
172 Typo.
173
174 > +# @DESCRIPTION:
175 > +# Internal function that returns number in megabites.
176 > +# Converts from 1G=1024 or 1T=1048576
177 > +check-reqs_get_megs() {
178 > + debug-print-function ${FUNCNAME} "$@"
179 > +
180 > + [[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
181 > +
182 > + local unit=${1//[[:digit:]]/}
183 > + local size=${1//[[:alpha:]]/}
184
185 Seems hacky and poor. What if one uses '1G234'? :P
186
187 > +
188 > + if [[ ${unit//[[:alpha:]]/} != "" ]]; then
189 > + die "${FUNCNAME}: Failed to determine units, garbage
190 > in variables"
191
192 Would that catch anything beside symbols? I guess it would catch '.' as
193 well.
194
195 > + else
196 > + # temporary workaround for empty units
197 > + unit="M"
198 > + fi
199 > +
200 > + case ${unit} in
201 > + [gG]) echo $((1024 * ${size})) ;;
202 > + [mM]) echo ${size} ;;
203 > + [tT]) echo $((1024 * 1024 * ${size})) ;;
204 > + *)
205 > + die "${FUNCNAME}: Unknown unit size: ${unit}"
206
207 size unit.
208
209 > + ;;
210 > + esac
211 > +}
212 > +
213 > +# @FUNCTION: check-reqs_get_numbers
214
215 Why the plural?
216
217 > +# @DESCRIPTION:
218 > +# Internal function that returns number without the unit.
219 > +# Converts from 1G=1 or 150T=150.
220 > +check-reqs_get_numbers() {
221 > + debug-print-function ${FUNCNAME} "$@"
222 > +
223 > + [[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
224 > +
225 > + local size=${1//[[:alpha:]]/}
226 > +
227 > + # warn about un-united variables
228 > + if [[ ${size} == ${1//[[:alpha:]]/} ]]; then
229 > + ewarn "QA: Package does not specify unit for the
230 > size check"
231 > + ewarn "QA: Assuming Megabytes."
232 > + ewarn "QA: File bug against the package. It should
233 > specify it." fi
234 >
235 > - if [[ -n "${CHECKREQS_NEED_DIE}" ]] ; then
236 > - eerror "Bailing out as specified by CHECKREQS_ACTION"
237 > - die "Build requirements not met"
238 > + if [[ ${size//[[:digit:]]/} == "" ]]; then
239 > + echo ${size}
240 > + else
241 > + die "${FUNCNAME}: Failed to determine size, garbage
242 > in variables." fi
243 > }
244
245 And at this point, I can't stand it anymore. Man, you've transformed
246 a bad eclass into almost-python.eclass. You should not post diffs when
247 they don't help with anything; and you should not rewrite eclasses like
248 that.
249
250 Start from scratch, write check-reqs-r1, make it SIMPLE.
251
252 --
253 Best regards,
254 Michał Górny

Attachments

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

Replies

Subject Author
Re: [gentoo-dev] [RFC] check-reqs.eclass.patch "Tomáš Chvátal" <scarabeus@g.o>