-
Notifications
You must be signed in to change notification settings - Fork 50
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
jtb20
wants to merge
37
commits into
ROCm:aomp-dev
Choose a base branch
from
jtb20:shellcheck-fixes-8
base: aomp-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[AOMP] Shellcheck fixes #1252
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7641c37
to
3dac11f
Compare
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.
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.
3dac11f
to
8a77cce
Compare
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.