mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-11-16 04:24:43 +00:00
I got a review comment [1] because I forgot to do "space before paren". I realized I forgot to run check_GNU_style.py, a script from the GCC repo, which warns about things like this. [ The python script has been around since 2017 (and an earlier version written in shell script since 2010). ] So for this change in gdb/gdb.c: ... - return gdb_main (&args); + return gdb_main(&args); ... we get: ... $ ./contrib/check_GNU_style.py <(git diff) === ERROR type #1: there should be exactly one space between function name \ and parenthesis (1 error(s)) === gdb/gdb.c:38:17: return gdb_main(&args); ... Add a pre-commit hook to do this automatically. This copies two files from the GCC repo to root-level contrib, and adds a wrapper script gdb/contrib/check-gnu-style-pre-commit.sh (checked with shellcheck). The wrapper script is setup to not fail on violations, so the messages are informational at this point. I'm not sure all checks are 100% applicable to our coding style. The python script check_GNU_style.py has two dependencies: unidiff and termcolor, which users need to install themselves. The check is added at the pre-commit stage. I also considered post-commit, and I'm still not sure what is the better choice. As with all pre-commit checks, if the check is not to your liking, you can use SKIP=check-gnu-style to skip it. In summary, with the new pre-commit check we get: ... $ git commit -a -m "style error" black...............................................(no files to check)Skipped flake8..............................................(no files to check)Skipped isort...............................................(no files to check)Skipped codespell...........................................(no files to check)Skipped check-include-guards................................(no files to check)Skipped check-gnu-style.........................................................Passed - hook id: check-gnu-style - duration: 0.04s === ERROR type #1: there should be exactly one space between function name \ and parenthesis (1 error(s)) === gdb/gdb.c:38:17: return gdb_main(&args); tclint..............................................(no files to check)Skipped black...............................................(no files to check)Skipped flake8..............................................(no files to check)Skipped codespell...........................................(no files to check)Skipped check-include-guards................................(no files to check)Skipped codespell-log...........................................................Passed - hook id: codespell-log - duration: 0.19s tclint...............................................(no files to check)Skipped [master $hex] style error ... Approved-By: Simon Marchi <simon.marchi@efficios.com> [1] https://sourceware.org/pipermail/gdb-patches/2025-September/220983.html
43 lines
1.0 KiB
Bash
Executable File
43 lines
1.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Copyright (C) 2025 Free Software Foundation, Inc.
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
set -e
|
|
|
|
scriptdir=$(cd "$(dirname "$0")" || exit 1; pwd -P)
|
|
|
|
tmp=""
|
|
|
|
cleanup()
|
|
{
|
|
if [ "$tmp" != "" ]; then
|
|
rm -f "$tmp"
|
|
fi
|
|
}
|
|
|
|
# Schedule cleanup.
|
|
trap cleanup EXIT
|
|
|
|
# Get temporary file.
|
|
tmp=$(mktemp)
|
|
|
|
# Generate patch.
|
|
git diff --staged "$@" \
|
|
> "$tmp"
|
|
|
|
# Verify patch. Ignore exit status.
|
|
"$scriptdir"/../../contrib/check_GNU_style.py "$tmp" \
|
|
|| true
|