Skip to content

Commit ef461e3

Browse files
Fixing scripts and configuration of cppcheck and vera++, adding some vera++ rules.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
1 parent 1669c3e commit ef461e3

File tree

8 files changed

+427
-22
lines changed

8 files changed

+427
-22
lines changed

build/static-checkers/add_cppcheck_for_target.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
# Cppcheck launcher
16-
set(CMAKE_CPPCHECK ${CMAKE_SOURCE_DIR}/tools/cppcheck.sh)
16+
set(CMAKE_CPPCHECK ${CMAKE_SOURCE_DIR}/tools/cppcheck/cppcheck.sh)
1717

1818
# Definition of cppcheck targets
1919
add_custom_target(cppcheck)

tools/cppcheck.sh renamed to tools/cppcheck/cppcheck.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
BASE=$(dirname $0)/../third-party/tools/cppcheck
17+
REPOSITORY_DIR=$(dirname $0)/../..
18+
CPPCHECK=$REPOSITORY_DIR/third-party/cppcheck/cppcheck
19+
SUPPRESSIONS_LIST=$(dirname $0)/suppressions-list
1820

19-
if [ ! -x $BASE/$(uname -m)/cppcheck ]
21+
if [ ! -x $CPPCHECK ]
2022
then
2123
exit 1;
2224
fi
2325

24-
$BASE/$(uname -m)/cppcheck "$@" "--exitcode-suppressions=$BASE/cfg/suppressions-list"
26+
$CPPCHECK "$@" "--exitcode-suppressions=$SUPPRESSIONS_LIST"
2527
status_code=$?
2628

2729
exit $status_code

tools/cppcheck/suppressions-list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
operatorEqVarError

tools/precommit.sh

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,18 @@ shift
2323
TARGETS="$1"
2424
shift
2525

26-
PARSE_ONLY_TESTING_PATHS="./tests/benchmarks/jerry"
27-
FULL_TESTING_PATHS="./tests/jerry ./tests/jerry-test-suite/precommit_test_list"
26+
VERA_DIRECTORIES_EXCLUDE_LIST="-path ./third-party -o -path tests"
27+
VERA_CONFIGURATION_PATH="./tools/vera++"
2828

29-
VERA=`which vera++`
30-
if [ -x "$VERA" ]
31-
then
32-
VERA_DIRECTORIES_EXCLUDE_LIST="-path ./third-party -o -path tests"
33-
VERA_SCRIPTS_PATH="./tools/vera++"
34-
35-
SOURCES_AND_HEADERS_LIST=`find . -type d \( $VERA_DIRECTORIES_EXCLUDE_LIST \) -prune -or -name "*.c" -or -name "*.cpp" -or -name "*.h"`
36-
vera++ -r $VERA_SCRIPTS_PATH -p jerry $SOURCES_AND_HEADERS_LIST -e --no-duplicate
37-
STATUS_CODE=$?
29+
SOURCES_AND_HEADERS_LIST=`find . -type d \( $VERA_DIRECTORIES_EXCLUDE_LIST \) -prune -or -name "*.c" -or -name "*.cpp" -or -name "*.h"`
30+
./tools/vera++/vera.sh -r $VERA_CONFIGURATION_PATH -p jerry $SOURCES_AND_HEADERS_LIST -e --no-duplicate
31+
STATUS_CODE=$?
3832

39-
if [ $STATUS_CODE -ne 0 ]
40-
then
41-
echo -e "\e[1;33m vera++ static checks failed. See output above for details. \e[0m\n"
33+
if [ $STATUS_CODE -ne 0 ]
34+
then
35+
echo -e "\e[1;33m vera++ static checks failed. See output above for details. \e[0m\n"
4236

43-
exit $STATUS_CODE
44-
fi
45-
else
46-
echo -e "\e[1;33m Warning: vera++ not installed, skipping corresponding static checks. \e[0m\n"
37+
exit $STATUS_CODE
4738
fi
4839

4940
echo -e "\nBuilding...\n\n"

tools/vera++/profiles/jerry

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set rules {
2+
jerry_indentation
3+
jerry_switch_case
4+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/tclsh
2+
3+
# Copyright 2014-2015 Samsung Electronics Co., Ltd.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Indentation
18+
19+
foreach fileName [getSourceFileNames] {
20+
set indent 0
21+
set lastCheckedLineNumber -1
22+
set is_in_comment "no"
23+
set is_in_pp_define "no"
24+
set is_in_class "no"
25+
set parentheses_level 0
26+
27+
foreach token [getTokens $fileName 1 0 -1 -1 {}] {
28+
set type [lindex $token 3]
29+
set lineNumber [lindex $token 1]
30+
31+
if {$is_in_comment == "yes"} {
32+
set is_in_comment "no"
33+
}
34+
35+
if {$type == "newline"} {
36+
set is_in_pp_define "no"
37+
} elseif {$type == "class"} {
38+
set is_in_class "yes"
39+
} elseif {$is_in_class == "yes" && $type == "semicolon" && $indent == 0} {
40+
set is_in_class "no"
41+
} elseif {$type == "ccomment"} {
42+
set is_in_comment "yes"
43+
} elseif {[string first "pp_" $type] == 0} {
44+
if {$type == "pp_define"} {
45+
set is_in_pp_define "yes"
46+
}
47+
48+
set lastCheckedLineNumber $lineNumber
49+
} elseif {$type == "space"} {
50+
} elseif {$type != "eof"} {
51+
if {$type == "rightbrace"} {
52+
incr indent -2
53+
}
54+
55+
if {$is_in_pp_define == "no" && $is_in_comment == "no" && $is_in_class == "no" && $parentheses_level == 0} {
56+
set line [getLine $fileName $lineNumber]
57+
58+
if {$lineNumber != $lastCheckedLineNumber} {
59+
if {[string length $line] == 0} {
60+
}
61+
62+
if {[regexp {^[[:blank:]]*} $line match]} {
63+
set real_indent [string length $match]
64+
if {$indent != $real_indent} {
65+
if {![regexp {^[[:alnum:]_]{1,}:$} $line] || $real_indent != 0} {
66+
report $fileName $lineNumber "Indentation: $real_indent -> $indent. Line: '$line'"
67+
}
68+
}
69+
}
70+
}
71+
72+
if {$lineNumber == $lastCheckedLineNumber} {
73+
if {$type == "leftbrace"} {
74+
if {![regexp {^[[:blank:]]*\{[[:blank:]]*$} $line]
75+
&& ![regexp {[^\{=]=[^\{=]\{.*\},?} $line]} {
76+
report $fileName $lineNumber "Left brace is not the only non-space character in the line: '$line'"
77+
}
78+
}
79+
if {$type == "rightbrace"} {
80+
if {![regexp {^.* = .*\{.*\}[,;]?$} $line]
81+
&& ![regexp {[^\{=]=[^\{=]\{.*\}[,;]?} $line]} {
82+
report $fileName $lineNumber "Right brace is not first non-space character in the line: '$line'"
83+
}
84+
}
85+
}
86+
if {$type == "rightbrace"} {
87+
if {![regexp {^[[:blank:]]*\}((( [a-z_\(][a-z0-9_\(\)]{0,}){1,})?;| /\*.*\*/| //.*)?$} $line]
88+
&& ![regexp {[^\{=]=[^\{=]\{.*\}[,;]?} $line]} {
89+
report $fileName $lineNumber "Right brace is not the only non-space character in the line and \
90+
is not single right brace followed by \[a-z0-9_() \] string and single semicolon character: '$line'"
91+
}
92+
}
93+
}
94+
95+
if {$type == "leftbrace"} {
96+
incr indent 2
97+
} elseif {$type == "leftparen"} {
98+
incr parentheses_level 1
99+
} elseif {$type == "rightparen"} {
100+
incr parentheses_level -1
101+
}
102+
103+
set lastCheckedLineNumber $lineNumber
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)