Skip to content

[llvm-test-suite] Refactor run script arg parsing to while/case (NFCI)#2248

Merged
jplehr merged 1 commit into
ROCm:aomp-devfrom
jplehr:feat/enable-lib-tests-in-llvm-test-suite-001
Jun 11, 2026
Merged

[llvm-test-suite] Refactor run script arg parsing to while/case (NFCI)#2248
jplehr merged 1 commit into
ROCm:aomp-devfrom
jplehr:feat/enable-lib-tests-in-llvm-test-suite-001

Conversation

@jplehr

@jplehr jplehr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Replace getopts with a while/case parser as groundwork for adding long options. Preserves all existing short flags and bundled forms (e.g. -cbt, -j8, -j 8) with no behavior change.

This will be used in follow-up PRs which add support for enabling "heavier" libraris, e.g., --rocprim as additional targets.

@jplehr jplehr requested review from mhalk and ro-i June 10, 2026 13:55
@ro-i

ro-i commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

If you use getopt as in /usr/bin/getopt instead of the bash builtin getopts, you get support for long options, see man 1 getopt

@ro-i

ro-i commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

I would avoid hand-parsing options at all costs :D

@jplehr

jplehr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

If you use getopt as in /usr/bin/getopt instead of the bash builtin getopts, you get support for long options, see man 1 getopt

I am aware of it and found sources saying it's better not to be used. I don't care which way we go.

@ro-i

ro-i commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

I wasn't aware of those concerns, sorry. But claude thinks:

Why the "avoid getopt" advice exists — and why it's mostly outdated

  • The warning targets legacy/BSD getopt, which mangled whitespace and empty values (it word-split everything).
  • Enhanced getopt (util-linux) fixes this via eval set -- "$(getopt ...)" with proper quoting. It's on essentially every Linux distro.
  • Real catch: enhanced getopt is Linux-only; macOS/BSD ship the broken one. AOMP is ROCm → effectively Linux-only, so this is likely a non-issue here. That's the actual reason the folklore persists.

@mhalk

mhalk commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

While I have no clear preference, IMHO this current use-case is perfectly covered by getopts.
We're using shell scripts on different systems and the options are not that plentiful, so I don't see the benefit of getopt.
If we want "better" arg parsing, something tells me: we won't ever find it in a shell script.

Was just about to point out the concerns but Robert already did :)

@jplehr

jplehr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

While I have no clear preference, IMHO this current use-case is perfectly covered by getopts. We're using shell scripts on different systems and the options are not that plentiful, so I don't see the benefit of getopt. If we want "better" arg parsing, something tells me: we won't ever find it in a shell script.

The reason I'm doing this is to enable us to include long-options, e.g., --rocprim, --kokkos, --ginkgo and similar, which to my understanding getopts does not cover.

@mhalk

mhalk commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Sorry, that flew by me and I was only scanning the code -- it is actually hard to understand this intent TBH (at least for me).
Then getopt might actually be a good option AFAICT.

Replace the getopts builtin with GNU getopt as groundwork for adding long
options. getopt normalizes the argument list (via eval set) so the parse
loop handles long and short options uniformly. Preserves all existing short
flags and bundled forms (e.g. -cbt, -j8, -j 8) with no behavior change.
@jplehr jplehr force-pushed the feat/enable-lib-tests-in-llvm-test-suite-001 branch from 6a22aba to add4d6d Compare June 11, 2026 09:07
@jplehr

jplehr commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Switched the whole thing over to using getopt

@jplehr jplehr marked this pull request as ready for review June 11, 2026 10:49

@mhalk mhalk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@jplehr jplehr merged commit a9e63c1 into ROCm:aomp-dev Jun 11, 2026
1 check passed
@ro-i

ro-i commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

nice, thanks!

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.

3 participants