Skip to content

Commit 166c6f5

Browse files
Merge pull request #86 from psathyan/clangJob
Add clang-format check along with checkpatch.
2 parents 2278381 + bdd225e commit 166c6f5

File tree

3 files changed

+130
-20
lines changed

3 files changed

+130
-20
lines changed

build_scripts/checkpatch/.checkpatch.conf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,45 @@
7575
# We have the FSF address in a lot of our headers at the moment,
7676
# should clean that up one day but ignoring for now.
7777
--ignore FSF_MAILING_ADDRESS
78+
79+
# We will no longer get grumpy about single line braces
80+
--ignore BRACES
81+
82+
# We use #if 0 to preserve possibly interesting code
83+
--ignore IF_0
84+
--ignore IF_1
85+
86+
--ignore PREFER_DEFINED_ATTRIBUTE_MACRO
87+
--ignore STRLCPY
88+
--ignore DATE_TIME
89+
90+
# @todo FSF work on removing these ones if they make sense...
91+
--ignore BLOCK_COMMENT_STYLE
92+
#--ignore GLOBAL_INITIALISERS
93+
#--ignore UNSPECIFIED_INT
94+
#--ignore LONG_LINE
95+
#--ignore SUSPECT_CODE_INDENT
96+
#--ignore CONSTANT_COMPARISON
97+
#--ignore LINE_SPACING
98+
#--ignore TYPECAST_INT_CONSTANT
99+
100+
# allow split strings
101+
--ignore SPLIT_STRING
102+
103+
# we like symbolic permissions
104+
--ignore SYMBOLIC_PERMS
105+
106+
# we are ok with function prototypes without identifier names
107+
--ignore FUNCTION_ARGUMENTS
108+
109+
--ignore CONST_STRUCT
110+
111+
#retain 80 column max line length
112+
--max-line-length=80
113+
114+
# ignore some annoying things
115+
--ignore COMPLEX_MACRO
116+
--ignore MACRO_WITH_FLOW_CONTROL
117+
--ignore DATE_TIME
118+
--ignore POINTER_LOCATION
119+
--ignore SPACING

jobs/checkpatch.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
- job:
22
name: checkpatch
33
node: cico-workspace
4-
description: "Run checkpatch on nfs-ganesha. This job is triggered by sending a change to https://review.gerrithub.io/#/q/project:ffilz/nfs-ganesha for review\n\nNote: it is possible to retrigger a test for a change by including recheck checkpatch in a comment on GerritHub."
4+
description: >-
5+
Run checkpatch and clang-format on nfs-ganesha. This job is triggered by
6+
sending a change to
7+
https://review.gerrithub.io/#/q/project:ffilz/nfs-ganesha for review.
8+
9+
Note: it is possible to retrigger a test for a change by including recheck
10+
checkpatch in a comment on GerritHub.
511
project-type: freestyle
612
concurrent: true
713
allow-manual-triggers: false

jobs/scripts/checkpatch.sh

Lines changed: 81 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,96 @@
1+
#!/bin/bash
2+
3+
# This script has the following workflow
4+
# 1. Checkout the patch reference
5+
# 2. Run clang format against the review.
6+
# 3. Execute checkpatch
17
set -o pipefail
28
set -x
39

410
if [[ -n "$GERRIT_REFSPEC" ]]; then
5-
GERRIT_REF="$GERRIT_REFSPEC"
6-
REVISION="$GERRIT_PATCHSET_REVISION"
7-
GERRIT_PUBLISH=true
11+
GERRIT_REF="$GERRIT_REFSPEC"
12+
REVISION="$GERRIT_PATCHSET_REVISION"
13+
GERRIT_PUBLISH=true
814
fi
915

10-
if ! [ -d nfs-ganesha ]; then
11-
GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -i $GERRITHUB_KEY" git clone --depth=1 -o gerrit ssh://$GERRIT_USER@review.gerrithub.io:29418/ffilz/nfs-ganesha.git -v
16+
if [ ! -d nfs-ganesha ]; then
17+
GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -i $GERRITHUB_KEY" git \
18+
clone --depth=1 \
19+
-o gerrit \
20+
ssh://$GERRIT_USER@review.gerrithub.io:29418/ffilz/nfs-ganesha.git -v
1221
fi
1322

1423
( cd nfs-ganesha && git fetch gerrit $GERRIT_REF && git checkout $REVISION )
1524

25+
job_url="${JENKINS_URL}/job/checkpatch/${BUILD_NUMBER}/console"
26+
27+
# Install git-clang-format
28+
sudo dnf -qy git-clang-format
29+
30+
pushd nfs-ganesha
31+
git clang-format -v \
32+
--diff \
33+
--style file:src/.clang-format \
34+
--extensions c,cc,cpp,h,hpp \
35+
HEAD~1
36+
RETURN_VALUE=$?
37+
popd
38+
39+
# Post message
40+
case ${RETURN_VALUE} in
41+
0)
42+
MESSAGE="${job_url}: Success."
43+
VERIFIED="--verified +1"
44+
NOTIFY="--notify NONE"
45+
EXIT=0
46+
;;
47+
1)
48+
MESSAGE="${job_url}: Failed"
49+
VERIFIED='--verified -1'
50+
NOTIFY="--notify all"
51+
EXIT=1
52+
;;
53+
*)
54+
MESSAGE="${job_url}: UNKNOWN"
55+
VERIFIED=''
56+
NOTIFY="--notify NONE"
57+
EXIT=1
58+
;;
59+
esac
60+
61+
if [ "${GERRIT_PUBLISH}" == "true" ]; then
62+
ssh \
63+
-l ${GERRIT_USER} \
64+
-i ${GERRITHUB_KEY} \
65+
-o StrictHostKeyChecking=no \
66+
-p ${GERRIT_PORT} \
67+
${GERRIT_HOST} \
68+
gerrit review \
69+
--message "'${MESSAGE}'" \
70+
--project ${GERRIT_PROJECT} \
71+
${VERIFIED} \
72+
${NOTIFY} \
73+
${GERRIT_PATCHSET_REVISION}
74+
else
75+
echo "Clang format review is not posted"
76+
fi
77+
1678
publish_checkpatch() {
17-
local SSH_GERRIT="ssh -p 29418 -i $GERRITHUB_KEY $GERRIT_USER@review.gerrithub.io"
18-
if [[ "$GERRIT_PUBLISH" == "true" ]]; then
19-
tee /proc/$$/fd/1 | $SSH_GERRIT "gerrit review --json --project ffilz/nfs-ganesha $REVISION"
20-
else
21-
echo "Would have submit:"
22-
echo -n "echo '"
23-
cat
24-
echo "' | $SSH_GERRIT \"gerrit review --json --project ffilz/nfs-ganesha $REVISION\""
79+
local SSH_GERRIT="ssh -p 29418 -i $GERRITHUB_KEY $GERRIT_USER@review.gerrithub.io"
80+
81+
if [[ "$GERRIT_PUBLISH" == "true" ]]; then
82+
tee /proc/$$/fd/1 | \
83+
$SSH_GERRIT "gerrit review --json --project ffilz/nfs-ganesha $REVISION"
84+
else
85+
echo "Would have submit:"
86+
echo -n "echo '"
87+
cat
88+
echo "' | $SSH_GERRIT \"gerrit review --json --project ffilz/nfs-ganesha $REVISION\""
2589
fi
2690
}
2791

2892
# cd to ~/checkpatch for checkpatch.pl as a hack to get config without modifying $HOME
29-
GIT_DIR=nfs-ganesha/.git git show --format=email | \
30-
( cd $WORKSPACE/ci-tests/build_scripts/checkpatch && ./checkpatch.pl -q - || true ) | \
31-
python $WORKSPACE/ci-tests/build_scripts/checkpatch/checkpatch-to-gerrit-json.py | \
32-
publish_checkpatch
33-
34-
93+
GIT_DIR=nfs-ganesha/.git git show --format=email | \
94+
(cd $WORKSPACE/ci-tests/build_scripts/checkpatch && ./checkpatch.pl -q - || true ) | \
95+
python $WORKSPACE/ci-tests/build_scripts/checkpatch/checkpatch-to-gerrit-json.py | \
96+
publish_checkpatch

0 commit comments

Comments
 (0)