Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AOMP] Shellcheck fixes #1252

Open
wants to merge 37 commits into
base: aomp-dev
Choose a base branch
from
Open

[AOMP] Shellcheck fixes #1252

wants to merge 37 commits into from

Conversation

jtb20
Copy link
Contributor

@jtb20 jtb20 commented Feb 19, 2025

These patches constitute the result of running Shellcheck (https://www.shellcheck.net/) on the AOMP scripts, mostly build*.sh so far but a few other bits crept in too. With this, "shellcheck -x build*.sh" runs clean, and the resulting patches run "build_aomp.sh" and "run_epsdb_aomp_test.sh" successfully. (I will probably need help with further testing, since there are likely lots of use cases I'm not very familiar with). These patches are mostly quite mechanical, but touch a lot of code.

Some of these bits are less controversial than others. Shellcheck is a little opinionated (e.g. regarding backtick syntax), so we don't necessarily need to do all this stuff, but some things in here are definitely real bugs it found, too.

@jtb20 jtb20 marked this pull request as draft February 19, 2025 17:50
@jtb20 jtb20 force-pushed the shellcheck-fixes-8 branch 2 times, most recently from 7641c37 to 3dac11f Compare February 24, 2025 13:26
jtb20 added 24 commits February 26, 2025 11:51
Factor out helper function to check if installdir is writable.
Add a helper function to quote arguments so they can be safely passed
to a command as a shell string.
Use the new writable_install_dir function instead of duplicating the
check in each script.

Further factoring is possible here for the symlink check, but that's
not done yet.
This patch uses $(...) syntax instead of `...` syntax, which is considered
easier to read and can be nested properly.

Some additional quotation is also introduced here (to prevent word
splitting and globbing).
Parsing 'ls' output is considered fragile, and should be avoided in
shellscripts.  This patch adds a function to find the most recent
version of FileCheck in a particular directory, and uses it in
rocm_quick_check.sh.
This patch fixes a typo and uses correct quotation for the AOMP_NINJA_BIN
variable in aomp_common_vars.
This patch fixes a typo in the shebang line for build-deb-aomp.sh.
The script build_hipcc.sh accidentally checks the wrong environment
variable to verify the source directory.  This succeeds anyway because
[ -d <unset-var> ] evaluates to true.  This patch fixes the condition
to use the correct variable instead.
This patch removes uninitialised var refs in build_qmcpack.sh and
clone_aomp.sh.
This patch removes some variables which are set but not used in various
build scripts.
This patch uses "test -n" in several places instead of "test ! -z".
This patch introduces the "cd ... || exit" (and pushd/popd, etc.) idiom,
to avoid situations where changing directory may fail but the script
carries on executing regardless.
Bare shell variable references are subject to word splitting and globbing,
which can have undesirable side effects.  This patch adds quotation in
"simple" cases throughout the build scripts.
The 'find | xargs' invocation in build_aomp.sh is unsafe in some
degenerate cases.  This patch uses find's '-exec' option instead.
This patch changes quoting for *_RPATH variables to be consistent with the
quoting above.  This also stops shellcheck complaining about non-expansion
of variables in single quotes.
This patch avoids use of $? in many places throughout the build scripts,
preferring 'if cmd' syntax. See https://www.shellcheck.net/wiki/SC2181
for rationale.
This patch uses arrays instead of strings for "cmake" options (and a
few other things) throughout the build scripts.  This makes quotation
easier when options are themselves lists of options (e.g. CFLAGS),
though necessitates the use of bash's slightly unwieldy array syntax in
a few places.
This patch groups echos in build-deb-aomp.sh, to avoid repeatedly
appending to files.
This patch exports the 'log' variable in run_omptests.sh so it can be seen
by check_omptests.sh.  Otherwise the latter cannot access the variable,
and sees it as uninitialised.
This patch avoids parsing 'ls' output in check_omptests.sh,
create_release_tarball.sh and get_trunk_pr_since.
This patch fixes several cases where 'cat' is used unnecessarily, rather
than using an input redirection.
This patch moves some variable initialisations higher in build-rpm.sh
to avoid uninitialised variable references in the intervening code.
Several build scripts set LDFLAGS but do not export it, so the new value
will not be seen by spawned processes.  It turns out that exporting
LDFLAGS causes build failures, so this patch comments out that code for
now, pending further investigation.
This patch fixes edit_installed_hip_file to use a function argument
instead of a global to pass its parameter.
jtb20 added 13 commits February 26, 2025 11:51
This patch uses regexps instead of 'cut' and 'eval' in the clone_test.sh,
clone_aomp.sh and create_release_tarball.sh scripts.
This patch fixes some quotation issues in get_trunk_pr_since.
This patch uses [ ... ] && [ ... ] instead of [ ... && ... ], since the
latter does not appear to be valid syntax.
The use of 'p2rereq_array' appears to be a typo.
The 'llvm_dylib' variable doesn't seem to be set anywhere, so the code
in question looks dead.  This patch comments it out.  (FIXME: Intent?)
The variable 'amd_compiler_symlinks' is not used, since the code below
is commented out.
This patch adds shellcheck 'disable' annotations in several places that
aren't wrong, but show up as false positives with the tool.
If running these scripts under osh (https://oils.pub), stricter semantics
(improved error checking, etc.) can be enabled using this patch.
It should be a no-op under bash.
If "$(which getconf)" fails, running it inside the condition of an 'if'
statement will mask the error.  This patch breaks out the substitution
into a separate line.
This patch initialises the 'list' variable in build_aomp.sh before
appending to it.  This fixes an error running under osh.
This patch simplifies the quoting for SED_INSTALL_DIR in build_extras.sh.
@jtb20 jtb20 force-pushed the shellcheck-fixes-8 branch from 3dac11f to 8a77cce Compare February 26, 2025 17:52
@jtb20 jtb20 marked this pull request as ready for review February 26, 2025 18:06
@jtb20
Copy link
Contributor Author

jtb20 commented Feb 26, 2025

I've fixed various issues with these patches, and the result now completes a "build_aomp.sh" run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant