Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move cppcheck logic from Makefile and CMakeLists.txt to tools/check-cppcheck.sh #903

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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)
Expand Down Expand Up @@ -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()
45 changes: 9 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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).
#
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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..."
Expand Down
78 changes: 0 additions & 78 deletions build/static-checkers/add_cppcheck_for_target.cmake

This file was deleted.

35 changes: 35 additions & 0 deletions tools/check-cppcheck.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 3 additions & 9 deletions tools/check-vera.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tools/cppcheck/suppressions-list
Original file line number Diff line number Diff line change
Expand Up @@ -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