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 akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss 2016-02-18 17:28:00 +01:00
parent be1920dc46
commit b2edaafaa1
7 changed files with 49 additions and 136 deletions

View File

@ -13,7 +13,7 @@ install: make prerequisites
script: "make -j VERBOSE=1 NINJA=1 $TARGET"
env:
- TARGET="check-signed-off check-vera check-cpp"
- TARGET="check-signed-off check-vera check-cppcheck"
- TARGET="build.linux test-js-precommit"
- TARGET=build.mcu_stm32f3
- TARGET=build.mcu_stm32f4

View File

@ -41,9 +41,6 @@ project (Jerry C ASM)
set(PREFIX_IMPORTED_LIB imported_)
set(SUFFIX_THIRD_PARTY_LIB .third_party.lib)
# Static checkers
include(build/static-checkers/add_cppcheck_for_target.cmake)
# Architecture-specific compile/link flags
foreach(FLAG ${FLAGS_COMMON_ARCH})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
@ -421,8 +418,6 @@ endif()
${FDLIBM_TARGET_NAME} ${PREFIX_IMPORTED_LIB}libgcc)
endif()
add_cppcheck_target(${TARGET_NAME})
if("${PLATFORM}" STREQUAL "MCU")
add_dependencies(${TARGET_NAME} mcu_header_with_script_to_run.${TARGET_NAME})
add_custom_target(${TARGET_NAME}.bin
@ -466,8 +461,6 @@ endif()
POST_BUILD
COMMAND echo $<TARGET_FILE:${LIBC_TARGET_NAME}> >> ${CMAKE_BINARY_DIR}/${TARGET_NAME}/list)
endif()
add_cppcheck_target(${TARGET_NAME})
endif()
endfunction()
@ -484,7 +477,6 @@ endif()
# Unit tests declaration
if(("${PLATFORM}" STREQUAL "LINUX") OR ("${PLATFORM}" STREQUAL "DARWIN"))
add_custom_target(unittests)
add_custom_target(cppcheck.unittests)
foreach(SOURCE_UNIT_TEST_MAIN ${SOURCE_UNIT_TEST_MAIN_MODULES})
get_filename_component(TARGET_NAME ${SOURCE_UNIT_TEST_MAIN} NAME_WE)
@ -512,9 +504,6 @@ endif()
${PREFIX_IMPORTED_LIB}libgcc)
endif()
add_cppcheck_target(${TARGET_NAME})
add_dependencies(unittests ${TARGET_NAME})
add_dependencies(cppcheck.unittests cppcheck.${TARGET_NAME})
endforeach()
endif()

View File

@ -164,11 +164,11 @@ endif
# $(3) - command description (printed if command fails)
ifdef VERBOSE
define SHLOG
$(1) || (echo "$(3) failed. No log file generated. (Run make without VERBOSE if log is needed.)"; exit 1;)
$(1) || (echo -e "\e[1;33m$(3) failed. No log file generated. (Run make without VERBOSE if log is needed.)\e[0m"; exit 1;)
endef
else
define SHLOG
( mkdir -p $$(dirname $(2)) ; $(1) 2>&1 | tee $(2) >/dev/null ; ( exit $${PIPESTATUS[0]} ) ) || (echo "$(3) failed. See $(2) for details."; exit 1;)
( 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;)
endef
endif
@ -241,35 +241,7 @@ endef
$(foreach __SYSTEM,$(NATIVE_SYSTEM) $(MCU_SYSTEMS), \
$(eval $(call GEN_MAKEFILE_RULE,$(BUILD_DIR)/$(__SYSTEM))))
# Targets to perform build, check, and test steps in the build directories
# Make rule macro to preform cppcheck on a build target.
#
# $(1) - rule to define in the current Makefile
# $(2) - system name
# $(3) - target(s) to check
define CPPCHECK_RULE
.PHONY: $(1)
$(1): $$(BUILD_DIR)/$(2)/Makefile prerequisites
$$(Q) $$(call SHLOG,$$(BUILD_COMMAND) -C $$(BUILD_DIR)/$(2) $(3),$$(BUILD_DIR)/$(2)/$(1).log,cppcheck run)
endef
$(foreach __TARGET,$(JERRY_NATIVE_TARGETS), \
$(eval $(call CPPCHECK_RULE,check-cpp.$(__TARGET),$(NATIVE_SYSTEM),cppcheck.$(__TARGET))))
$(eval $(call CPPCHECK_RULE,check-cpp.$(NATIVE_SYSTEM),$(NATIVE_SYSTEM),$(foreach __TARGET,$(JERRY_NATIVE_TARGETS),cppcheck.$(__TARGET))))
$(foreach __TARGET,$(JERRY_STM32F3_TARGETS), \
$(eval $(call CPPCHECK_RULE,check-cpp.$(__TARGET),stm32f3,cppcheck.$(__TARGET))))
$(eval $(call CPPCHECK_RULE,check-cpp.mcu_stm32f3,stm32f3,$(foreach __TARGET,$(JERRY_STM32F3_TARGETS),cppcheck.$(__TARGET))))
$(foreach __TARGET,$(JERRY_STM32F4_TARGETS), \
$(eval $(call CPPCHECK_RULE,check-cpp.$(__TARGET),stm32f4,cppcheck.$(__TARGET))))
$(eval $(call CPPCHECK_RULE,check-cpp.mcu_stm32f4,stm32f4,$(foreach __TARGET,$(JERRY_STM32F4_TARGETS),cppcheck.$(__TARGET))))
$(eval $(call CPPCHECK_RULE,check-cpp.unittests,$(NATIVE_SYSTEM),cppcheck.unittests))
# Targets to perform build and test steps in the build directories
# Make rule macro to build a/some target(s) and copy out the result(s).
#
@ -348,11 +320,12 @@ check-signed-off:
$(Q) ./tools/check-signed-off.sh
.PHONY: check-vera
check-vera: prerequisites
$(Q) ./tools/check-vera.sh
check-vera:
$(Q) $(call SHLOG,./tools/check-vera.sh,$(OUT_DIR)/vera.log,Vera++)
.PHONY: check-cpp
check-cpp: check-cpp.$(NATIVE_SYSTEM) $(foreach __SYSTEM,$(MCU_SYSTEMS),check-cpp.mcu_$(__SYSTEM)) check-cpp.unittests
.PHONY: check-cppcheck
check-cppcheck:
$(Q) $(call SHLOG,./tools/check-cppcheck.sh,$(OUT_DIR)/cppcheck.log,Cppcheck)
.PHONY: build
build: build.$(NATIVE_SYSTEM) $(foreach __SYSTEM,$(MCU_SYSTEMS),build.mcu_$(__SYSTEM))
@ -380,7 +353,7 @@ test-js-precommit: \
precommit: prerequisites
$(Q)+$(MAKE) --no-print-directory clean
$(Q) echo "Running checks..."
$(Q)+$(MAKE) --no-print-directory check-signed-off check-vera check-cpp
$(Q)+$(MAKE) --no-print-directory check-signed-off check-vera check-cppcheck
$(Q) echo "...building engine..."
$(Q)+$(MAKE) --no-print-directory build
$(Q) echo "...building and running unit tests..."

View File

@ -1,78 +0,0 @@
# Copyright 2015-2016 Samsung Electronics Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Cppcheck launcher
set(CMAKE_CPPCHECK cppcheck)
# Definition of cppcheck targets
add_custom_target(cppcheck)
function(add_cppcheck_target TARGET_NAME)
# Get target's parameters
get_target_property(TARGET_DEFINES ${TARGET_NAME} COMPILE_DEFINITIONS)
get_target_property(TARGET_INCLUDES ${TARGET_NAME} INCLUDE_DIRECTORIES)
get_target_property(TARGET_SOURCES ${TARGET_NAME} SOURCES)
get_target_property(TARGET_LIBRARIES ${TARGET_NAME} LINK_LIBRARIES)
# Build cppcheck's argument strings
set(CPPCHECK_DEFINES_LIST )
set(CPPCHECK_INCLUDES_LIST )
set(CPPCHECK_SOURCES_LIST )
foreach(DEFINE ${TARGET_DEFINES})
set(CPPCHECK_DEFINES_LIST ${CPPCHECK_DEFINES_LIST} -D${DEFINE})
endforeach()
foreach(INCLUDE ${TARGET_INCLUDES})
set(CPPCHECK_INCLUDES_LIST ${CPPCHECK_INCLUDES_LIST} -I${INCLUDE})
endforeach()
set(ADD_CPPCHECK_COMMAND FALSE)
foreach(SOURCE ${TARGET_SOURCES})
# Add to list if it is C or C++ source
get_filename_component(SOURCE_EXTENSION ${SOURCE} EXT)
if("${SOURCE_EXTENSION}" STREQUAL ".c")
set(CPPCHECK_SOURCES_LIST ${CPPCHECK_SOURCES_LIST} ${SOURCE})
set(ADD_CPPCHECK_COMMAND true)
endif()
endforeach()
if(ADD_CPPCHECK_COMMAND)
add_custom_target(cppcheck.${TARGET_NAME}
COMMAND ${CMAKE_CPPCHECK} -j8 --error-exitcode=1 --language=c++ --std=c++11
--enable=warning,style,performance,portability,information
--exitcode-suppressions=${CMAKE_SOURCE_DIR}/tools/cppcheck/suppressions-list
${CPPCHECK_DEFINES_LIST} ${CPPCHECK_SOURCES_LIST} ${CPPCHECK_INCLUDES_LIST}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
else()
add_custom_target(cppcheck.${TARGET_NAME})
endif()
if(NOT "${TARGET_LIBRARIES}" STREQUAL "TARGET_LIBRARIES-NOTFOUND")
foreach(LIBRARY ${TARGET_LIBRARIES})
string(REGEX MATCH "^${PREFIX_IMPORTED_LIB}.*|.*${SUFFIX_THIRD_PARTY_LIB}$" MATCHED ${LIBRARY})
if("${MATCHED}" STREQUAL "") # exclude imported and third-party modules
if(NOT TARGET cppcheck.${LIBRARY})
add_cppcheck_target(${LIBRARY})
add_dependencies(cppcheck.${TARGET_NAME} cppcheck.${LIBRARY})
endif()
endif()
endforeach()
endif()
add_dependencies(cppcheck cppcheck.${TARGET_NAME})
endfunction()

35
tools/check-cppcheck.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
# Copyright 2016 Samsung Electronics Co., Ltd.
# Copyright 2016 University of Szeged
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
CPPCHECK_JOBS=${CPPCHECK_JOBS:=$(nproc)}
JERRY_CORE_DIRS=`find jerry-core -type d`
JERRY_LIBC_DIRS=`find jerry-libc -type d`
INCLUDE_DIRS=()
for DIR in $JERRY_CORE_DIRS $JERRY_LIBC_DIRS
do
INCLUDE_DIRS=("${INCLUDE_DIRS[@]}" "-I$DIR")
done
cppcheck -j$CPPCHECK_JOBS --force \
--language=c++ --std=c++11 \
--enable=warning,style,performance,portability,information \
--error-exitcode=1 \
--exitcode-suppressions=tools/cppcheck/suppressions-list \
"${INCLUDE_DIRS[@]}" \
jerry-core jerry-libc *.c *h tests/unit

View File

@ -19,12 +19,6 @@ JERRY_CORE_FILES=`find ./jerry-core -name "*.c" -or -name "*.cpp" -or -name "*.h
JERRY_LIBC_FILES=`find ./jerry-libc -name "*.c" -or -name "*.cpp" -or -name "*.h"`
JERRY_MAIN_FILES=`find . -maxdepth 1 -name "*.c" -or -name "*.cpp" -or -name "*.h"`
vera++ -r tools/vera++ -p jerry $JERRY_CORE_FILES $JERRY_LIBC_FILES $JERRY_MAIN_FILES -e --no-duplicate
STATUS_CODE=$?
if [ $STATUS_CODE -ne 0 ]
then
echo -e "\e[1;33m vera++ static checks failed. See output above for details. \e[0m\n"
fi
exit $STATUS_CODE
vera++ -r tools/vera++ -p jerry \
-e --no-duplicate \
$JERRY_CORE_FILES $JERRY_LIBC_FILES $JERRY_MAIN_FILES

View File

@ -3,4 +3,4 @@ noConstructor
duplicateExpression
// FIXME: false positive in cppcheck 1.61 (will disappear once distro ships with 1.69)
variableScope:*/jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c
variableScope:jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c