1
1
#! /usr/bin/env bash
2
2
3
+ # Ensure that the common script exists and is readable, then verify it has no
4
+ # syntax errors and defines the required function.
5
+ common_script=" $( dirname " $0 " ) /../../scripts/common.sh"
6
+ [ -r " $common_script " ] || { echo " [!] '$common_script ' not found or not readable." >&2 ; exit 1; }
7
+ bash -n " $common_script " > /dev/null 2>&1 || { echo " [!] '$common_script ' contains syntax errors." >&2 ; exit 1; }
8
+ source " $common_script "
9
+ declare -F set_colors > /dev/null 2>&1 || { echo " [!] '$common_script ' does not define the required function." >&2 ; exit 1; }
10
+
3
11
# Build unmatched suppressions for each *.c file.
4
12
cppcheck_build_unmatched () {
5
13
local file suppression=" "
@@ -64,26 +72,25 @@ CPPCHECK_OPTS="-I. --enable=all --error-exitcode=1"
64
72
CPPCHECK_OPTS+=" --force $( cppcheck_suppressions) $( cppcheck_build_unmatched) "
65
73
CPPCHECK_OPTS+=" --cppcheck-build-dir=.out ."
66
74
75
+ set_colors
76
+
67
77
RETURN=0
68
78
69
79
# Disallow non-ASCII characters in workspace path
70
80
workspace=$( git rev-parse --show-toplevel)
71
81
if echo " $workspace " | grep -q " [一-龥]" ; then
72
- echo " [!] The workspace path '$workspace ' contains non-ASCII characters." >&2
73
- exit 1
82
+ throw " The workspace path '$workspace ' contains non-ASCII characters."
74
83
fi
75
84
76
85
CLANG_FORMAT=$( which clang-format)
77
86
if [ $? -ne 0 ]; then
78
- echo " [!] clang-format not installed. Unable to check source file format policy." >&2
79
- exit 1
87
+ throw " clang-format not installed. Unable to check source file format policy."
80
88
fi
81
89
82
90
CPPCHECK=$( which cppcheck)
83
91
mkdir -p .out
84
92
if [ $? -ne 0 ]; then
85
- echo " [!] cppcheck not installed. Unable to perform static analysis." >&2
86
- exit 1
93
+ throw " cppcheck not installed. Unable to perform static analysis."
87
94
fi
88
95
89
96
# Check that cppcheck's version is at least 1.90.
@@ -94,21 +101,18 @@ else
94
101
# For version 1.x, extract the minor version and compare.
95
102
minor_version=$( echo " $cppcheck_ver " | sed -Ee ' s/Cppcheck 1\.([0-9]+)/\1/;q' )
96
103
if [ " $minor_version " -lt 90 ]; then
97
- echo " [!] cppcheck version must be at least 1.90." >&2
98
- echo -e " See Developer Info for building cppcheck from source:\n"
99
- echo -e " https://cppcheck.sourceforge.io/devinfo/" >&2
100
- exit 1
104
+ throw " cppcheck version must be at least 1.90.\n\
105
+ See Developer Info for building cppcheck from source:\n\
106
+ https://cppcheck.sourceforge.io/devinfo/"
101
107
fi
102
108
fi
103
109
104
110
ASPELL=$( which aspell)
105
111
if [ $? -ne 0 ]; then
106
- echo " [!] aspell not installed. Unable to do spelling check." >&2
107
- exit 1
112
+ throw " aspell not installed. Unable to do spelling check."
108
113
fi
109
114
if [ -z " $( aspell dump dicts | grep -E ' ^en$' ) " ]; then
110
- echo " [!] aspell-en not installed. Unable to do spelling check." >&2
111
- exit 1
115
+ throw " aspell-en not installed. Unable to do spelling check."
112
116
fi
113
117
114
118
DIFF=$( which colordiff)
@@ -121,8 +125,7 @@ if command -v sha1sum >/dev/null 2>&1; then
121
125
elif command -v shasum > /dev/null 2>&1 ; then
122
126
SHA1SUM=" shasum"
123
127
else
124
- echo " [!] sha1sum or shasum not installed." >&2
125
- exit 1
128
+ throw " sha1sum or shasum not installed."
126
129
fi
127
130
128
131
# Get staged filenames (added, copied, or modified) into an array.
@@ -137,12 +140,12 @@ for file in "${FILES[@]}"; do
137
140
138
141
if echo " $mime_info " | grep -qi binary; then
139
142
binary_files+=(" $name " )
140
- echo " [!] '$name ' appears to be a binary blob."
143
+ printf " ${RED} [!]${NC} '${YELLOW} $ name${NC} ' appears to be a binary blob.\n "
141
144
fi
142
145
done
143
146
144
147
if [ " ${# binary_files[@]} " -gt 0 ]; then
145
- echo " WARNING: Binary data found"
148
+ printf " ${RED} [!] ${NC} Binary data found.\n "
146
149
fi
147
150
148
151
FILES=$( git diff --cached --name-only --diff-filter=ACMR | grep -E " \.(c|cpp|h)$" )
180
183
181
184
$SHA1SUM -c scripts/checksums 2> /dev/null > /dev/null
182
185
if [ $? -ne 0 ]; then
183
- echo " [!] You are not allowed to change the header file queue.h or list.h" >&2
184
- exit 1
186
+ throw " You are not allowed to change the header file queue.h or list.h"
185
187
fi
186
188
187
189
# Prevent unsafe functions
0 commit comments