diff --git a/.gitignore b/.gitignore index e3ec9bcd53..ae11510098 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ build/bin build/obj-* +build/prerequisites build/tests # IDE related files @@ -25,3 +26,11 @@ cscope.* # ctags and ID database tags ID + +# Prerequisites +.prerequisites +third-party/STM32F3-Discovery_FW_V1.1.0 +third-party/STM32F4-Discovery_FW_V1.1.0 +third-party/nuttx +third-party/vera++ +third-party/cppcheck diff --git a/CMakeLists.txt b/CMakeLists.txt index 52ab6ecccd..5c68467932 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,10 @@ project (Jerry CXX C ASM) message(FATAL_ERROR "Currently, external build with Jerry's libc is not supported") endif() else() + if (NOT EXISTS "${EXTERNAL_LIBC_INTERFACE}") + message(FATAL_ERROR "External libc interface directory doesn't exist: ${EXTERNAL_LIBC_INTERFACE}") + endif() + set(USE_EXTERNAL_LIBC TRUE) endif() @@ -194,9 +198,9 @@ project (Jerry CXX C ASM) # Platform-specific # MCU # stm32f3 - set(LINKER_FLAGS_COMMON_MCU_STM32F3 "-T${CMAKE_SOURCE_DIR}/third-party/stm32f3.ld") + set(LINKER_FLAGS_COMMON_MCU_STM32F3 "-T${CMAKE_SOURCE_DIR}/third-party/STM32F3-Discovery_FW_V1.1.0/Project/Peripheral_Examples/FLASH_Program/TrueSTUDIO/FLASH_Program/STM32_FLASH.ld") # stm32f4 - set(LINKER_FLAGS_COMMON_MCU_STM32F4 "-T${CMAKE_SOURCE_DIR}/third-party/stm32f4.ld") + set(LINKER_FLAGS_COMMON_MCU_STM32F4 "-T${CMAKE_SOURCE_DIR}/third-party/STM32F4-Discovery_FW_V1.1.0/Project/Peripheral_Examples/FLASH_Program/TrueSTUDIO/FLASH_Program/stm32_flash.ld") # Debug set(FLAGS_COMMON_DEBUG "-nostdlib") diff --git a/Makefile b/Makefile index f246f15d7d..0cc3f45cf0 100644 --- a/Makefile +++ b/Makefile @@ -102,6 +102,7 @@ export CHECK_TARGETS = $(foreach __TARGET,$(JERRY_LINUX_TARGETS),$(__TARGET).che export FLASH_TARGETS = $(foreach __TARGET,$(JERRY_STM32F3_TARGETS) $(JERRY_STM32F4_TARGETS),$(__TARGET).flash) export OUT_DIR = ./build/bin +export PREREQUISITES_STATE_DIR = ./build/prerequisites export SHELL=/bin/bash @@ -138,7 +139,7 @@ export SHELL=/bin/bash all: precommit -$(BUILD_DIRS_NATIVE): +$(BUILD_DIRS_NATIVE): prerequisites @ arch=`uname -m`; \ if [ "$$arch" == "armv7l" ]; \ then \ @@ -149,7 +150,7 @@ $(BUILD_DIRS_NATIVE): cmake -DENABLE_VALGRIND=$(VALGRIND) -DENABLE_LTO=$(LTO) -DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_linux_$$arch.cmake ../../.. &>cmake.log || \ (echo "CMake run failed. See "`pwd`"/cmake.log for details."; exit 1;) -$(BUILD_DIRS_NUTTX): +$(BUILD_DIRS_NUTTX): prerequisites @ [ "$(EXTERNAL_LIBS_INTERFACE)" != "" ] && [ -x `which $(EXTERNAL_C_COMPILER)` ] && [ -x `which $(EXTERNAL_CXX_COMPILER)` ] || \ (echo "Wrong external arguments."; \ echo "EXTERNAL_LIBS_INTERFACE='$(EXTERNAL_LIBS_INTERFACE)'"; \ @@ -167,13 +168,13 @@ $(BUILD_DIRS_NUTTX): ../../.. &>cmake.log || \ (echo "CMake run failed. See "`pwd`"/cmake.log for details."; exit 1;) -$(BUILD_DIRS_STM32F3): +$(BUILD_DIRS_STM32F3): prerequisites @ mkdir -p $@ && \ cd $@ && \ cmake -DENABLE_VALGRIND=$(VALGRIND) -DENABLE_LTO=$(LTO) -DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_mcu_stm32f3.cmake ../../.. &>cmake.log || \ (echo "CMake run failed. See "`pwd`"/cmake.log for details."; exit 1;) -$(BUILD_DIRS_STM32F4): +$(BUILD_DIRS_STM32F4): prerequisites @ mkdir -p $@ && \ cd $@ && \ cmake -DENABLE_VALGRIND=$(VALGRIND) -DENABLE_LTO=$(LTO) -DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_mcu_stm32f4.cmake ../../.. &>cmake.log || \ @@ -279,7 +280,7 @@ pull: ./tools/git-scripts/pull.sh log: ./tools/git-scripts/log.sh @ ./tools/git-scripts/log.sh -precommit: clean +precommit: clean prerequisites @ ./tools/precommit.sh "$(MAKE)" "$(OUT_DIR)" "$(PRECOMMIT_CHECK_TARGETS_LIST)" unittests_run: unittests @@ -291,4 +292,17 @@ unittests_run: unittests clean: @ rm -rf $(BUILD_DIR_PREFIX)* $(OUT_DIR) -.PHONY: clean build unittests_run $(BUILD_DIRS_ALL) $(JERRY_TARGETS) $(FLASH_TARGETS) +prerequisites: $(PREREQUISITES_STATE_DIR)/.prerequisites + +$(PREREQUISITES_STATE_DIR)/.prerequisites: + @ echo "Setting up prerequisites... (log file: $(PREREQUISITES_STATE_DIR)/prerequisites.log)" + @ mkdir -p $(PREREQUISITES_STATE_DIR) + @ ./tools/prerequisites.sh $(PREREQUISITES_STATE_DIR)/.prerequisites >&$(PREREQUISITES_STATE_DIR)/prerequisites.log || \ + (echo "Prerequisites setup failed. See $(PREREQUISITES_STATE_DIR)/prerequisites.log for details."; exit 1;) + @ echo "Prerequisites setup succeeded" + +prerequisites_clean: + @ ./tools/prerequisites.sh $(PREREQUISITES_STATE_DIR)/.prerequisites clean + @ rm -rf $(PREREQUISITES_STATE_DIR) + +.PHONY: prerequisites_clean prerequisites clean build unittests_run $(BUILD_DIRS_ALL) $(JERRY_TARGETS) $(FLASH_TARGETS) diff --git a/build/static-checkers/add_cppcheck_for_target.cmake b/build/static-checkers/add_cppcheck_for_target.cmake index bd764d4364..c3d1e5e46f 100644 --- a/build/static-checkers/add_cppcheck_for_target.cmake +++ b/build/static-checkers/add_cppcheck_for_target.cmake @@ -13,7 +13,7 @@ # limitations under the License. # Cppcheck launcher - set(CMAKE_CPPCHECK ${CMAKE_SOURCE_DIR}/tools/cppcheck.sh) + set(CMAKE_CPPCHECK ${CMAKE_SOURCE_DIR}/tools/cppcheck/cppcheck.sh) # Definition of cppcheck targets add_custom_target(cppcheck) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 40305bb404..574defc87a 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -49,12 +49,14 @@ project (Jerry_Plugins CXX ASM) # MCU # STM32F3 set(INCLUDE_THIRD_PARTY_MCU_STM32F3 + ${CMAKE_SOURCE_DIR}/third-party/STM32F3-Discovery_FW_V1.1.0/Project/Demonstration ${CMAKE_SOURCE_DIR}/third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/CMSIS/Device/ST/STM32F30x/Include ${CMAKE_SOURCE_DIR}/third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/STM32F30x_StdPeriph_Driver/inc ${CMAKE_SOURCE_DIR}/third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/CMSIS/Include ${CMAKE_SOURCE_DIR}/third-party/STM32F3-Discovery_FW_V1.1.0) # STM32F4 set(INCLUDE_THIRD_PARTY_MCU_STM32F4 + ${CMAKE_SOURCE_DIR}/third-party/STM32F4-Discovery_FW_V1.1.0/Project/Demonstration ${CMAKE_SOURCE_DIR}/third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Include ${CMAKE_SOURCE_DIR}/third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/inc ${CMAKE_SOURCE_DIR}/third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/Include diff --git a/tools/cppcheck.sh b/tools/cppcheck/cppcheck.sh similarity index 74% rename from tools/cppcheck.sh rename to tools/cppcheck/cppcheck.sh index cf92a56ead..7e2755f571 100755 --- a/tools/cppcheck.sh +++ b/tools/cppcheck/cppcheck.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014-2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,16 +14,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - -BASE=$(dirname $0)/../third-party/tools/cppcheck +REPOSITORY_DIR=$(dirname $0)/../.. +CPPCHECK=$REPOSITORY_DIR/third-party/cppcheck/cppcheck +SUPPRESSIONS_LIST=$(dirname $0)/suppressions-list -if [ ! -x $BASE/$(uname -m)/cppcheck ] +if [ ! -x $CPPCHECK ] then exit 1; fi -$BASE/$(uname -m)/cppcheck "$@" "--exitcode-suppressions=$BASE/cfg/suppressions-list" +$CPPCHECK "$@" "--exitcode-suppressions=$SUPPRESSIONS_LIST" status_code=$? exit $status_code diff --git a/tools/cppcheck/suppressions-list b/tools/cppcheck/suppressions-list new file mode 100644 index 0000000000..b02af84f1c --- /dev/null +++ b/tools/cppcheck/suppressions-list @@ -0,0 +1 @@ +operatorEqVarError diff --git a/tools/generator.sh b/tools/generator.sh index 81695b3d8d..e020fe0da2 100755 --- a/tools/generator.sh +++ b/tools/generator.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014-2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,11 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - echo "#define JERRY_MCU_SCRIPT \\" > $2 cat $1 | while read line do + line=$(echo $line | sed 's/"/\\"/g') echo "\"$line\n\" \\" >> $2 done echo >> $2 diff --git a/tools/git-scripts/log.sh b/tools/git-scripts/log.sh index 8a69c21327..d7c59555bd 100755 --- a/tools/git-scripts/log.sh +++ b/tools/git-scripts/log.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014-2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - git log --graph --branches --decorate \ --show-notes=perf --show-notes=mem --show-notes=test_build_env \ --show-notes=arm-linux-perf \ diff --git a/tools/git-scripts/pull.sh b/tools/git-scripts/pull.sh index c7d04b56a6..828012a452 100755 --- a/tools/git-scripts/pull.sh +++ b/tools/git-scripts/pull.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - git pull --rebase status_code=$? diff --git a/tools/git-scripts/push.sh b/tools/git-scripts/push.sh index f1a38c4fca..328919724d 100755 --- a/tools/git-scripts/push.sh +++ b/tools/git-scripts/push.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014-2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - GIT_STATUS_NOT_CLEAN_MSG="Git status of current directory is not clean" GIT_STATUS_CONSIDER_CLEAN_MSG="Consider removing all untracked files, locally commiting all changes and running $0 again" diff --git a/tools/perf-compare.sh b/tools/perf-compare.sh index 5f8963bcdc..155a55235b 100755 --- a/tools/perf-compare.sh +++ b/tools/perf-compare.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - commit_first=$1 shift diff --git a/tools/perf.sh b/tools/perf.sh index 918909abd9..38c1332451 100755 --- a/tools/perf.sh +++ b/tools/perf.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - ITERS=$1 ENGINE=$2 BENCHMARK=$3 diff --git a/tools/precommit.sh b/tools/precommit.sh index b409517f9e..d631ee83c1 100755 --- a/tools/precommit.sh +++ b/tools/precommit.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - MAKE="$1" shift @@ -23,27 +23,18 @@ shift TARGETS="$1" shift -PARSE_ONLY_TESTING_PATHS="./tests/benchmarks/jerry" -FULL_TESTING_PATHS="./tests/jerry ./tests/jerry-test-suite/precommit_test_list" +VERA_DIRECTORIES_EXCLUDE_LIST="-path ./third-party -o -path tests" +VERA_CONFIGURATION_PATH="./tools/vera++" -VERA=`which vera++` -if [ -x "$VERA" ] -then - VERA_DIRECTORIES_EXCLUDE_LIST="-path ./third-party -o -path tests" - VERA_SCRIPTS_PATH="./tools/vera++" - - SOURCES_AND_HEADERS_LIST=`find . -type d \( $VERA_DIRECTORIES_EXCLUDE_LIST \) -prune -or -name "*.c" -or -name "*.cpp" -or -name "*.h"` - vera++ -r $VERA_SCRIPTS_PATH -p jerry $SOURCES_AND_HEADERS_LIST -e --no-duplicate - STATUS_CODE=$? +SOURCES_AND_HEADERS_LIST=`find . -type d \( $VERA_DIRECTORIES_EXCLUDE_LIST \) -prune -or -name "*.c" -or -name "*.cpp" -or -name "*.h"` +./tools/vera++/vera.sh -r $VERA_CONFIGURATION_PATH -p jerry $SOURCES_AND_HEADERS_LIST -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" +if [ $STATUS_CODE -ne 0 ] +then + echo -e "\e[1;33m vera++ static checks failed. See output above for details. \e[0m\n" - exit $STATUS_CODE - fi -else - echo -e "\e[1;33m Warning: vera++ not installed, skipping corresponding static checks. \e[0m\n" + exit $STATUS_CODE fi echo -e "\nBuilding...\n\n" diff --git a/tools/prerequisites.sh b/tools/prerequisites.sh new file mode 100755 index 0000000000..ad4c4dd2d9 --- /dev/null +++ b/tools/prerequisites.sh @@ -0,0 +1,267 @@ +#!/bin/bash + +# Copyright 2015 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. + +FLAG_FILE="$1" +shift + +rm -f $FLAG_FILE + +if [ "$1" == "clean" ] +then + CLEAN_MODE=yes +else + CLEAN_MODE=no +fi + +trap clean_on_exit INT + +function clean_on_exit() { + rm -rf $TMP_DIR + + [[ $1 == "OK" ]] || exit 1 + exit 0 +} + +function fail_msg() { + echo "$1" + + clean_on_exit "FAIL" +} + +function remove_gitignore_files_at() { + DEST="$1" + gitignore_files_list=`find "$DEST" -name .gitignore` + [ $? -eq 0 ] || fail_msg "Failed to search for .gitignore in '$DEST'." + + rm -rf $gitignore_files_list || fail_msg "Failed to remove .gitignore files from '$DEST'." +} + +function setup_from_zip() { + NAME="$1" + shift + + DEST=$(pwd)/"$1" + shift + + URL="$1" + shift + + CHECKSUM="$1" + shift + + LIST="$*" + + FAIL_MSG="Failed to setup '$NAME' prerequisite" + + if [ -e "$DEST" ] + then + chmod -R u+w "$DEST" || fail_msg "$FAIL_MSG. Failed to add write permission to '$DEST' directory contents." + rm -rf "$DEST" || fail_msg "$FAIL_MSG. Cannot remove '$DEST' directory." + fi + + if [ "$CLEAN_MODE" == "yes" ] + then + return 0 + fi + + wget -O "$TMP_DIR/$NAME.zip" "$URL" || fail_msg "$FAIL_MSG. Cannot download '$URL' zip archive." + + echo "$CHECKSUM $TMP_DIR/$NAME.zip" | sha256sum --check --strict || fail_msg "$FAIL_MSG. Archive's checksum doesn't match." + + unzip "$TMP_DIR/$NAME.zip" -d "$TMP_DIR/$NAME" || fail_msg "$FAIL_MSG. Failed to unpack zip archive." + mkdir "$DEST" || fail_msg "$FAIL_MSG. Failed to create '$DEST' directory." + + for part in "$LIST" + do + mv "$TMP_DIR/$NAME"/$part "$DEST" || fail_msg "$FAIL_MSG. Failed to move '$part' to '$DEST'." + done + + remove_gitignore_files_at "$DEST" + chmod -R u-w "$DEST" || fail_msg "$FAIL_MSG. Failed to remove write permission from '$DEST' directory contents." +} + +function setup_nuttx_headers() { + NAME="$1" + shift + + DEST=$(pwd)/"$1" + shift + + URL="$1" + shift + + REVISION="$1" + shift + + FAIL_MSG="Failed to setup '$NAME' prerequisite" + + if [ -e "$DEST" ] + then + chmod -R u+w "$DEST" || fail_msg "$FAIL_MSG. Failed to add write permission to '$DEST' directory contents." + rm -rf "$DEST" || fail_msg "$FAIL_MSG. Cannot remove '$DEST' directory." + fi + + if [ "$CLEAN_MODE" == "yes" ] + then + return 0 + fi + + git clone "$URL" "$TMP_DIR/$NAME" || fail_msg "$FAIL_MSG. Failed to checkout Nuttx." + ( + cd "$TMP_DIR/$NAME" || exit 1 + git checkout $REVISION || exit 1 + cd nuttx/tools || exit 1 + ./configure.sh stm32f429i-disco/usbnsh || exit 1 + cd .. || exit 1 + make include/nuttx/config.h || exit 1 + make include/arch || exit 1 + make include/arch/chip || exit 1 + ) || fail_msg "$FAIL_MSG. Failed to prepare nuttx headers" + + mkdir "./third-party/nuttx" || fail_msg "Failed to create '$DEST' directory." + cp -L -r "$TMP_DIR/$NAME/nuttx/include" "$DEST" || fail_msg "Failed to copy Nuttx headers to '$DEST' directory" + + remove_gitignore_files_at "$DEST" + chmod -R u-w "$DEST" || fail_msg "$FAIL_MSG. Failed to remove write permission from '$DEST' directory contents." +} + +function setup_cppcheck() { + NAME="$1" + shift + + DEST=$(pwd)/"$1" + shift + + URL="$1" + shift + + CHECKSUM="$1" + shift + + FAIL_MSG="Failed to setup '$NAME' prerequisite" + + if [ -e "$DEST" ] + then + chmod -R u+w "$DEST" || fail_msg "$FAIL_MSG. Failed to add write permission to '$DEST' directory contents." + rm -rf "$DEST" || fail_msg "$FAIL_MSG. Cannot remove '$DEST' directory." + fi + + if [ "$CLEAN_MODE" == "yes" ] + then + return 0 + fi + + wget -O "$TMP_DIR/$NAME.tar.bz2" "$URL" || fail_msg "$FAIL_MSG. Cannot download '$URL' archive." + + echo "$CHECKSUM $TMP_DIR/$NAME.tar.bz2" | sha256sum --check --strict || fail_msg "$FAIL_MSG. Archive's checksum doesn't match." + + tar xjvf "$TMP_DIR/$NAME.tar.bz2" -C "$TMP_DIR" || fail_msg "$FAIL_MSG. Failed to unpack archive." + + ( + cd "$TMP_DIR/$NAME" || exit 1 + make -j HAVE_RULES=yes CFGDIR="$DEST/cfg" || exit 1 + ) || fail_msg "$FAIL_MSG. Failed to build cppcheck 1.66." + + mkdir "$DEST" || fail_msg "$FAIL_MSG. Failed to create '$DEST' directory." + mkdir "$DEST/cfg" || fail_msg "$FAIL_MSG. Failed to create '$DEST/cfg' directory." + + cp "$TMP_DIR/$NAME/cppcheck" "$DEST" || fail_msg "$FAIL_MSG. Failed to copy cppcheck to '$DEST' directory." + cp "$TMP_DIR/$NAME/cfg/std.cfg" "$DEST/cfg" || fail_msg "$FAIL_MSG. Failed to copy cfg/std.cfg to '$DEST/cfg' directory." + + remove_gitignore_files_at "$DEST" + chmod -R u-w "$DEST" || fail_msg "$FAIL_MSG. Failed to remove write permission from '$DEST' directory contents." +} + +function setup_vera() { + NAME="$1" + shift + + DEST=$(pwd)/"$1" + shift + + URL="$1" + shift + + CHECKSUM="$1" + shift + + FAIL_MSG="Failed to setup '$NAME' prerequisite" + + if [ -e "$DEST" ] + then + chmod -R u+w "$DEST" || fail_msg "$FAIL_MSG. Failed to add write permission to '$DEST' directory contents." + rm -rf "$DEST" || fail_msg "$FAIL_MSG. Cannot remove '$DEST' directory." + fi + + if [ "$CLEAN_MODE" == "yes" ] + then + return 0 + fi + + wget -O "$TMP_DIR/$NAME.tar.gz" "$URL" || fail_msg "$FAIL_MSG. Cannot download '$URL' archive." + + echo "$CHECKSUM $TMP_DIR/$NAME.tar.gz" | sha256sum --check --strict || fail_msg "$FAIL_MSG. Archive's checksum doesn't match." + + tar xzvf "$TMP_DIR/$NAME.tar.gz" -C "$TMP_DIR" || fail_msg "$FAIL_MSG. Failed to unpack archive." + + ( + cd "$TMP_DIR/$NAME" || exit 1 + mkdir build || exit 1 + cd build || exit 1 + cmake .. -DCMAKE_INSTALL_PREFIX="$DEST" || exit 1 + make -j || exit 1 + make install || exit 1 + ) || fail_msg "$FAIL_MSG. Failed to build vera++ 1.2.1." + + remove_gitignore_files_at "$DEST" + chmod -R u-w "$DEST" || fail_msg "$FAIL_MSG. Failed to remove write permission from '$DEST' directory contents." +} + +TMP_DIR=`mktemp -d --tmpdir=./` + +setup_from_zip "stm32f3" \ + "./third-party/STM32F3-Discovery_FW_V1.1.0" \ + "http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/firmware/stm32f3discovery_fw.zip" \ + "cf81efd07d627adb58adc20653eecb415878b6585310b77b0ca54a34837b3855" \ + "STM32F3-Discovery_FW_V1.1.0/*" + +setup_from_zip "stm32f4" \ + "./third-party/STM32F4-Discovery_FW_V1.1.0" \ + "http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/firmware/stsw-stm32068.zip" \ + "8e67f7b930c6c02bd7f89a266c8d1cae3b530510b7979fbfc0ee0d57e7f88b81" \ + "STM32F4-Discovery_FW_V1.1.0/*" + +setup_nuttx_headers "nuttx" \ + "./third-party/nuttx" \ + "git://git.code.sf.net/p/nuttx/git" \ + "36a655eddec29754cc93631b6083fe6409817861" + +setup_cppcheck "cppcheck-1.66" \ + "./third-party/cppcheck" \ + "http://downloads.sourceforge.net/project/cppcheck/cppcheck/1.66/cppcheck-1.66.tar.bz2" \ + "9469c23d39df5f03301fb0f9c29d75e9d63ed80d486cc6633145e3c95293c1b7" + +setup_vera "vera++-1.2.1" \ + "./third-party/vera++" \ + "https://bitbucket.org/verateam/vera/downloads/vera++-1.2.1.tar.gz" \ + "99b123c8f6d0f4fe9ee90397c461179066a36ed0d598d95e015baf2d3b56956b" + +if [ "$CLEAN_MODE" == "no" ] +then + touch $FLAG_FILE || fail_msg "Failed to create flag file '$FLAG_FILE'." +fi + +clean_on_exit "OK" diff --git a/tools/rss-measure.sh b/tools/rss-measure.sh index e4c5a123cb..b590acdba2 100755 --- a/tools/rss-measure.sh +++ b/tools/rss-measure.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - JERRY=$1 TEST=$2 RAW_OUTPUT=$3 diff --git a/tools/runners/run-benchmarks.sh b/tools/runners/run-benchmarks.sh index 46146be5ac..a92d005203 100755 --- a/tools/runners/run-benchmarks.sh +++ b/tools/runners/run-benchmarks.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014-2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - ENGINE=$1 function run () diff --git a/tools/runners/run-precommit-check-for-target.sh b/tools/runners/run-precommit-check-for-target.sh index 6fa121901a..bd6cf76dcc 100755 --- a/tools/runners/run-precommit-check-for-target.sh +++ b/tools/runners/run-precommit-check-for-target.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - ENGINE_PATH="$1" OUTPUT_PATH="$2" TESTS_PATH="$3" diff --git a/tools/runners/run-stability-test.sh b/tools/runners/run-stability-test.sh index a3052d3442..716c41e0e8 100755 --- a/tools/runners/run-stability-test.sh +++ b/tools/runners/run-stability-test.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014-2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - NUM_COMMITS=$1 BENCH=./tests/benchmarks/jerry/loop_arithmetics_1kk.js TARGET=release.linux diff --git a/tools/runners/run-test-pass.sh b/tools/runners/run-test-pass.sh index 015004c2fe..0b1451376e 100755 --- a/tools/runners/run-test-pass.sh +++ b/tools/runners/run-test-pass.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014-2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - TIMEOUT=${TIMEOUT:=5} START_DIR=`pwd` diff --git a/tools/runners/run-test-suite-test262.sh b/tools/runners/run-test-suite-test262.sh index 56559372cd..dfbba39a76 100755 --- a/tools/runners/run-test-suite-test262.sh +++ b/tools/runners/run-test-suite-test262.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014-2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - TARGET=$1 shift diff --git a/tools/runners/run-test-xfail.sh b/tools/runners/run-test-xfail.sh index 21a3b02bac..c9adcbcb4d 100755 --- a/tools/runners/run-test-xfail.sh +++ b/tools/runners/run-test-xfail.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014-2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - TIMEOUT=${TIMEOUT:=5} START_DIR=`pwd` diff --git a/tools/runners/run-unittests.sh b/tools/runners/run-unittests.sh index 7217212e7b..51d8e743ee 100755 --- a/tools/runners/run-unittests.sh +++ b/tools/runners/run-unittests.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014-2015 Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -#!/bin/bash - DIR="$1" shift diff --git a/tools/vera++/profiles/jerry b/tools/vera++/profiles/jerry new file mode 100644 index 0000000000..3865531f91 --- /dev/null +++ b/tools/vera++/profiles/jerry @@ -0,0 +1,4 @@ +set rules { + jerry_indentation + jerry_switch_case +} diff --git a/tools/vera++/scripts/rules/jerry_indentation.tcl b/tools/vera++/scripts/rules/jerry_indentation.tcl new file mode 100644 index 0000000000..96a60fd379 --- /dev/null +++ b/tools/vera++/scripts/rules/jerry_indentation.tcl @@ -0,0 +1,106 @@ +#!/usr/bin/tclsh + +# Copyright 2014-2015 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. + +# Indentation + +foreach fileName [getSourceFileNames] { + set indent 0 + set lastCheckedLineNumber -1 + set is_in_comment "no" + set is_in_pp_define "no" + set is_in_class "no" + set parentheses_level 0 + + foreach token [getTokens $fileName 1 0 -1 -1 {}] { + set type [lindex $token 3] + set lineNumber [lindex $token 1] + + if {$is_in_comment == "yes"} { + set is_in_comment "no" + } + + if {$type == "newline"} { + set is_in_pp_define "no" + } elseif {$type == "class"} { + set is_in_class "yes" + } elseif {$is_in_class == "yes" && $type == "semicolon" && $indent == 0} { + set is_in_class "no" + } elseif {$type == "ccomment"} { + set is_in_comment "yes" + } elseif {[string first "pp_" $type] == 0} { + if {$type == "pp_define"} { + set is_in_pp_define "yes" + } + + set lastCheckedLineNumber $lineNumber + } elseif {$type == "space"} { + } elseif {$type != "eof"} { + if {$type == "rightbrace"} { + incr indent -2 + } + + if {$is_in_pp_define == "no" && $is_in_comment == "no" && $is_in_class == "no" && $parentheses_level == 0} { + set line [getLine $fileName $lineNumber] + + if {$lineNumber != $lastCheckedLineNumber} { + if {[string length $line] == 0} { + } + + if {[regexp {^[[:blank:]]*} $line match]} { + set real_indent [string length $match] + if {$indent != $real_indent} { + if {![regexp {^[[:alnum:]_]{1,}:$} $line] || $real_indent != 0} { + report $fileName $lineNumber "Indentation: $real_indent -> $indent. Line: '$line'" + } + } + } + } + + if {$lineNumber == $lastCheckedLineNumber} { + if {$type == "leftbrace"} { + if {![regexp {^[[:blank:]]*\{[[:blank:]]*$} $line] + && ![regexp {[^\{=]=[^\{=]\{.*\},?} $line]} { + report $fileName $lineNumber "Left brace is not the only non-space character in the line: '$line'" + } + } + if {$type == "rightbrace"} { + if {![regexp {^.* = .*\{.*\}[,;]?$} $line] + && ![regexp {[^\{=]=[^\{=]\{.*\}[,;]?} $line]} { + report $fileName $lineNumber "Right brace is not first non-space character in the line: '$line'" + } + } + } + if {$type == "rightbrace"} { + if {![regexp {^[[:blank:]]*\}((( [a-z_\(][a-z0-9_\(\)]{0,}){1,})?;| /\*.*\*/| //.*)?$} $line] + && ![regexp {[^\{=]=[^\{=]\{.*\}[,;]?} $line]} { + report $fileName $lineNumber "Right brace is not the only non-space character in the line and \ + is not single right brace followed by \[a-z0-9_() \] string and single semicolon character: '$line'" + } + } + } + + if {$type == "leftbrace"} { + incr indent 2 + } elseif {$type == "leftparen"} { + incr parentheses_level 1 + } elseif {$type == "rightparen"} { + incr parentheses_level -1 + } + + set lastCheckedLineNumber $lineNumber + } + } +} diff --git a/tools/vera++/scripts/rules/jerry_switch_case.tcl b/tools/vera++/scripts/rules/jerry_switch_case.tcl new file mode 100644 index 0000000000..30cfb27a59 --- /dev/null +++ b/tools/vera++/scripts/rules/jerry_switch_case.tcl @@ -0,0 +1,273 @@ +#!/usr/bin/tclsh + +# Copyright 2014-2015 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. + +# switch-case + +foreach fileName [getSourceFileNames] { + set is_in_comment "no" + set is_in_pp_define "no" + + foreach token [getTokens $fileName 1 0 -1 -1 {}] { + set type [lindex $token 3] + set lineNumber [lindex $token 1] + + if {$is_in_comment == "yes"} { + set is_in_comment "no" + } + + if {$type == "newline"} { + set is_in_pp_define "no" + } elseif {$type == "ccomment"} { + set is_in_comment "yes" + } elseif {[string first "pp_" $type] == 0} { + if {$type == "pp_define"} { + set is_in_pp_define "yes" + } + } elseif {$type == "space"} { + } elseif {$type != "eof"} { + if {$is_in_pp_define == "no" && $type == "switch"} { + set next_token_start [lindex $token 2] + incr next_token_start 1 + set line_num 0 + set state "switch" + set case_block "no" + set seen_braces 0 + foreach next_token [getTokens $fileName $lineNumber $next_token_start -1 -1 {}] { + set next_token_type [lindex $next_token 3] + set next_token_value [lindex $next_token 0] + if {$state == "switch"} { + if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} { + continue + } elseif {$next_token_type == "leftbrace"} { + set state "first-case" + continue + } else { + # TODO: check switch + continue + } + } elseif {$state == "first-case"} { + if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} { + continue + } elseif {$next_token_type == "case"} { + set state "case" + continue + } elseif {$next_token_type == "default"} { + set state "default" + continue + } else { + # Macros magic: give up + break + } + } elseif {$state == "case"} { + if {$next_token_type == "space"} { + set state "space-after-case" + continue + } else { + report $fileName [lindex $next_token 1] "There should be single space character after 'case' keyword (state $state)" + } + } elseif {$state == "space-after-case"} { + if {$next_token_type != "identifier" && $next_token_type != "intlit" && $next_token_type != "charlit" && $next_token_type != "sizeof"} { + report $fileName [lindex $next_token 1] "There should be single space character after 'case' keyword (state $state, next_token_type $next_token_type)" + } else { + set state "case-label" + continue + } + } elseif {$state == "case-label" || $state == "default"} { + set case_block "no" + if {$next_token_type != "colon"} { + continue + } else { + set state "colon" + continue + } + } elseif {$state == "after-colon-preprocessor"} { + if {$next_token_type == "newline"} { + set state "colon" + } + } elseif {$state == "colon"} { + if {$next_token_type == "space" || $next_token_type == "newline"} { + continue + } elseif {$next_token_type == "ccomment"} { + if {[string match "*FALL*" $next_token_value]} { + set state "fallthru" + set line_num [lindex $next_token 1] + continue + } else { + continue + } + } elseif {$next_token_type == "case"} { + set state "case" + continue + } elseif {$next_token_type == "default"} { + set state "default" + continue + } elseif {$next_token_type == "leftbrace"} { + set case_block "yes" + set state "wait-for-break" + continue + } elseif {$next_token_type == "identifier"} { + if {[string compare "JERRY_UNREACHABLE" $next_token_value] == 0 + || [string first "JERRY_UNIMPLEMENTED" $next_token_value] == 0} { + set state "wait-for-semicolon" + continue + } else { + set state "wait-for-break" + continue + } + } elseif {$next_token_type == "break" || $next_token_type == "return"} { + set state "wait-for-semicolon" + continue + } elseif {[string first "pp_" $next_token_type] == 0} { + set state "after-colon-preprocessor" + } else { + set state "wait-for-break" + continue + } + } elseif {$state == "wait-for-semicolon"} { + if {$next_token_type == "semicolon"} { + set state "break" + } + continue + } elseif {$state == "wait-for-break"} { + if {$next_token_type == "case" || $next_token_type == "default"} { + report $fileName [lindex $next_token 1] "Missing break or FALLTHRU comment before case (state $state)" + } elseif {$next_token_type == "leftbrace"} { + set state "inside-braces" + incr seen_braces 1 + continue + } elseif {$next_token_type == "rightbrace"} { + if {$case_block == "yes"} { + set state "case-blocks-end" + continue + } else { + break + } + } elseif {[string compare "JERRY_UNREACHABLE" $next_token_value] == 0 + || [string first "JERRY_UNIMPLEMENTED" $next_token_value] == 0} { + set state "wait-for-semicolon" + continue + } elseif {$next_token_type == "ccomment" && [string match "*FALL*" $next_token_value]} { + set state "fallthru" + set line_num [lindex $next_token 1] + continue + } elseif {$next_token_type == "break" || $next_token_type == "return" || $next_token_type == "goto"} { + set state "wait-for-semicolon" + continue + } + continue + } elseif {$state == "break" || $state == "fallthru"} { + if {$case_block == "no"} { + if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} { + continue + } elseif {$next_token_type == "case"} { + set state "case" + continue + } elseif {$next_token_type == "default"} { + set state "default" + continue + } elseif {$next_token_type == "leftbrace"} { + set state "inside-braces" + incr seen_braces 1 + continue + } elseif {$next_token_type == "rightbrace"} { + lappend switch_ends [lindex $next_token 1] + break + } elseif {$next_token_type == "break" || $next_token_type == "return"} { + set state "wait-for-semicolon" + continue + } else { + set state "wait-for-break" + continue + } + } else { + if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} { + continue + } elseif {$next_token_type == "case"} { + set state "case" + continue + } elseif {$next_token_type == "default"} { + set state "default" + continue + } elseif {$next_token_type == "leftbrace"} { + set state "inside-braces" + incr seen_braces 1 + continue + } elseif {$next_token_type == "rightbrace"} { + set state "after-rightbrace" + continue + } elseif {$next_token_type == "break" || $next_token_type == "return"} { + set state "wait-for-semicolon" + continue + } else { + set state "wait-for-break" + continue + } + } + } elseif {$state == "inside-braces"} { + if {$next_token_type == "rightbrace"} { + incr seen_braces -1 + if {$seen_braces == 0} { + set state "wait-for-break" + continue + } + } elseif {$next_token_type == "leftbrace"} { + incr seen_braces 1 + } + continue + } elseif {$state == "after-rightbrace-preprocessor"} { + if {$next_token_type == "newline"} { + set state "after-rightbrace" + } + } elseif {$state == "after-rightbrace"} { + if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} { + continue + } elseif {$next_token_type == "case"} { + set state "case" + continue + } elseif {$next_token_type == "default"} { + set state "default" + continue + } elseif {$next_token_type == "rightbrace"} { + lappend switch_ends [lindex $next_token 1] + break + } elseif {[string first "pp_" $next_token_type] == 0} { + set state "after-rightbrace-preprocessor" + } else { + report $fileName [lindex $next_token 1] "There should be 'case' or 'default' (state $state)" + } + } elseif {$state == "case-blocks-end-preprocessor"} { + if {$next_token_type == "newline"} { + set state "case-blocks-end" + } + } elseif {$state == "case-blocks-end"} { + if {$next_token_type == "ccomment" || $next_token_type == "space" || $next_token_type == "newline"} { + continue + } elseif {$next_token_type == "rightbrace"} { + lappend switch_ends [lindex $next_token 1] + break + } elseif {[string first "pp_" $next_token_type] == 0} { + set state "case-blocks-end-preprocessor" + } else { + report $fileName [lindex $next_token 1] "Missing break or FALLTHRU comment before rightbrace (state $state)" + } + } else { + report $fileName [lindex $next_token 1] "Unknown state: $state" + } + } + } + } + } +} diff --git a/tools/vera++/vera.sh b/tools/vera++/vera.sh new file mode 100755 index 0000000000..397b690dcb --- /dev/null +++ b/tools/vera++/vera.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Copyright 2015 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. + +REPOSITORY_DIR=$(dirname $0)/../.. +VERA=$REPOSITORY_DIR/third-party/vera++/bin/vera++ + +if [ ! -x $VERA ] +then + exit 1; +fi + +$VERA "$@" +status_code=$? + +exit $status_code