Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [pushed] [gdb] Make po/gdbtext shellcheck-clean
@ 2026-08-28  8:38 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2026-08-28  8:38 UTC (permalink / raw)
  To: gdb-patches

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
---
 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 "$@"

base-commit: c562e4ffa94c50ee974200a7457e435cec411a43
-- 
2.51.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-08-28  8:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-28  8:38 [pushed] [gdb] Make po/gdbtext shellcheck-clean Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox