Skip to content

Commit b2edaaf

Browse files
committed
Move cppcheck logic from Makefile and CMakeLists.txt to tools/check-cppcheck.sh
The legacy approach executed cppcheck for every build target, which resulted in a huge number of re-checks of the sources if more than one targets were built. The main reason behind that was to get the right macro-guarded code paths analyzed. However, cppcheck can analyze every configuration of the sources in one go. (The patch also contains some aesthetic changes around the way vera++ is called and how errors are reported.) JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent be1920d commit b2edaaf

File tree

7 files changed

+49
-136
lines changed

7 files changed

+49
-136
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ install: make prerequisites
1313
script: "make -j VERBOSE=1 NINJA=1 $TARGET"
1414

1515
env:
16-
- TARGET="check-signed-off check-vera check-cpp"
16+
- TARGET="check-signed-off check-vera check-cppcheck"
1717
- TARGET="build.linux test-js-precommit"
1818
- TARGET=build.mcu_stm32f3
1919
- TARGET=build.mcu_stm32f4

CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ project (Jerry C ASM)
4141
set(PREFIX_IMPORTED_LIB imported_)
4242
set(SUFFIX_THIRD_PARTY_LIB .third_party.lib)
4343

44-
# Static checkers
45-
include(build/static-checkers/add_cppcheck_for_target.cmake)
46-
4744
# Architecture-specific compile/link flags
4845
foreach(FLAG ${FLAGS_COMMON_ARCH})
4946
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
@@ -421,8 +418,6 @@ endif()
421418
${FDLIBM_TARGET_NAME} ${PREFIX_IMPORTED_LIB}libgcc)
422419
endif()
423420

424-
add_cppcheck_target(${TARGET_NAME})
425-
426421
if("${PLATFORM}" STREQUAL "MCU")
427422
add_dependencies(${TARGET_NAME} mcu_header_with_script_to_run.${TARGET_NAME})
428423
add_custom_target(${TARGET_NAME}.bin
@@ -466,8 +461,6 @@ endif()
466461
POST_BUILD
467462
COMMAND echo $<TARGET_FILE:${LIBC_TARGET_NAME}> >> ${CMAKE_BINARY_DIR}/${TARGET_NAME}/list)
468463
endif()
469-
470-
add_cppcheck_target(${TARGET_NAME})
471464
endif()
472465
endfunction()
473466

@@ -484,7 +477,6 @@ endif()
484477
# Unit tests declaration
485478
if(("${PLATFORM}" STREQUAL "LINUX") OR ("${PLATFORM}" STREQUAL "DARWIN"))
486479
add_custom_target(unittests)
487-
add_custom_target(cppcheck.unittests)
488480

489481
foreach(SOURCE_UNIT_TEST_MAIN ${SOURCE_UNIT_TEST_MAIN_MODULES})
490482
get_filename_component(TARGET_NAME ${SOURCE_UNIT_TEST_MAIN} NAME_WE)
@@ -512,9 +504,6 @@ endif()
512504
${PREFIX_IMPORTED_LIB}libgcc)
513505
endif()
514506

515-
add_cppcheck_target(${TARGET_NAME})
516-
517507
add_dependencies(unittests ${TARGET_NAME})
518-
add_dependencies(cppcheck.unittests cppcheck.${TARGET_NAME})
519508
endforeach()
520509
endif()

Makefile

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ endif
164164
# $(3) - command description (printed if command fails)
165165
ifdef VERBOSE
166166
define SHLOG
167-
$(1) || (echo "$(3) failed. No log file generated. (Run make without VERBOSE if log is needed.)"; exit 1;)
167+
$(1) || (echo -e "\e[1;33m$(3) failed. No log file generated. (Run make without VERBOSE if log is needed.)\e[0m"; exit 1;)
168168
endef
169169
else
170170
define SHLOG
171-
( mkdir -p $$(dirname $(2)) ; $(1) 2>&1 | tee $(2) >/dev/null ; ( exit $${PIPESTATUS[0]} ) ) || (echo "$(3) failed. See $(2) for details."; exit 1;)
171+
( mkdir -p $$(dirname $(2)) ; $(1) 2>&1 | tee $(2) >/dev/null ; ( exit $${PIPESTATUS[0]} ) ) || (echo -e "\e[1;33m$(3) failed. See $(2) for details.\e[0m"; exit 1;)
172172
endef
173173
endif
174174

@@ -241,35 +241,7 @@ endef
241241
$(foreach __SYSTEM,$(NATIVE_SYSTEM) $(MCU_SYSTEMS), \
242242
$(eval $(call GEN_MAKEFILE_RULE,$(BUILD_DIR)/$(__SYSTEM))))
243243

244-
# Targets to perform build, check, and test steps in the build directories
245-
246-
# Make rule macro to preform cppcheck on a build target.
247-
#
248-
# $(1) - rule to define in the current Makefile
249-
# $(2) - system name
250-
# $(3) - target(s) to check
251-
define CPPCHECK_RULE
252-
.PHONY: $(1)
253-
$(1): $$(BUILD_DIR)/$(2)/Makefile prerequisites
254-
$$(Q) $$(call SHLOG,$$(BUILD_COMMAND) -C $$(BUILD_DIR)/$(2) $(3),$$(BUILD_DIR)/$(2)/$(1).log,cppcheck run)
255-
endef
256-
257-
$(foreach __TARGET,$(JERRY_NATIVE_TARGETS), \
258-
$(eval $(call CPPCHECK_RULE,check-cpp.$(__TARGET),$(NATIVE_SYSTEM),cppcheck.$(__TARGET))))
259-
260-
$(eval $(call CPPCHECK_RULE,check-cpp.$(NATIVE_SYSTEM),$(NATIVE_SYSTEM),$(foreach __TARGET,$(JERRY_NATIVE_TARGETS),cppcheck.$(__TARGET))))
261-
262-
$(foreach __TARGET,$(JERRY_STM32F3_TARGETS), \
263-
$(eval $(call CPPCHECK_RULE,check-cpp.$(__TARGET),stm32f3,cppcheck.$(__TARGET))))
264-
265-
$(eval $(call CPPCHECK_RULE,check-cpp.mcu_stm32f3,stm32f3,$(foreach __TARGET,$(JERRY_STM32F3_TARGETS),cppcheck.$(__TARGET))))
266-
267-
$(foreach __TARGET,$(JERRY_STM32F4_TARGETS), \
268-
$(eval $(call CPPCHECK_RULE,check-cpp.$(__TARGET),stm32f4,cppcheck.$(__TARGET))))
269-
270-
$(eval $(call CPPCHECK_RULE,check-cpp.mcu_stm32f4,stm32f4,$(foreach __TARGET,$(JERRY_STM32F4_TARGETS),cppcheck.$(__TARGET))))
271-
272-
$(eval $(call CPPCHECK_RULE,check-cpp.unittests,$(NATIVE_SYSTEM),cppcheck.unittests))
244+
# Targets to perform build and test steps in the build directories
273245

274246
# Make rule macro to build a/some target(s) and copy out the result(s).
275247
#
@@ -348,11 +320,12 @@ check-signed-off:
348320
$(Q) ./tools/check-signed-off.sh
349321

350322
.PHONY: check-vera
351-
check-vera: prerequisites
352-
$(Q) ./tools/check-vera.sh
323+
check-vera:
324+
$(Q) $(call SHLOG,./tools/check-vera.sh,$(OUT_DIR)/vera.log,Vera++)
353325

354-
.PHONY: check-cpp
355-
check-cpp: check-cpp.$(NATIVE_SYSTEM) $(foreach __SYSTEM,$(MCU_SYSTEMS),check-cpp.mcu_$(__SYSTEM)) check-cpp.unittests
326+
.PHONY: check-cppcheck
327+
check-cppcheck:
328+
$(Q) $(call SHLOG,./tools/check-cppcheck.sh,$(OUT_DIR)/cppcheck.log,Cppcheck)
356329

357330
.PHONY: build
358331
build: build.$(NATIVE_SYSTEM) $(foreach __SYSTEM,$(MCU_SYSTEMS),build.mcu_$(__SYSTEM))
@@ -380,7 +353,7 @@ test-js-precommit: \
380353
precommit: prerequisites
381354
$(Q)+$(MAKE) --no-print-directory clean
382355
$(Q) echo "Running checks..."
383-
$(Q)+$(MAKE) --no-print-directory check-signed-off check-vera check-cpp
356+
$(Q)+$(MAKE) --no-print-directory check-signed-off check-vera check-cppcheck
384357
$(Q) echo "...building engine..."
385358
$(Q)+$(MAKE) --no-print-directory build
386359
$(Q) echo "...building and running unit tests..."

build/static-checkers/add_cppcheck_for_target.cmake

Lines changed: 0 additions & 78 deletions
This file was deleted.

tools/check-cppcheck.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Copyright 2016 Samsung Electronics Co., Ltd.
4+
# Copyright 2016 University of Szeged
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
CPPCHECK_JOBS=${CPPCHECK_JOBS:=$(nproc)}
19+
20+
JERRY_CORE_DIRS=`find jerry-core -type d`
21+
JERRY_LIBC_DIRS=`find jerry-libc -type d`
22+
23+
INCLUDE_DIRS=()
24+
for DIR in $JERRY_CORE_DIRS $JERRY_LIBC_DIRS
25+
do
26+
INCLUDE_DIRS=("${INCLUDE_DIRS[@]}" "-I$DIR")
27+
done
28+
29+
cppcheck -j$CPPCHECK_JOBS --force \
30+
--language=c++ --std=c++11 \
31+
--enable=warning,style,performance,portability,information \
32+
--error-exitcode=1 \
33+
--exitcode-suppressions=tools/cppcheck/suppressions-list \
34+
"${INCLUDE_DIRS[@]}" \
35+
jerry-core jerry-libc *.c *h tests/unit

tools/check-vera.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ JERRY_CORE_FILES=`find ./jerry-core -name "*.c" -or -name "*.cpp" -or -name "*.h
1919
JERRY_LIBC_FILES=`find ./jerry-libc -name "*.c" -or -name "*.cpp" -or -name "*.h"`
2020
JERRY_MAIN_FILES=`find . -maxdepth 1 -name "*.c" -or -name "*.cpp" -or -name "*.h"`
2121

22-
vera++ -r tools/vera++ -p jerry $JERRY_CORE_FILES $JERRY_LIBC_FILES $JERRY_MAIN_FILES -e --no-duplicate
23-
STATUS_CODE=$?
24-
25-
if [ $STATUS_CODE -ne 0 ]
26-
then
27-
echo -e "\e[1;33m vera++ static checks failed. See output above for details. \e[0m\n"
28-
fi
29-
30-
exit $STATUS_CODE
22+
vera++ -r tools/vera++ -p jerry \
23+
-e --no-duplicate \
24+
$JERRY_CORE_FILES $JERRY_LIBC_FILES $JERRY_MAIN_FILES

tools/cppcheck/suppressions-list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ noConstructor
33
duplicateExpression
44

55
// FIXME: false positive in cppcheck 1.61 (will disappear once distro ships with 1.69)
6-
variableScope:*/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c
6+
variableScope:jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c

0 commit comments

Comments
 (0)