aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2020-07-07 08:43:57 -0700
committerMartin Mathieson <martin.r.mathieson@googlemail.com>2020-07-07 18:18:45 +0000
commite9a21e9f41bea590a71611c0e9f4c5402a0dc54e (patch)
treeaf72a10ff5cf2dbc6f00fd5012e7f9931dc540fd /tools
parent3c37494ea67d8e991dfcfc95645a6b5a07374731 (diff)
cppcheck: Bail if "-l <n>" or "-o" don't find any files.
If we've been passed "-l <n>" and the last <n> commits don't match any C or C++ files or we've been passed "-o" and no files have been changed, simply exit instead of testing the entire code base. We use "cppcheck.sh -l <n>" in our CI system and the former behavior is much more useful (and faster) than the latter. Change-Id: I1127eabefa854d68f80b0a2dfd05e6895658abc0 Reviewed-on: https://code.wireshark.org/review/37773 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Reviewed-by: Martin Mathieson <martin.r.mathieson@googlemail.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/cppcheck/cppcheck.sh21
1 files changed, 18 insertions, 3 deletions
diff --git a/tools/cppcheck/cppcheck.sh b/tools/cppcheck/cppcheck.sh
index b7f78f3908..9730773acf 100755
--- a/tools/cppcheck/cppcheck.sh
+++ b/tools/cppcheck/cppcheck.sh
@@ -58,6 +58,15 @@ colorize()
[ -z "$1" ] && colorize_worker || colorize_worker <<< "$1"
}
+exit_cleanup() {
+ if [ "$MODE" = "html" ]; then
+ echo "</table></body></html>"
+ fi
+ if [ -z "$1" ] ; then
+ exit "$1"
+ fi
+}
+
while getopts "achxj:l:ov" OPTCHAR ; do
case $OPTCHAR in
a) SUPPRESSIONS=" " ;;
@@ -87,11 +96,19 @@ fi
if [ "$LAST_COMMITS" -gt 0 ] ; then
TARGET=$( git diff --name-only HEAD~"$LAST_COMMITS".. | grep -E '\.(c|cpp)$' )
+ if [ -z "$TARGET" ] ; then
+ echo "No C or C++ files found in the last $LAST_COMMITS commit(s)."
+ exit_cleanup 0
+ fi
fi
if [ "$OPEN_FILES" = "yes" ] ; then
TARGET=$(git diff --name-only | grep -E '\.(c|cpp)$' )
TARGET="$TARGET $(git diff --staged --name-only | grep -E '\.(c|cpp)$' )"
+ if [ -z "$TARGET" ] ; then
+ echo "No C or C++ files are currently opened (modified or added for next commit)."
+ exit_cleanup 0
+ fi
fi
if [ $# -gt 0 ]; then
@@ -119,9 +136,7 @@ $CPPCHECK --force --enable=style $QUIET \
--std=c99 --template=$TEMPLATE \
-j $THREADS $TARGET $XML_ARG 2>&1 | colorize
-if [ "$MODE" = "html" ]; then
- echo "</table></body></html>"
-fi
+exit_cleanup
#
# Editor modelines - https://www.wireshark.org/tools/modelines.html