3 readonly BASEDIR
=$
(readlink
-f $
(dirname $0))/..
11 echo -n "Checking file permissions..."
13 while read -r perm _res0 _res1 path
; do
14 if [ ! -f "$path" ]; then
18 fname
=$
(basename -- "$path")
21 c|h|cpp|cc|cxx|hh|hpp|md|html|js|json|svg|Doxyfile|yml|LICENSE|README|conf|
in|Makefile|mk|gitignore|go|txt
)
22 # These file types should never be executable
23 if [ "$perm" -eq 100755 ]; then
24 echo "ERROR: $path is marked executable but is a code file."
29 shebang
=$
(head -n 1 $path | cut
-c1-3)
31 # git only tracks the execute bit, so will only ever return 755 or 644 as the permission.
32 if [ "$perm" -eq 100755 ]; then
33 # If the file has execute permission, it should start with a shebang.
34 if [ "$shebang" != "#!/" ]; then
35 echo "ERROR: $path is marked executable but does not start with a shebang."
39 # If the file doesnot have execute permissions, it should not start with a shebang.
40 if [ "$shebang" = "#!/" ]; then
41 echo "ERROR: $path is not marked executable but starts with a shebang."
48 done <<< "$(git grep -I --name-only --untracked -e . | git ls-files -s)"
50 if [ $rc -eq 0 ]; then
55 echo -n "Checking coding style..."
56 if [ "$(astyle -V)" \
< "Artistic Style Version 3" ]
58 echo -n " Your astyle version is too old. This may cause failure on patch verification performed by CI. Please update astyle to at least 3.0.1 version..."
62 # Exclude rte_vhost code imported from DPDK - we want to keep the original code
63 # as-is to enable ongoing work to synch with a generic upstream DPDK vhost library,
64 # rather than making diffs more complicated by a lot of changes to follow SPDK
66 git ls-files
'*.[ch]' '*.cpp' '*.cc' '*.cxx' '*.hh' '*.hpp' | \
67 grep -v rte_vhost |
grep -v cpp_headers | \
68 xargs astyle
--options=.astylerc
>> astyle.log
69 if grep -q "^Formatted" astyle.log
; then
70 echo " errors detected"
72 sed -i -e 's/ / /g' astyle.log
73 grep --color=auto
"^Formatted.*" astyle.log
74 echo "Incorrect code style detected in one or more files."
75 echo "The files have been automatically formatted."
76 echo "Remember to add the files to your commit."
83 echo "You do not have astyle installed so your code style is not being checked!"
86 echo -n "Checking comment style..."
88 git
grep --line-number -e '/[*][^ *-]' -- '*.[ch]' > comment.log || true
89 git
grep --line-number -e '[^ ][*]/' -- '*.[ch]' ':!lib/vhost/rte_vhost*/*' >> comment.log || true
90 git
grep --line-number -e '^[*]' -- '*.[ch]' >> comment.log || true
92 if [ -s comment.log
]; then
93 echo " Incorrect comment formatting detected"
101 echo -n "Checking for spaces before tabs..."
102 git
grep --line-number $
' \t' -- > whitespace.log || true
103 if [ -s whitespace.log
]; then
104 echo " Spaces before tabs detected"
112 echo -n "Checking trailing whitespace in output strings..."
114 git
grep --line-number -e ' \\n"' -- '*.[ch]' > whitespace.log || true
116 if [ -s whitespace.log
]; then
117 echo " Incorrect trailing whitespace detected"
125 echo -n "Checking for use of forbidden library functions..."
127 git
grep --line-number -w '\(strncpy\|strcpy\|strcat\|sprintf\|vsprintf\)' -- './*.c' ':!lib/vhost/rte_vhost*/**' > badfunc.log || true
128 if [ -s badfunc.log
]; then
129 echo " Forbidden library functions detected"
137 echo -n "Checking for use of forbidden CUnit macros..."
139 git
grep --line-number -w 'CU_ASSERT_FATAL' -- 'test/*' ':!test/spdk_cunit.h' > badcunit.log || true
140 if [ -s badcunit.log
]; then
141 echo " Forbidden CU_ASSERT_FATAL usage detected - use SPDK_CU_ASSERT_FATAL instead"
149 echo -n "Checking blank lines at end of file..."
151 if ! git
grep -I -l -e .
-z | \
152 xargs -0 -P8 -n1 scripts
/eofnl
> eofnl.log
; then
153 echo " Incorrect end-of-file formatting detected"
161 echo -n "Checking for POSIX includes..."
162 git
grep -I -i -f scripts
/posix.txt
-- './*' ':!include/spdk/stdinc.h' ':!include/linux/**' ':!lib/vhost/rte_vhost*/**' ':!scripts/posix.txt' > scripts
/posix.log || true
163 if [ -s scripts
/posix.log
]; then
164 echo "POSIX includes detected. Please include spdk/stdinc.h instead."
165 cat scripts
/posix.log
170 rm -f scripts
/posix.log
172 if hash pycodestyle
2>/dev
/null
; then
174 elif hash pep8
2>/dev
/null
; then
178 if [ ! -z ${PEP8} ]; then
179 echo -n "Checking Python style..."
181 PEP8_ARGS
+=" --max-line-length=140"
184 git ls-files
'*.py' |
xargs -n1 $PEP8 $PEP8_ARGS > pep8.log || error
=1
185 if [ $error -ne 0 ]; then
186 echo " Python formatting errors detected"
194 echo "You do not have pycodestyle or pep8 installed so your Python style is not being checked!"
197 # Check if any of the public interfaces were modified by this patch.
198 # Warn the user to consider updating the changelog any changes
200 echo -n "Checking whether CHANGELOG.md should be updated..."
201 staged
=$
(git
diff --name-only --cached .
)
202 working
=$
(git status
-s --porcelain |
grep -iv "??" |
awk '{print $2}')
203 files
="$staged $working"
204 if [[ "$files" = " " ]]; then
205 files
=$
(git diff-tree
--no-commit-id --name-only -r HEAD
)
210 if [[ $f == CHANGELOG.md
]]; then
211 # The user has a changelog entry, so exit.
218 if [ $has_changelog -eq 0 ]; then
220 if [[ $f == include
/spdk
/* ]] ||
[[ $f == scripts
/rpc.py
]] ||
[[ $f == etc
/* ]]; then
222 echo -n "$f was modified. Consider updating CHANGELOG.md."
228 if [ $needs_changelog -eq 0 ]; then