Skip to content

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 3 times, most recently 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.

@jtb20 jtb20 force-pushed the shellcheck-fixes-8 branch 2 times, most recently from 0d3409a to a2c7ecc Compare May 15, 2025 16:00
@jtb20
Copy link
Contributor Author

jtb20 commented May 15, 2025

This version's rebased, and has had a couple of minor tweaks (e.g. around argument quoting). It still mostly covers only the top-level build*.sh scripts.

Copy link
Contributor

@estewart08 estewart08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan on squashing this?

Copy link
Contributor

@dpalermo dpalermo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't land this today (Friday). There are a lot of scripts changed here that will affect things beyond build_aomp.sh (e.g. nightly CI). I would also like to try this out a bit in a sandbox before letting the nightlies run with these changes. I will remove the change request and give approval when I have a few tests run with this (and it isn't Friday ;-).

@gregrodgers
Copy link
Contributor

dont land this till after 21.0-1 is released and we move development to 21.0-2. I will land this myself after I study this some more.

@jtb20 jtb20 force-pushed the shellcheck-fixes-8 branch 2 times, most recently from 3a3871f to 9f6d775 Compare May 20, 2025 09:03
@saiislam
Copy link
Member

Any plans to add a .shellcheckrc file also?

# .shellcheckrc for build_aomp.sh and related scripts
 
# Exclude warnings that are common in build_aomp.sh and are reviewed:
#   SC1090, SC1091: Not following sourced files (dynamic paths)
#   SC2086: Double-quoting variables in command arguments (intentional in some cases)
#   SC2155: Declare and assign local variables on the same line (for brevity)
exclude=SC1090,SC1091,SC2086,SC2155
 
# Set severity level: error, warning, info, style
severity=warning
 
# End of .shellcheckrc

@dpalermo dpalermo self-requested a review June 2, 2025 14:26
Copy link
Contributor

@dpalermo dpalermo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patch does not currently apply cleanly to amd-staging. Please rebase and I will retry these changes with the nightly build.

@ronlieb
Copy link
Contributor

ronlieb commented Jun 2, 2025 via email

@dpalermo
Copy link
Contributor

dpalermo commented Jun 2, 2025

Sorry wrong branch in previous comment. Build was amd-staging, but yes aomp was aomp-dev. Still need this patch rebased before I can retest.

jtb20 added 7 commits June 2, 2025 11:49
Factor out helper function to check if installdir is writable.
Add a helper functions to quote a list of arguments so it can be
safely passed to cmake as a single string argument (cmquot), or to be
reinterpreted by the shell as a string (shquot).
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.
jtb20 added 27 commits June 2, 2025 11:49
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 build_supp.sh, 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?)
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 9f6d775 to bb6c1f5 Compare June 2, 2025 17:55
Copy link
Contributor

@dpalermo dpalermo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine with the nightly build scripts. Did another pass through the patch and all changes look good to me. Thanks!

@jtb20 jtb20 merged commit 1f724e8 into ROCm:aomp-dev Jun 3, 2025
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.

6 participants