Skip to content

Commit

Permalink
issue: 1310745 Add jenkins style verification
Browse files Browse the repository at this point in the history
Codying style check is based on LLVM clang-format
tool.

Signed-off-by: Igor Ivanov <igor.ivanov.va@gmail.com>
  • Loading branch information
igor-ivanov committed May 31, 2018
1 parent ca1fc73 commit 7a08a94
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions contrib/jenkins_tests/globals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ rpm_dir=${WORKSPACE}/${prefix}/rpm
cov_dir=${WORKSPACE}/${prefix}/cov
cppcheck_dir=${WORKSPACE}/${prefix}/cppcheck
csbuild_dir=${WORKSPACE}/${prefix}/csbuild
style_dir=${WORKSPACE}/${prefix}/style


nproc=$(grep processor /proc/cpuinfo|wc -l)
Expand Down
47 changes: 47 additions & 0 deletions contrib/jenkins_tests/style.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# BasedOnStyle: LLVM
AccessModifierOffset: -4
ConstructorInitializerIndentWidth: 4
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakTemplateDeclarations: false
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BinPackParameters: true
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: false
DerivePointerBinding: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 60
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerBindsToType: false
SpacesBeforeTrailingComments: 1
Cpp11BracedListStyle: false
Standard: Cpp03
IndentWidth: 4
TabWidth: 4
UseTab: Never
BreakBeforeBraces: Attach
IndentFunctionDeclarationAfterType: false
SpacesInParentheses: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
...

56 changes: 56 additions & 0 deletions contrib/jenkins_tests/style.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash -xeEl

source $(dirname $0)/globals.sh

do_check_filter "Checking for codying style ..." "on"

cd $WORKSPACE

rm -rf $style_dir
mkdir -p $style_dir
cd $style_dir

test_app="clang-format"

if [ $(command -v $test_app >/dev/null 2>&1 || echo $?) ]; then
echo can not find $test_app
exit 1
fi

style_tap=${WORKSPACE}/${prefix}/style_test.tap
rm -rf $style_tap
ln -sf $WORKSPACE/contrib/jenkins_tests/style.conf $WORKSPACE/.clang-format


check_files=$(find $WORKSPACE/src/ -name '*.c' -o -name '*.cpp' -o -name '*.h')

echo "1..$(echo $check_files | wc -w)" > $style_tap
i=0
nerrors=0

for file in $check_files; do
set +eE
style_diff="${style_dir}/$(basename ${file}).diff"
eval "env $test_app -style=file \
${file} \
| diff -u ${file} - | sed -e '1s|-- |--- a/|' -e '2s|+++ -|+++ b/$file|' \
> ${style_diff} 2>&1"
[ -s ${style_diff} ]
ret=$((1-$?))
nerrors=$((nerrors+ret))
set -eE
i=$((i+1))

file=$(basename ${file})
if [ $ret -gt 0 ]; then
echo "not ok $i $file # See: ${file}.diff" >> $style_tap
else
echo "ok $i $file" >> $style_tap
fi
done

do_archive "${style_dir}/*.diff"
rc=$(($rc+$nerrors))

echo "[${0##*/}]..................exit code = $rc"
exit $rc
11 changes: 11 additions & 0 deletions contrib/test_jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jenkins_test_cov=${jenkins_test_cov:="no"}
jenkins_test_cppcheck=${jenkins_test_cppcheck:="yes"}
jenkins_test_csbuild=${jenkins_test_csbuild:="no"}
jenkins_test_run=${jenkins_test_run:="no"}
jenkins_test_style=${jenkins_test_style:="no"}


echo Starting on host: $(hostname)
Expand Down Expand Up @@ -157,6 +158,16 @@ for target_v in "${target_list[@]}"; do
rc=$((rc + $ret))
fi
fi
if [ 7 -lt "$jenkins_opt_exit" -o "$rc" -eq 0 ]; then
if [ "$jenkins_test_style" = "yes" ]; then
$WORKSPACE/contrib/jenkins_tests/style.sh
ret=$?
if [ $ret -gt 0 ]; then
do_err "case: [style: ret=$ret]"
fi
rc=$((rc + $ret))
fi
fi
set -e

# Archive all logs in single file
Expand Down

0 comments on commit 7a08a94

Please sign in to comment.