1 |
- Use Bash tests (i.e. [[ ]] instead of [ ]) |
2 |
- Use consistent newlines for if/while |
3 |
- Drop unnecessary ; line terminators |
4 |
|
5 |
Signed-off-by: Sam James <sam@g.o> |
6 |
--- |
7 |
eclass/linux-info.eclass | 142 ++++++++++++++++++--------------------- |
8 |
1 file changed, 66 insertions(+), 76 deletions(-) |
9 |
|
10 |
diff --git a/eclass/linux-info.eclass b/eclass/linux-info.eclass |
11 |
index 3e64cb9457a9..308286e515c5 100644 |
12 |
--- a/eclass/linux-info.eclass |
13 |
+++ b/eclass/linux-info.eclass |
14 |
@@ -140,13 +140,12 @@ KERNEL_DIR="${KERNEL_DIR:-${ROOT%/}/usr/src/linux}" |
15 |
# A read-only variable. It's a string containing the kernel object directory, will be KV_DIR unless |
16 |
# KBUILD_OUTPUT is used. This should be used for referencing .config. |
17 |
|
18 |
- |
19 |
# @ECLASS_VARIABLE: SKIP_KERNEL_CHECK |
20 |
# @USER_VARIABLE |
21 |
# @DEFAULT_UNSET |
22 |
# @DESCRIPTION: |
23 |
-# Do not check for kernel sources or a running kernel version |
24 |
-# Main use-case is for chroots |
25 |
+# Do not check for kernel sources or a running kernel version. |
26 |
+# Main use-case is for chroots. |
27 |
# This is a user flag and should under _no circumstances_ be set in the ebuild. |
28 |
: ${SKIP_KERNEL_CHECK:=""} |
29 |
|
30 |
@@ -156,8 +155,7 @@ inherit toolchain-funcs |
31 |
|
32 |
EXPORT_FUNCTIONS pkg_setup |
33 |
|
34 |
-# Bug fixes |
35 |
-# fix to bug #75034 |
36 |
+# bug #75034 |
37 |
case ${ARCH} in |
38 |
ppc) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";; |
39 |
ppc64) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";; |
40 |
@@ -175,7 +173,7 @@ set_arch_to_pkgmgr() { export ARCH=$(tc-arch); } |
41 |
|
42 |
# @FUNCTION: qout |
43 |
# @DESCRIPTION: |
44 |
-# qout <einfo | ewarn | eerror> is a quiet call when EBUILD_PHASE should not have visible output. |
45 |
+# qout <einfo | ewarn | eerror> is a quiet call when EBUILD_PHASE should not have visible output. |
46 |
qout() { |
47 |
local outputmsg type |
48 |
type=${1} |
49 |
@@ -186,7 +184,7 @@ qout() { |
50 |
clean) unset outputmsg;; |
51 |
preinst) unset outputmsg;; |
52 |
esac |
53 |
- [ -n "${outputmsg}" ] && ${type} "${outputmsg}" |
54 |
+ [[ -n "${outputmsg}" ]] && ${type} "${outputmsg}" |
55 |
} |
56 |
|
57 |
# @FUNCTION: qeinfo |
58 |
@@ -196,14 +194,12 @@ qeinfo() { qout einfo "${@}" ; } |
59 |
|
60 |
# @FUNCTION: qewarn |
61 |
# @DESCRIPTION: |
62 |
-# qewarn is a quiet ewarn call when EBUILD_PHASE |
63 |
-# should not have visible output. |
64 |
+# qewarn is a quiet ewarn call when EBUILD_PHASE should not have visible output. |
65 |
qewarn() { qout ewarn "${@}" ; } |
66 |
|
67 |
# @FUNCTION: qeerror |
68 |
# @DESCRIPTION: |
69 |
-# qeerror is a quiet error call when EBUILD_PHASE |
70 |
-# should not have visible output. |
71 |
+# qeerror is a quiet error call when EBUILD_PHASE should not have visible output. |
72 |
qeerror() { qout eerror "${@}" ; } |
73 |
|
74 |
# File Functions |
75 |
@@ -213,18 +209,17 @@ qeerror() { qout eerror "${@}" ; } |
76 |
# @USAGE: <variable> <configfile> |
77 |
# @RETURN: the value of the variable |
78 |
# @DESCRIPTION: |
79 |
-# It detects the value of the variable defined in the file configfile. This is |
80 |
-# done by including the configfile, and printing the variable with Make. |
81 |
+# It detects the value of the variable defined in the file 'configfile'. This is |
82 |
+# done by including the 'configfile', and printing the variable with Make. |
83 |
# It WILL break if your makefile has missing dependencies! |
84 |
getfilevar() { |
85 |
local ERROR basefname basedname myARCH="${ARCH}" |
86 |
ERROR=0 |
87 |
|
88 |
- [ -z "${1}" ] && ERROR=1 |
89 |
- [ ! -f "${2}" ] && ERROR=1 |
90 |
+ [[ -z "${1}" ]] && ERROR=1 |
91 |
+ [[ ! -f "${2}" ]] && ERROR=1 |
92 |
|
93 |
- if [ "${ERROR}" = 1 ] |
94 |
- then |
95 |
+ if [[ "${ERROR}" = 1 ]]; then |
96 |
echo -e "\n" |
97 |
eerror "getfilevar requires 2 variables, with the second a valid file." |
98 |
eerror " getfilevar <VARIABLE> <CONFIGFILE>" |
99 |
@@ -250,7 +245,7 @@ getfilevar() { |
100 |
# @USAGE: <variable> <configfile> |
101 |
# @RETURN: the value of the variable |
102 |
# @DESCRIPTION: |
103 |
-# It detects the value of the variable defined in the file configfile. |
104 |
+# It detects the value of the variable defined in the file 'configfile'. |
105 |
# This is done with sed matching an expression only. If the variable is defined, |
106 |
# you will run into problems. See getfilevar for those cases. |
107 |
getfilevar_noexec() { |
108 |
@@ -258,12 +253,11 @@ getfilevar_noexec() { |
109 |
ERROR=0 |
110 |
mycat='cat' |
111 |
|
112 |
- [ -z "${1}" ] && ERROR=1 |
113 |
- [ ! -f "${2}" ] && ERROR=1 |
114 |
- [ "${2%.gz}" != "${2}" ] && mycat='zcat' |
115 |
+ [[ -z "${1}" ]] && ERROR=1 |
116 |
+ [[ ! -f "${2}" ]] && ERROR=1 |
117 |
+ [[ "${2%.gz}" != "${2}" ]] && mycat='zcat' |
118 |
|
119 |
- if [ "${ERROR}" = 1 ] |
120 |
- then |
121 |
+ if [[ "${ERROR}" = 1 ]]; then |
122 |
echo -e "\n" |
123 |
eerror "getfilevar_noexec requires 2 variables, with the second a valid file." |
124 |
eerror " getfilevar_noexec <VARIABLE> <CONFIGFILE>" |
125 |
@@ -293,7 +287,8 @@ _LINUX_CONFIG_EXISTS_DONE= |
126 |
# Helper funciton which returns an error before the function argument is run if no config exists |
127 |
linux_config_qa_check() { |
128 |
local f="$1" |
129 |
- if [ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]; then |
130 |
+ |
131 |
+ if [[ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]]; then |
132 |
ewarn "QA: You called $f before any linux_config_exists!" |
133 |
ewarn "QA: The return value of $f will NOT guaranteed later!" |
134 |
fi |
135 |
@@ -351,7 +346,6 @@ linux_config_path() { |
136 |
# This function verifies that the current kernel is configured (it checks against the existence of .config) |
137 |
# otherwise it dies. |
138 |
require_configured_kernel() { |
139 |
- |
140 |
[[ -n ${SKIP_KERNEL_CHECK} ]] && return |
141 |
|
142 |
if ! use kernel_linux; then |
143 |
@@ -365,6 +359,7 @@ require_configured_kernel() { |
144 |
qeerror "it points to the necessary object directory so that it might find .config." |
145 |
die "Kernel not configured; no .config found in ${KV_OUT_DIR}" |
146 |
fi |
147 |
+ |
148 |
get_version || die "Unable to determine configured kernel version" |
149 |
} |
150 |
|
151 |
@@ -445,7 +440,7 @@ kernel_is() { |
152 |
die "${FUNCNAME}() called on non-Linux system, please fix the ebuild" |
153 |
fi |
154 |
|
155 |
- # if we haven't determined the version yet, we need to. |
156 |
+ # If we haven't determined the version yet, we need to. |
157 |
linux-info_get_any_version |
158 |
|
159 |
# Now we can continue |
160 |
@@ -459,7 +454,7 @@ kernel_is() { |
161 |
eq) operator="-eq"; shift;; |
162 |
*) operator="-eq";; |
163 |
esac |
164 |
- [[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters" |
165 |
+ [[ $# -gt 3 ]] && die "Error in ${ECLASS}_${FUNCNAME}(): too many parameters" |
166 |
|
167 |
ver_test \ |
168 |
"${KV_MAJOR:-0}.${KV_MINOR:-0}.${KV_PATCH:-0}" \ |
169 |
@@ -488,7 +483,7 @@ get_makefile_extract_function() { |
170 |
|
171 |
# @ECLASS_VARIABLE: get_version_warning_done |
172 |
# @INTERNAL |
173 |
-# @DESCRIPTION: |
174 |
+# @DESCRIPTION: |
175 |
# Internal variable, so we know to only print the warning once. |
176 |
get_version_warning_done= |
177 |
|
178 |
@@ -511,26 +506,25 @@ get_version() { |
179 |
|
180 |
[[ -n ${SKIP_KERNEL_CHECK} ]] && return |
181 |
|
182 |
- # no need to execute this twice assuming KV_FULL is populated. |
183 |
- # we can force by unsetting KV_FULL |
184 |
- [ -n "${KV_FULL}" ] && return 0 |
185 |
+ # No need to execute this twice assuming KV_FULL is populated. |
186 |
+ # We can force by unsetting KV_FULL. |
187 |
+ [[ -n "${KV_FULL}" ]] && return 0 |
188 |
|
189 |
- # if we dont know KV_FULL, then we need too. |
190 |
- # make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR |
191 |
+ # If we don't know KV_FULL, then we need to. |
192 |
+ # Make sure KV_DIR isn't set since we need to work it out via KERNEL_DIR. |
193 |
unset KV_DIR |
194 |
|
195 |
# KV_DIR will contain the full path to the sources directory we should use |
196 |
- [ -z "${get_version_warning_done}" ] && \ |
197 |
+ [[ -z "${get_version_warning_done}" ]] && \ |
198 |
qeinfo "Determining the location of the kernel source code" |
199 |
- [ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}" |
200 |
+ [[ -d "${KERNEL_DIR}" ]] && KV_DIR="${KERNEL_DIR}" |
201 |
|
202 |
- if [ -z "${KV_DIR}" ] |
203 |
- then |
204 |
- if [ -z "${get_version_warning_done}" ]; then |
205 |
+ if [[ -z "${KV_DIR}" ]]; then |
206 |
+ if [[ -z "${get_version_warning_done}" ]]; then |
207 |
get_version_warning_done=1 |
208 |
qewarn "Unable to find kernel sources at ${KERNEL_DIR}" |
209 |
#qeinfo "This package requires Linux sources." |
210 |
- if [ "${KERNEL_DIR}" == "/usr/src/linux" ] ; then |
211 |
+ if [[ "${KERNEL_DIR}" == "/usr/src/linux" ]] ; then |
212 |
qeinfo "Please make sure that ${KERNEL_DIR} points at your running kernel, " |
213 |
qeinfo "(or the kernel you wish to build against)." |
214 |
qeinfo "Alternatively, set the KERNEL_DIR environment variable to the kernel sources location" |
215 |
@@ -542,22 +536,21 @@ get_version() { |
216 |
fi |
217 |
|
218 |
# See if the kernel dir is actually an output dir. #454294 |
219 |
- if [ -z "${KBUILD_OUTPUT}" -a -L "${KERNEL_DIR}/source" ]; then |
220 |
+ if [[ -z "${KBUILD_OUTPUT}" && -L "${KERNEL_DIR}/source" ]]; then |
221 |
KBUILD_OUTPUT=${KERNEL_DIR} |
222 |
KERNEL_DIR=$(readlink -f "${KERNEL_DIR}/source") |
223 |
KV_DIR=${KERNEL_DIR} |
224 |
fi |
225 |
|
226 |
- if [ -z "${get_version_warning_done}" ]; then |
227 |
+ if [[ -z "${get_version_warning_done}" ]]; then |
228 |
qeinfo "Found kernel source directory:" |
229 |
qeinfo " ${KV_DIR}" |
230 |
fi |
231 |
|
232 |
kernel_get_makefile |
233 |
|
234 |
- if [[ ! -s ${KERNEL_MAKEFILE} ]] |
235 |
- then |
236 |
- if [ -z "${get_version_warning_done}" ]; then |
237 |
+ if [[ ! -s ${KERNEL_MAKEFILE} ]]; then |
238 |
+ if [[ -z "${get_version_warning_done}" ]]; then |
239 |
get_version_warning_done=1 |
240 |
qeerror "Could not find a Makefile in the kernel source directory." |
241 |
qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources" |
242 |
@@ -567,8 +560,9 @@ get_version() { |
243 |
|
244 |
# OK so now we know our sources directory, but they might be using |
245 |
# KBUILD_OUTPUT, and we need this for .config and localversions-* |
246 |
- # so we better find it eh? |
247 |
- # do we pass KBUILD_OUTPUT on the CLI? |
248 |
+ # so we better find it, eh? |
249 |
+ # |
250 |
+ # Do we pass KBUILD_OUTPUT on the CLI? |
251 |
local OUTPUT_DIR=${KBUILD_OUTPUT} |
252 |
|
253 |
if [[ -z ${OUTPUT_DIR} ]]; then |
254 |
@@ -579,17 +573,16 @@ get_version() { |
255 |
OUTPUT_DIR=$(${mkfunc} KBUILD_OUTPUT "${KERNEL_MAKEFILE}") |
256 |
fi |
257 |
|
258 |
- # And contrary to existing functions I feel we shouldn't trust the |
259 |
+ # And contrary to existing functions, I feel we shouldn't trust the |
260 |
# directory name to find version information as this seems insane. |
261 |
- # So we parse ${KERNEL_MAKEFILE}. |
262 |
+ # So we parse ${KERNEL_MAKEFILE}. |
263 |
KV_MAJOR=$(getfilevar VERSION "${KERNEL_MAKEFILE}") |
264 |
KV_MINOR=$(getfilevar PATCHLEVEL "${KERNEL_MAKEFILE}") |
265 |
KV_PATCH=$(getfilevar SUBLEVEL "${KERNEL_MAKEFILE}") |
266 |
KV_EXTRA=$(getfilevar EXTRAVERSION "${KERNEL_MAKEFILE}") |
267 |
|
268 |
- if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ] |
269 |
- then |
270 |
- if [ -z "${get_version_warning_done}" ]; then |
271 |
+ if [[ -z "${KV_MAJOR}" || -z "${KV_MINOR}" || -z "${KV_PATCH}" ]; then |
272 |
+ if [[ -z "${get_version_warning_done}" ]]; then |
273 |
get_version_warning_done=1 |
274 |
qeerror "Could not detect kernel version." |
275 |
qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources." |
276 |
@@ -597,9 +590,8 @@ get_version() { |
277 |
return 1 |
278 |
fi |
279 |
|
280 |
- [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}" |
281 |
- if [ -n "${KV_OUT_DIR}" ]; |
282 |
- then |
283 |
+ [[ -d "${OUTPUT_DIR}" ]] && KV_OUT_DIR="${OUTPUT_DIR}" |
284 |
+ if [[ -n "${KV_OUT_DIR}" ]]; then |
285 |
qeinfo "Found kernel object directory:" |
286 |
qeinfo " ${KV_OUT_DIR}" |
287 |
fi |
288 |
@@ -609,9 +601,9 @@ get_version() { |
289 |
# Grab the kernel release from the output directory. |
290 |
# TODO: we MUST detect kernel.release being out of date, and 'return 1' from |
291 |
# this function. |
292 |
- if [ -s "${KV_OUT_DIR}"/include/config/kernel.release ]; then |
293 |
+ if [[ -s "${KV_OUT_DIR}"/include/config/kernel.release ]]; then |
294 |
KV_LOCAL=$(<"${KV_OUT_DIR}"/include/config/kernel.release) |
295 |
- elif [ -s "${KV_OUT_DIR}"/.kernelrelease ]; then |
296 |
+ elif [[ -s "${KV_OUT_DIR}"/.kernelrelease ]]; then |
297 |
KV_LOCAL=$(<"${KV_OUT_DIR}"/.kernelrelease) |
298 |
else |
299 |
KV_LOCAL= |
300 |
@@ -624,13 +616,13 @@ get_version() { |
301 |
# Clear out KV_LOCAL in that case. |
302 |
# TODO: this does not detect a change in the localversion part between |
303 |
# kernel.release and the value that would be generated. |
304 |
- if [ "$KV_LOCAL" = "$tmplocal" ]; then |
305 |
+ if [[ "${KV_LOCAL}" = "${tmplocal}" ]]; then |
306 |
KV_LOCAL= |
307 |
else |
308 |
- KV_LOCAL=$tmplocal |
309 |
+ KV_LOCAL=${tmplocal} |
310 |
fi |
311 |
|
312 |
- # and in newer versions we can also pull LOCALVERSION if it is set. |
313 |
+ # and in newer versions, we can also pull LOCALVERSION if it is set. |
314 |
# but before we do this, we need to find if we use a different object directory. |
315 |
# This *WILL* break if the user is using localversions, but we assume it was |
316 |
# caught before this if they are. |
317 |
@@ -718,7 +710,7 @@ check_kernel_built() { |
318 |
die "${FUNCNAME}() called on non-Linux system, please fix the ebuild" |
319 |
fi |
320 |
|
321 |
- # if we haven't determined the version yet, we need to |
322 |
+ # If we haven't determined the version yet, we need to |
323 |
|
324 |
[[ -n ${SKIP_KERNEL_CHECK} ]] && return |
325 |
|
326 |
@@ -731,8 +723,7 @@ check_kernel_built() { |
327 |
versionh_path="include/linux/version.h" |
328 |
fi |
329 |
|
330 |
- if [ ! -f "${KV_OUT_DIR}/${versionh_path}" ] |
331 |
- then |
332 |
+ if [[ ! -f "${KV_OUT_DIR}/${versionh_path}" ]]; then |
333 |
eerror "These sources have not yet been prepared." |
334 |
eerror "We cannot build against an unprepared tree." |
335 |
eerror "To resolve this, please type the following:" |
336 |
@@ -754,7 +745,7 @@ check_modules_supported() { |
337 |
die "${FUNCNAME}() called on non-Linux system, please fix the ebuild" |
338 |
fi |
339 |
|
340 |
- # if we haven't determined the version yet, we need too. |
341 |
+ # If we haven't determined the version yet, we need to. |
342 |
require_configured_kernel |
343 |
|
344 |
if ! linux_chkconfig_builtin "MODULES"; then |
345 |
@@ -774,12 +765,12 @@ check_extra_config() { |
346 |
|
347 |
local config negate die error reworkmodulenames |
348 |
local soft_errors_count=0 hard_errors_count=0 config_required=0 |
349 |
- # store the value of the QA check, because otherwise we won't catch usages |
350 |
+ # Store the value of the QA check, because otherwise we won't catch usages |
351 |
# after if check_extra_config is called AND other direct calls are done |
352 |
# later. |
353 |
local old_LINUX_CONFIG_EXISTS_DONE="${_LINUX_CONFIG_EXISTS_DONE}" |
354 |
|
355 |
- # if we haven't determined the version yet, we need to |
356 |
+ # If we haven't determined the version yet, we need to. |
357 |
linux-info_get_any_version |
358 |
|
359 |
# Determine if we really need a .config. The only time when we don't need |
360 |
@@ -820,9 +811,8 @@ check_extra_config() { |
361 |
|
362 |
ebegin "Checking for suitable kernel configuration options" |
363 |
|
364 |
- for config in ${CONFIG_CHECK} |
365 |
- do |
366 |
- # if we specify any fatal, ensure we honor them |
367 |
+ for config in ${CONFIG_CHECK}; do |
368 |
+ # If we specify any fatal, ensure we honor them |
369 |
die=1 |
370 |
error=0 |
371 |
negate=0 |
372 |
@@ -919,7 +909,7 @@ check_zlibinflate() { |
373 |
die "${FUNCNAME}() called on non-Linux system, please fix the ebuild" |
374 |
fi |
375 |
|
376 |
- # if we haven't determined the version yet, we need to |
377 |
+ # If we haven't determined the version yet, we need to. |
378 |
require_configured_kernel |
379 |
|
380 |
# although I restructured this code - I really really really dont support it! |
381 |
@@ -951,15 +941,15 @@ check_zlibinflate() { |
382 |
|
383 |
LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)" |
384 |
LINENO_START="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1)" |
385 |
- (( LINENO_AMOUNT = $LINENO_END - $LINENO_START )) |
386 |
- (( LINENO_END = $LINENO_END - 1 )) |
387 |
+ (( LINENO_AMOUNT = ${LINENO_END} - ${LINENO_START} )) |
388 |
+ (( LINENO_END = ${LINENO_END} - 1 )) |
389 |
SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')" |
390 |
|
391 |
# okay, now we have a list of symbols |
392 |
# we need to check each one in turn, to see whether it is set or not |
393 |
- for x in $SYMBOLS ; do |
394 |
- if [ "${!x}" = "y" ]; then |
395 |
- # we have a winner! |
396 |
+ for x in ${SYMBOLS} ; do |
397 |
+ if [[ "${!x}" = "y" ]]; then |
398 |
+ # We have a winner! |
399 |
einfo "${x} ensures zlib is linked into your kernel - excellent" |
400 |
return 0 |
401 |
fi |
402 |
@@ -974,7 +964,7 @@ check_zlibinflate() { |
403 |
eerror "Please ensure that you enable at least one of these options:" |
404 |
eerror |
405 |
|
406 |
- for x in $SYMBOLS ; do |
407 |
+ for x in ${SYMBOLS} ; do |
408 |
eerror " * $x" |
409 |
done |
410 |
|
411 |
@@ -997,7 +987,7 @@ linux-info_pkg_setup() { |
412 |
|
413 |
linux-info_get_any_version |
414 |
|
415 |
- [[ -n "${CONFIG_CHECK}" && -z ${CHECKCONFIG_DONOTHING} ]] && check_extra_config; |
416 |
+ [[ -n "${CONFIG_CHECK}" && -z ${CHECKCONFIG_DONOTHING} ]] && check_extra_config |
417 |
} |
418 |
|
419 |
# @FUNCTION: kernel_get_makefile |
420 |
-- |
421 |
2.39.0 |