Gentoo Archives: gentoo-dev

From: Sam James <sam@g.o>
To: gentoo-dev@l.g.o
Cc: kernel@g.o, Sam James <sam@g.o>
Subject: [gentoo-dev] [PATCH 1/3] linux-mod.eclass: use consistent style
Date: Sun, 25 Dec 2022 19:17:29
Message-Id: 20221225191714.757003-1-sam@gentoo.org
1 - Use Bash tests (i.e. [[ ]] instead of [ ])
2 - Use consistent newlines for if/while
3 - Drop unnecessary ; line terminators
4 - Add a handful of missing || dies
5
6 Signed-off-by: Sam James <sam@g.o>
7 ---
8 eclass/linux-mod.eclass | 149 +++++++++++++++++-----------------------
9 1 file changed, 64 insertions(+), 85 deletions(-)
10
11 diff --git a/eclass/linux-mod.eclass b/eclass/linux-mod.eclass
12 index ff2294f1e4ef..b0a1264288a0 100644
13 --- a/eclass/linux-mod.eclass
14 +++ b/eclass/linux-mod.eclass
15 @@ -199,13 +199,13 @@ DEPEND="${RDEPEND}
16 use_m() {
17 debug-print-function ${FUNCNAME} $*
18
19 - # if we haven't determined the version yet, we need too.
20 - get_version;
21 + # If we haven't determined the version yet, we need to.
22 + get_version
23
24 - # if the kernel version is greater than 2.6.6 then we should use
25 + # If the kernel version is greater than 2.6.6 then we should use
26 # M= instead of SUBDIRS=
27 - [ ${KV_MAJOR} -ge 3 ] && return 0
28 - [ ${KV_MAJOR} -eq 2 -a ${KV_MINOR} -gt 5 -a ${KV_PATCH} -gt 5 ] && \
29 + [[ ${KV_MAJOR} -ge 3 ]] && return 0
30 + [[ ${KV_MAJOR} -eq 2 && ${KV_MINOR} -gt 5 && ${KV_PATCH} -gt 5 ]] && \
31 return 0 || return 1
32 }
33
34 @@ -216,10 +216,10 @@ use_m() {
35 convert_to_m() {
36 debug-print-function ${FUNCNAME} $*
37
38 - if use_m
39 - then
40 - [ ! -f "${1}" ] && \
41 + if use_m; then
42 + [[ ! -f "${1}" ]] && \
43 die "convert_to_m() requires a filename as an argument"
44 +
45 ebegin "Converting ${1/${WORKDIR}\//} to use M= instead of SUBDIRS="
46 sed -i 's:SUBDIRS=:M=:g' "${1}"
47 eend $?
48 @@ -233,12 +233,11 @@ convert_to_m() {
49 update_depmod() {
50 debug-print-function ${FUNCNAME} $*
51
52 - # if we haven't determined the version yet, we need too.
53 - get_version;
54 + # If we haven't determined the version yet, we need to.
55 + get_version
56
57 ebegin "Updating module dependencies for ${KV_FULL}"
58 - if [ -r "${KV_OUT_DIR}"/System.map ]
59 - then
60 + if [[ -r "${KV_OUT_DIR}"/System.map ]]; then
61 depmod -ae -F "${KV_OUT_DIR}"/System.map -b "${ROOT:-/}" ${KV_FULL}
62 eend $?
63 else
64 @@ -310,15 +309,15 @@ remove_moduledb() {
65 set_kvobj() {
66 debug-print-function ${FUNCNAME} $*
67
68 - if kernel_is ge 2 6
69 - then
70 + if kernel_is ge 2 6; then
71 KV_OBJ="ko"
72 else
73 KV_OBJ="o"
74 fi
75 +
76 # Do we really need to know this?
77 - # Lets silence it.
78 - # einfo "Using KV_OBJ=${KV_OBJ}"
79 + # Let's silence it.
80 + #einfo "Using KV_OBJ=${KV_OBJ}"
81 }
82
83 # @FUNCTION: get-KERNEL_CC
84 @@ -334,7 +333,7 @@ get-KERNEL_CC() {
85 fi
86
87 local kernel_cc
88 - if [ -n "${KERNEL_ABI}" ]; then
89 + if [[ -n "${KERNEL_ABI}" ]]; then
90 # In future, an arch might want to define CC_$ABI
91 #kernel_cc="$(get_abi_CC)"
92 #[ -z "${kernel_cc}" ] &&
93 @@ -358,14 +357,13 @@ get-KERNEL_CC() {
94 # At the end the documentation specified with MODULESD_<modulename>_DOCS is installed.
95 generate_modulesd() {
96 debug-print-function ${FUNCNAME} $*
97 - [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
98 + [[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
99
100 local currm_path currm currm_t t myIFS myVAR
101 local module_docs module_enabled module_aliases \
102 module_additions module_examples module_modinfo module_opts
103
104 - for currm_path in ${@}
105 - do
106 + for currm_path in ${@}; do
107 currm=${currm_path//*\/}
108 currm=$(echo ${currm} | tr '[:lower:]' '[:upper:]')
109 currm_t=${currm}
110 @@ -388,8 +386,7 @@ generate_modulesd() {
111 [[ ${module_enabled} == no ]] && return 0
112
113 # unset any unwanted variables.
114 - for t in ${!module_*}
115 - do
116 + for t in ${!module_*}; do
117 [[ -z ${!t} ]] && unset ${t}
118 done
119
120 @@ -427,19 +424,16 @@ generate_modulesd() {
121 fi
122
123 #-----------------------------------------------------------------------
124 - if [[ -n ${module_modinfo} ]]
125 - then
126 + if [[ -n ${module_modinfo} ]]; then
127 echo >> "${module_config}"
128 echo "# Configurable module parameters" >> "${module_config}"
129 echo "# ------------------------------" >> "${module_config}"
130 myIFS="${IFS}"
131 IFS="$(echo -en "\n\b")"
132
133 - for t in ${module_modinfo}
134 - do
135 + for t in ${module_modinfo}; do
136 myVAR="$(echo ${t#*:} | grep -o "[^ ]*[0-9][ =][^ ]*" | tail -1 | grep -o "[0-9]")"
137 - if [[ -n ${myVAR} ]]
138 - then
139 + if [[ -n ${myVAR} ]]; then
140 module_opts="${module_opts} ${t%%:*}:${myVAR}"
141 fi
142 echo -e "# ${t%%:*}:\t${t#*:}" >> "${module_config}"
143 @@ -449,11 +443,9 @@ generate_modulesd() {
144 fi
145
146 #-----------------------------------------------------------------------
147 - if [[ $(eval echo \${MODULESD_${currm}_ALIASES[0]}) == guess ]]
148 - then
149 - # So lets do some guesswork eh?
150 - if [[ -n ${module_opts} ]]
151 - then
152 + if [[ $(eval echo \${MODULESD_${currm}_ALIASES[0]}) == guess ]]; then
153 + # So, let's do some guesswork, eh?
154 + if [[ -n ${module_opts} ]]; then
155 echo "# For Example..." >> "${module_config}"
156 echo "# --------------" >> "${module_config}"
157 for t in ${module_opts}
158 @@ -462,12 +454,10 @@ generate_modulesd() {
159 done
160 echo '' >> "${module_config}"
161 fi
162 - elif [[ ${module_examples} -gt 0 ]]
163 - then
164 + elif [[ ${module_examples} -gt 0 ]]; then
165 echo "# For Example..." >> "${module_config}"
166 echo "# --------------" >> "${module_config}"
167 - for((t=0; t<${module_examples}; t++))
168 - do
169 + for ((t=0; t<${module_examples}; t++)); do
170 echo "options $(eval echo \${MODULESD_${currm}_EXAMPLES[$t]})" \
171 >> "${module_config}"
172 done
173 @@ -475,10 +465,8 @@ generate_modulesd() {
174 fi
175
176 #-----------------------------------------------------------------------
177 - if [[ ${module_additions} -gt 0 ]]
178 - then
179 - for((t=0; t<${module_additions}; t++))
180 - do
181 + if [[ ${module_additions} -gt 0 ]]; then
182 + for ((t=0; t<${module_additions}; t++)); do
183 echo "$(eval echo \${MODULESD_${currm}_ADDITIONS[$t]})" \
184 >> "${module_config}"
185 done
186 @@ -510,8 +498,7 @@ find_module_params() {
187 local matched_offset=0 matched_opts=0 test="${@}" temp_var result
188 local i=0 y=0 z=0
189
190 - for((i=0; i<=${#test}; i++))
191 - do
192 + for ((i=0; i<=${#test}; i++)); do
193 case ${test:${i}:1} in
194 \() matched_offset[0]=${i};;
195 \:) matched_opts=$((${matched_opts} + 1));
196 @@ -521,8 +508,7 @@ find_module_params() {
197 esac
198 done
199
200 - for((i=0; i<=${matched_opts}; i++))
201 - do
202 + for ((i=0; i<=${matched_opts}; i++)); do
203 # i = offset were working on
204 # y = last offset
205 # z = current offset - last offset
206 @@ -556,7 +542,7 @@ find_module_params() {
207 # in the kernel and sets the object extension KV_OBJ.
208 linux-mod_pkg_setup() {
209 debug-print-function ${FUNCNAME} $*
210 - [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
211 + [[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
212
213 local is_bin="${MERGE_TYPE}"
214
215 @@ -569,12 +555,12 @@ linux-mod_pkg_setup() {
216 # External modules use kernel symbols (bug #591832)
217 CONFIG_CHECK+=" !TRIM_UNUSED_KSYMS"
218
219 - linux-info_pkg_setup;
220 + linux-info_pkg_setup
221 require_configured_kernel
222 - check_kernel_built;
223 - strip_modulenames;
224 + check_kernel_built
225 + strip_modulenames
226 [[ -n ${MODULE_NAMES} ]] && check_modules_supported
227 - set_kvobj;
228 + set_kvobj
229 }
230
231 # @FUNCTION: linux-mod_pkg_setup_binary
232 @@ -586,13 +572,13 @@ linux-mod_pkg_setup_binary() {
233 debug-print-function ${FUNCNAME} $*
234 local new_CONFIG_CHECK
235 # ~ needs always to be quoted, else bash expands it.
236 - for config in $CONFIG_CHECK ; do
237 + for config in ${CONFIG_CHECK} ; do
238 optional='~'
239 [[ ${config:0:1} == "~" ]] && optional=''
240 new_CONFIG_CHECK="${new_CONFIG_CHECK} ${optional}${config}"
241 done
242 CONFIG_CHECK="${new_CONFIG_CHECK}"
243 - linux-info_pkg_setup;
244 + linux-info_pkg_setup
245 }
246
247 # @FUNCTION: strip_modulenames
248 @@ -617,7 +603,7 @@ strip_modulenames() {
249 # Look at the description of these variables for more details.
250 linux-mod_src_compile() {
251 debug-print-function ${FUNCNAME} $*
252 - [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
253 + [[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
254
255 local modulename libdir srcdir objdir i n myABI="${ABI}"
256 set_arch_to_kernel
257 @@ -631,30 +617,25 @@ linux-mod_src_compile() {
258 local -x CROSS_COMPILE=${CROSS_COMPILE-${CHOST}-}
259
260 BUILD_TARGETS=${BUILD_TARGETS:-clean module}
261 - strip_modulenames;
262 - cd "${S}"
263 - touch Module.symvers
264 - for i in ${MODULE_NAMES}
265 - do
266 + strip_modulenames
267 + cd "${S}" || die
268 + touch Module.symvers || die
269 + for i in ${MODULE_NAMES}; do
270 unset libdir srcdir objdir
271 - for n in $(find_module_params ${i})
272 - do
273 + for n in $(find_module_params ${i}); do
274 eval ${n/:*}=${n/*:/}
275 done
276 libdir=${libdir:-misc}
277 srcdir=${srcdir:-${S}}
278 objdir=${objdir:-${srcdir}}
279
280 - if [ ! -f "${srcdir}/.built" ];
281 - then
282 - cd "${srcdir}"
283 - ln -s "${S}"/Module.symvers Module.symvers
284 + if [[ ! -f "${srcdir}/.built" ]]; then
285 + cd "${srcdir}" || die
286 + ln -s "${S}"/Module.symvers Module.symvers || die
287 einfo "Preparing ${modulename} module"
288 - if [[ -n ${ECONF_PARAMS} ]]
289 - then
290 + if [[ -n ${ECONF_PARAMS} ]]; then
291 eqawarn "This package relies on the deprecated functionality of econf being called in linux-mod_src_compile (ECONF_PARAMS), which will go away in 30 days (20230107) (https://bugs.gentoo.org/340597)"
292 - econf ${ECONF_PARAMS} || \
293 - die "Unable to run econf ${ECONF_PARAMS}"
294 + econf ${ECONF_PARAMS}
295 fi
296
297 # This looks messy, but it is needed to handle multiple variables
298 @@ -668,8 +649,8 @@ linux-mod_src_compile() {
299 ${BUILD_PARAMS} \
300 ${BUILD_TARGETS} " \
301 || die "Unable to emake HOSTCC="$(tc-getBUILD_CC)" LDFLAGS="$(get_abi_LDFLAGS)" ${BUILD_FIXES} ${BUILD_PARAMS} ${BUILD_TARGETS}"
302 - cd "${OLDPWD}"
303 - touch "${srcdir}"/.built
304 + cd "${OLDPWD}" || die
305 + touch "${srcdir}"/.built || die
306 fi
307 done
308
309 @@ -690,18 +671,16 @@ linux-mod_src_compile() {
310 # Look at the description of these variables for more details.
311 linux-mod_src_install() {
312 debug-print-function ${FUNCNAME} $*
313 - [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
314 + [[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
315
316 local modulename libdir srcdir objdir i n
317
318 [[ -n ${KERNEL_DIR} ]] && addpredict "${KERNEL_DIR}/null.dwo"
319
320 - strip_modulenames;
321 - for i in ${MODULE_NAMES}
322 - do
323 + strip_modulenames
324 + for i in ${MODULE_NAMES}; do
325 unset libdir srcdir objdir
326 - for n in $(find_module_params ${i})
327 - do
328 + for n in $(find_module_params ${i}); do
329 eval ${n/:*}=${n/*:/}
330 done
331 libdir=${libdir:-misc}
332 @@ -742,22 +721,22 @@ linux-mod_src_install() {
333 # It checks what to do after having merged the package.
334 linux-mod_pkg_preinst() {
335 debug-print-function ${FUNCNAME} $*
336 - [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
337 + [[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
338
339 - [ -d "${D%/}/lib/modules" ] && UPDATE_DEPMOD=true || UPDATE_DEPMOD=false
340 - [ -d "${D%/}/lib/modules" ] && UPDATE_MODULEDB=true || UPDATE_MODULEDB=false
341 + [[ -d "${D%/}/lib/modules" ]] && UPDATE_DEPMOD=true || UPDATE_DEPMOD=false
342 + [[ -d "${D%/}/lib/modules" ]] && UPDATE_MODULEDB=true || UPDATE_MODULEDB=false
343 }
344
345 # @FUNCTION: linux-mod_pkg_postinst
346 # @DESCRIPTION:
347 # It executes /sbin/depmod and adds the package to the /var/lib/module-rebuild/moduledb
348 -# database (if ${D}/lib/modules is created)"
349 +# database (if ${D}/lib/modules is created)
350 linux-mod_pkg_postinst() {
351 debug-print-function ${FUNCNAME} $*
352 - [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
353 + [[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
354
355 - ${UPDATE_DEPMOD} && update_depmod;
356 - ${UPDATE_MODULEDB} && update_moduledb;
357 + ${UPDATE_DEPMOD} && update_depmod
358 + ${UPDATE_MODULEDB} && update_moduledb
359 }
360
361 # @FUNCTION: linux-mod_pkg_postrm
362 @@ -766,8 +745,8 @@ linux-mod_pkg_postinst() {
363 # call /sbin/depmod because the modules are still installed.
364 linux-mod_pkg_postrm() {
365 debug-print-function ${FUNCNAME} $*
366 - [ -n "${MODULES_OPTIONAL_USE}" ] && use !${MODULES_OPTIONAL_USE} && return
367 - remove_moduledb;
368 + [[ -n "${MODULES_OPTIONAL_USE}" ]] && use !${MODULES_OPTIONAL_USE} && return
369 + remove_moduledb
370 }
371
372 fi
373 --
374 2.39.0

Replies