[binutils-gdb] [gdb] Make po/gdbtext shellcheck-clean
Tom de Vries via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1469a04f30917ef6a2bf4afc73e442b836574563 commit 1469a04f30917ef6a2bf4afc73e442b836574563 Author: Tom de Vries <[email protected]> Date: Fri Aug 28 10:37:44 2026 +0200 [gdb] Make po/gdbtext shellcheck-clean Make po/gdbtext shellcheck-clean. First: - add missing quotes in a few places - do "find *" -> "find -- *" Then, restructure the code into two functions, leaving just: ... find_files "$@" \ | run_xgettext "$@" ... and fix: ... In gdb/po/gdbtext line 38: ${__directories} \ ^--------------^ SC2086 (info): Double quote to prevent globbing and word splitting. ... by eliminating the variable and using "set --" [1] instead. Tested on x86_64-linux by running make po/gdb.pot and comparing po/gdb.pot with and without the patch. Also add an entry in gdb/.gitattributes to ensure whitespace errors are detected. [1] https://www.shellcheck.net/wiki/SC2086 Diff: --- gdb/.gitattributes | 1 + gdb/contrib/shellcheck.sh | 1 - gdb/po/gdbtext | 77 ++++++++++++++++++++++++++++++----------------- 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/gdb/.gitattributes b/gdb/.gitattributes index f176977e7aa..9cb0318dca8 100644 --- a/gdb/.gitattributes +++ b/gdb/.gitattributes @@ -20,6 +20,7 @@ aclocal.m4 -whitespace *.[ly] whitespace=space-before-tab,indent-with-non-tab,trailing-space *.def whitespace=space-before-tab,indent-with-non-tab,trailing-space +po/gdbtext whitespace=space-before-tab,indent-with-non-tab,trailing-space # Imported files. exc_request.defs -whitespace diff --git a/gdb/contrib/shellcheck.sh b/gdb/contrib/shellcheck.sh index 64a6b8b6b22..f7f7bf9efbf 100755 --- a/gdb/contrib/shellcheck.sh +++ b/gdb/contrib/shellcheck.sh @@ -47,7 +47,6 @@ for f in "$@"; do | gdb/contrib/gdb-add-index.sh \ | gdb/gdb_buildall.sh \ | gdb/gdb_mbuild.sh \ - | gdb/po/gdbtext \ | gdb/regformats/regdat.sh \ | gdb/testsuite/lib/pdtrace.in) # Skip unclean files. diff --git a/gdb/po/gdbtext b/gdb/po/gdbtext index 37cd6dd3ae9..152a0dba0c4 100755 --- a/gdb/po/gdbtext +++ b/gdb/po/gdbtext @@ -9,31 +9,54 @@ fi xgettext=$1 ; shift package=$1 ; shift -for d in "$@" -do - __directories="$__directories --directory=$d" -done +find_files () +{ + for d in "$@"; do + ( + cd "$d" + find -- * \ + -name '*-stub.c' -prune -o \ + -name 'testsuite' -prune -o \ + -name 'init.c' -prune -o \ + -name '*.[hc]' -print -o \ + -name '*.cc' -print + ) + done +} -for d in "$@" -do - ( - cd $d - find * \ - -name '*-stub.c' -prune -o \ - -name 'testsuite' -prune -o \ - -name 'init.c' -prune -o \ - -name '*.[hc]' -print -o \ - -name '*.cc' -print - ) -done | ${xgettext} \ - --default-domain=${package} \ - --copyright-holder="Free Software Foundation, Inc." \ - --add-comments \ - --files-from=- \ - --force-po \ - --debug \ - --language=c++ \ - --keyword=_ \ - --keyword=N_ \ - ${__directories} \ - -o po/${package}.pot +run_xgettext () +{ + # Transform: + # "$@" == "arg1" "arg2" ... + # into: + # "$@" == "--directory=arg1" "--directory=arg2" ... + first=true + for d in "$@"; do + if $first; then + # Clear "$@", before we start appending to it. + set -- + first=false + fi + + # Append to "$@". + set -- \ + "$@" \ + --directory="$d" + done + + ${xgettext} \ + --default-domain="${package}" \ + --copyright-holder="Free Software Foundation, Inc." \ + --add-comments \ + --files-from=- \ + --force-po \ + --debug \ + --language=c++ \ + --keyword=_ \ + --keyword=N_ \ + "$@" \ + -o po/"${package}".pot +} + +find_files "$@" \ + | run_xgettext "$@"