From: Christian Goeschel Ndjomouo Date: Sun, 21 Dec 2025 20:07:10 +0000 (-0500) Subject: tools: (checkusage.sh) verify the completeness of listed long options X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b0350822a0555421f29b28613dc06a4813aa806;p=thirdparty%2Futil-linux.git tools: (checkusage.sh) verify the completeness of listed long options Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/Makefile.am b/Makefile.am index dd78a5345..75bab88f4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -339,9 +339,10 @@ checkcompletion: @ $(top_srcdir)/tools/checkcompletion.sh $(top_srcdir) checkusage: - @ $(top_srcdir)/tools/checkusage.sh \ + @ $(top_srcdir)/tools/checkusage.sh $(top_srcdir) \ $(bin_PROGRAMS) $(sbin_PROGRAMS) \ $(usrbin_exec_PROGRAMS) $(usrsbin_exec_PROGRAMS) + checklibdoc: @ $(top_srcdir)/tools/checklibdocs.sh \ $(top_srcdir)/libmount/src/libmount.sym \ diff --git a/tools/checkusage.sh b/tools/checkusage.sh index 69d69fde1..4af5848ba 100755 --- a/tools/checkusage.sh +++ b/tools/checkusage.sh @@ -11,6 +11,13 @@ if [ "$#" -lt 1 ]; then exit 1 fi +top_srcdir=${1:-.} +if [ -d "${top_srcdir}" ]; then + shift 1 +else + echo "directory '${top_srcdir}' not found" >&2 + exit 1 +fi builddir="." cmds=$(echo $@ | tr ' ' '\n' | sort) @@ -142,6 +149,39 @@ function check_unknownopt { fi } +function check_usage_long_options_completeness { + local prog="$1" + + prog_long_opts="$( TOP_SRCDIR="${top_srcdir}" "${top_srcdir}"/tools/get-options.sh "$prog" \ + | sed -e 's/^$//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + + if [[ "$?" != "0" || -z "$prog_long_opts" ]]; then + echo "Failed to get long options for $prog" + return 1 + fi + + if [ "$prog_long_opts" == "ENOTSUP" ]; then + return 0 + fi + + usage_long_opts="$( "${builddir}"/"$prog" --help \ + | grep -o -P '^.*[[:space:]]*--(?![^[:alnum:]])[A-Za-z-.0-9_]*' \ + | grep -o -P '[[:space:]]*--(?![^[:alnum:]])[A-Za-z-.0-9_]*' \ + | sed -e 's/^$//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' \ + | sort \ + | uniq \ + )" + + res="$( comm -23 <(echo "${prog_long_opts}") <(echo "${usage_long_opts}") )" + if [ -n "$res" ]; then + printf "%s\n%s\n" "${prog} (missing/extraneous option(s) in usage):" "$res" + return 1 + fi + + return 0 +} + +rc=0 for cb in $cmds; do c="$builddir/$cb" if ! type "$c" &>/dev/null; then @@ -155,5 +195,8 @@ for cb in $cmds; do fi check_version "$cb" "$c" check_unknownopt "$cb" "$c" "$nohelp" + + check_usage_long_options_completeness "$cb" || ((rc++)) done +exit $rc