Make the BLIS configure script pass all shellcheck checks#729
Make the BLIS configure script pass all shellcheck checks#729fgvanzee merged 4 commits intoflame:masterfrom leekillough:shellcheck_configure
Conversation
| for item in "${list}"; do | ||
|
|
||
| for item in ${list}; do | ||
|
|
There was a problem hiding this comment.
This is a bug -- quotes makes the loop only execute once, even if ${list} contains space-separated items.
If the items in ${list} may need to contain spaces, then declaring ${list} a Bash array variable and using it such as with "${list[@]}" will work.
There was a problem hiding this comment.
Agreed, this was a bug. I think we might have been lucky in that the config_registry didn't make use of syntax that would have needed the loop.
| # -- Command line option/argument parsing ---------------------------------- | ||
|
|
||
| found=true | ||
| while $found = true; do |
|
@leekillough thanks for going through and fixing all of these! I'll let Field comment on individual changes (@fgvanzee unless you want me to go through it, no problem). I'll test on MacOS since it is stuck on GPLv2 bash. |
…range redirections in long sed/perl pipes to look more natural
… to use only tabs
|
@leekillough Thank you for this exhaustive review. I sincerely appreciate your efforts. I'll go through your list more closely and see if I have any comments. |
|
This looks good, @leekillough. I only made a few trivial whitespace/formatting changes. I'll merge shortly. Thanks again for your contribution. |
|
@leekillough Lol, sorry. I got distracted while waiting for CI to finish. I mean it this time! 😅 |
Details: - Modified configure so that it passes all 'shellcheck' checks, disabling ones which we violate but which are just stylistic, or are special cases in our code. - Miscellaneous other minor changes, such as rearranged redirections in long sed/perl pipes to look more natural. - Whitespace tweaks.
Details:
- Updated common.mk so that when --disable-shared option is given to
configure:
1. The -fPIC compiler flag is omitted from the individual
configuration family members' CPICFLAGS variables (which are
initialized in each subconfig's make_defs.mk file); and
2. The BUILD_SYMFLAGS variable, which contains compiler flags needed
to control the symbol export behavior, is left blank.
- The net result of these changes is that flags specific to shared
library builds are only used when a shared library is actually
scheduled to be built. Thanks to Nick Knight for reporting this issue.
- CREDITS file update.
- (cherry picked from commit 5f84130)
Updated configure to pass all shellcheck checks. (#729)
Details:
- Modified configure so that it passes all 'shellcheck' checks,
disabling ones which we violate but which are just stylistic, or are
special cases in our code.
- Miscellaneous other minor changes, such as rearranged redirections in
long sed/perl pipes to look more natural.
- Whitespace tweaks.
- (cherry picked from 72c37eb)
Fixed bugs in scal2v ref kernel when alpha == 1. (#728)
Details:
- Fixed a typo bug in ref_kernels/1/bli_scal2v_ref.c where the
conditional that was supposed to be checking for cases when alpha is
equal to 1.0 (so that copyv could be used instead of scal2v) was
instead erroneously comparing alpha against 0.0.
- Fixed another bug in the same function whereby BLIS_NO_CONJUGATE was
erroneously being passed into copyv instead of the kernel's conjx
parameter. This second bug was inert, however, due to the first bug
since the "alpha == 0.0" case was already being handled, resulting in
the code block never executing.
- (cherry picked from 60f3634)
Use 'void*' datatypes in kernel APIs. (#727)
Details:
- Migrated all kernel APIs to use void* pointers instead of float*,
double*, scomplex*, and dcomplex* pointers. This allows us to define
many fewer kernel function pointer types, which also makes it much
easier to know which function pointer type to use at any given time.
(For example, whereas before there was ?axpyv_ker_ft, ?axpyv_ker_vft,
and axpyv_ker_vft, now there is just axpyv_ker_ft, which is equivalent
so what axpyv_ker_vft used to be.)
- Refactored how kernel function prototypes and kernel function types
are defined so as to reduce redundant code. Specifically, the
function signatures (excluding cntx_t* and, in the case of level-3
microkernels, auxinfo_t*) are defined in new headers named, for
example, bli_l1v_ker_params.h. Those signatures are reused via macro
instantiation when defining both kernel prototypes and kernel function
types. This will hopefully make it a little easier to update, add, and
manage kernel APIs going forward.
- Updated all reference kernels according to the aforementioned switch
to void* pointers.
- Updated all optimzied kernels according to the aforementioned switch
to void* pointers. This sometimes required renaming variables,
inserting typecasting so that pointer arithmetic could continue to
function as intended, and related tweaks.
- Updated sandbox/gemmlike according to the aforementioned switch to
void* pointers.
- Renamed:
- frame/1/bli_l1v_ft_ker.h -> frame/1/bli_l1v_ker_ft.h
- frame/1f/bli_l1f_ft_ker.h -> frame/1f/bli_l1f_ker_ft.h
- frame/1m/bli_l1m_ft_ker.h -> frame/1m/bli_l1m_ker_ft.h
- frame/3/bli_l1m_ft_ukr.h -> frame/3/bli_l1m_ukr_ft.h
- frame/3/bli_l3_sup_ft_ker.h -> frame/3/bli_l3_sup_ker_ft.h
to better align with naming of neighboring files.
- Added the missing "void* params" argument to bli_?packm_struc_cxk() in
frame/1m/packm/bli_packm_struc_cxk.c. This argument is being passed
into the function from bli_packm_blk_var1(), but wasn't being "caught"
by the function definition itself. The function prototype for
bli_?packm_struc_cxk() also needed updating.
- Reordered the last two parameters in bli_?packm_struc_cxk().
(Previously, the "void* params" was passed in after the
"const cntx_t* cntx", although because of the above bug the params
argument wasn't actually present in the function definition.)
- (cherry picked from fab18dc)
Use 'const' pointers in kernel APIs. (#722)
Details:
- Qualified all input-only data pointers in the various kernel APIs with
the 'const' keyword while also removing 'restrict' from those kernel
APIs. (Use of 'restrict' was maintained in kernel implementations,
where appropriate.) This affected the function pointer types defined
for all of the kernels, their prototypes, and the reference and
optimized kernel definitions' signatures.
- Templatized the definitions of copys_mxn and xpbys_mxn static inline
functions.
- Minor whitespace and style changes (e.g. combining local variable
declaration and initialization into a single statement).
- Removed some unused kernel code left in 'old' directories.
- Thanks to Nisanth M P for helping to validate changes to the power10
microkernels.
- (cherry picked from 93c63d1)
Details:
- Updated common.mk so that when --disable-shared option is given to
configure:
1. The -fPIC compiler flag is omitted from the individual
configuration family members' CPICFLAGS variables (which are
initialized in each subconfig's make_defs.mk file); and
2. The BUILD_SYMFLAGS variable, which contains compiler flags needed
to control the symbol export behavior, is left blank.
- The net result of these changes is that flags specific to shared
library builds are only used when a shared library is actually
scheduled to be built. Thanks to Nick Knight for reporting this issue.
- CREDITS file update.
- (cherry picked from 5f84130)
Updated configure to pass all shellcheck checks. (#729)
Details:
- Modified configure so that it passes all 'shellcheck' checks,
disabling ones which we violate but which are just stylistic, or are
special cases in our code.
- Miscellaneous other minor changes, such as rearranged redirections in
long sed/perl pipes to look more natural.
- Whitespace tweaks.
- (cherry picked from 72c37eb)
Fixed bugs in scal2v ref kernel when alpha == 1. (#728)
Details:
- Fixed a typo bug in ref_kernels/1/bli_scal2v_ref.c where the
conditional that was supposed to be checking for cases when alpha is
equal to 1.0 (so that copyv could be used instead of scal2v) was
instead erroneously comparing alpha against 0.0.
- Fixed another bug in the same function whereby BLIS_NO_CONJUGATE was
erroneously being passed into copyv instead of the kernel's conjx
parameter. This second bug was inert, however, due to the first bug
since the "alpha == 0.0" case was already being handled, resulting in
the code block never executing.
- (cherry picked from 60f3634)
Use 'void*' datatypes in kernel APIs. (#727)
Details:
- Migrated all kernel APIs to use void* pointers instead of float*,
double*, scomplex*, and dcomplex* pointers. This allows us to define
many fewer kernel function pointer types, which also makes it much
easier to know which function pointer type to use at any given time.
(For example, whereas before there was ?axpyv_ker_ft, ?axpyv_ker_vft,
and axpyv_ker_vft, now there is just axpyv_ker_ft, which is equivalent
so what axpyv_ker_vft used to be.)
- Refactored how kernel function prototypes and kernel function types
are defined so as to reduce redundant code. Specifically, the
function signatures (excluding cntx_t* and, in the case of level-3
microkernels, auxinfo_t*) are defined in new headers named, for
example, bli_l1v_ker_params.h. Those signatures are reused via macro
instantiation when defining both kernel prototypes and kernel function
types. This will hopefully make it a little easier to update, add, and
manage kernel APIs going forward.
- Updated all reference kernels according to the aforementioned switch
to void* pointers.
- Updated all optimzied kernels according to the aforementioned switch
to void* pointers. This sometimes required renaming variables,
inserting typecasting so that pointer arithmetic could continue to
function as intended, and related tweaks.
- Updated sandbox/gemmlike according to the aforementioned switch to
void* pointers.
- Renamed:
- frame/1/bli_l1v_ft_ker.h -> frame/1/bli_l1v_ker_ft.h
- frame/1f/bli_l1f_ft_ker.h -> frame/1f/bli_l1f_ker_ft.h
- frame/1m/bli_l1m_ft_ker.h -> frame/1m/bli_l1m_ker_ft.h
- frame/3/bli_l1m_ft_ukr.h -> frame/3/bli_l1m_ukr_ft.h
- frame/3/bli_l3_sup_ft_ker.h -> frame/3/bli_l3_sup_ker_ft.h
to better align with naming of neighboring files.
- Added the missing "void* params" argument to bli_?packm_struc_cxk() in
frame/1m/packm/bli_packm_struc_cxk.c. This argument is being passed
into the function from bli_packm_blk_var1(), but wasn't being "caught"
by the function definition itself. The function prototype for
bli_?packm_struc_cxk() also needed updating.
- Reordered the last two parameters in bli_?packm_struc_cxk().
(Previously, the "void* params" was passed in after the
"const cntx_t* cntx", although because of the above bug the params
argument wasn't actually present in the function definition.)
- (cherry picked from fab18dc)
Use 'const' pointers in kernel APIs. (#722)
Details:
- Qualified all input-only data pointers in the various kernel APIs with
the 'const' keyword while also removing 'restrict' from those kernel
APIs. (Use of 'restrict' was maintained in kernel implementations,
where appropriate.) This affected the function pointer types defined
for all of the kernels, their prototypes, and the reference and
optimized kernel definitions' signatures.
- Templatized the definitions of copys_mxn and xpbys_mxn static inline
functions.
- Minor whitespace and style changes (e.g. combining local variable
declaration and initialization into a single statement).
- Removed some unused kernel code left in 'old' directories.
- Thanks to Nisanth M P for helping to validate changes to the power10
microkernels.
- (cherry picked from 93c63d1)
Make the BLIS
configurescript pass allshellcheckchecks, disabling ones which we violate but which are just stylistic, or are special cases in our code.# shellcheck disable=2001,2249,2034,2154,2181,2312,2250,2292disables the following checks for the entireconfigurescript:${variable//search/replace}instead.*)case, even if it just exits with error.fooappears unused. Verify it or export it.varis referenced but not assigned. (configureusesevalto assign to variables whose names are runtime variables.)if mycmd;, not indirectly with$?.|| trueto ignore).[[ ]]over[ ]for tests in Bash/Ksh.pass_config_kernel_registries()which prevented a list of more than one configuration from working:The
"${list}"is taken as one item, and word splitting is not performed, so the loop only executes once. It should be:or it should use Bash array variables.
main():should be:
Address SC2268: Avoid x-prefix in comparisons as it no longer serves a purpose. (e.g.,
[ "x$var" = "xvalue"]).Address SC2086: Double quote to prevent globbing and word splitting.
There are many places in the code where variables are expanded but are not quoted, which causes word splitting, and globbing if the variable contains wildcard characters, and can lead to syntax errors if the variable is empty and used in
[ ].When the variable (or command substitution
$( ... )) appears on the LHS or as a unary operand of a[ ]test, then simply replacing[ ]with[[ ]]will avoid the problem, because inside[[ ]], the expansion is syntactically always present in the test, even if it expands to empty.When a variable possibly contains spaces, and it needs to be passed or treated as a single value, it should be double-quoted. As a test, I tried building BLIS in a directory whose name contained spaces.
On the other hand, there are a few places where word splitting is desired, such as building command lines with multiple options separated by spaces, and for those cases, this check has been disabled with
# shellcheck disable=2086.configurewas sometimes printing symbolic names like${prefix}. To fix this, I addedeval echo, two forlibdirin case it defaults to${exec_prefix}andexec_prefixdefaults to${prefix}:becomes:
It now prints out like this:
readwithout-rwill mangle backslashes.There are a few places where
readis used without-r. Unless it is the intention to interpret backslashes as escape characters in files read byconfigure,read -rshould be used.Address SC2196:
egrepis non-standard and deprecated. Usegrep -Einstead.Address SC2244: Prefer explicit
-nto check non-empty string (or use=/-neto check boolean/integer).Address SC2295: Expansions inside
${..}need to be quoted separately, otherwise they will match as a pattern. (Unclear?)$/${}is unnecessary on arithmetic variables.becomes:
$(...)notation instead of legacy backticked`...`.becomes:
cat. Considercmd < file.becomes:
and:
becomes:
and others.
[ p ] && [ q ]as[ p -a q ]is not well defined.Also, for style, use
[[ ]]which has&&and||operators, instead of[ ] && [ ]and[ ] || [ ].Replace:
with:
Similarly, replace:
with:
with:
with:
(Style.) Replace long pipelines of
sedandperlfilters with multiple-escriptlets. Faster and creates fewer processes. Need to add;at the end of each Perl scriptlet, since they get concatenated into one large script.(Style.) Replace 7 long
${gen_make_frags_sh}calls, with all but 3 arguments the same in each case, and with anechobefore each call, with short calls to a newcreate_makefile_fragment()function.(Style.) Replace repeated code which creates
Makefile,blis.pc.in,common.mkandconfigsymlinks, with one loop which iterates over them. Also address SC2226: Thislnhas no destination. Check the arguments, or specify.explicitly.(Style.) Rather than setting a variable with a
grepcommand substitution and then testing whether it is empty, test the assignment command itself, which will return a nonzero exit code if thegrepfails to find a match:becomes:
and:
becomes:
This allows the program to continue in case
set -eis enabled, because it's not considered a fatal error if thegrepfails inside anif.bashpattern-matching instead ofechoandgrep(supersedes #22):becomes:
and:
becomes:
and:
becomes:
configurescript work when errors are fatal (set -e). Add|| :in a few places, such as:this needs to be tested on all supported platforms, perhaps in the CI, to ensure that
set -ecan been enabled inconfigure.Edit: In case it wasn't clear,
set -ehas not been added to theconfigurescript, since it may break it on certain platforms I cannot test; however, clearly obvious places whereset -ewould causeconfigureto fail have been identified and remedied. With the|| :change above,configureworks fine to completion on x86-64 even ifset -eis added beforemainis called. I consider it good practice to make sure a script properly handles every command which returns a non-zero exit code.$(<file)instead of$(cat file)for loading the contents of a file into a shell variable.