Revert "Use ittnotify from thirdparty"
[platform/upstream/dldt.git] / inference-engine / scripts / run_code_checks.sh
1 #!/bin/bash
2 # Copyright (C) 2018-2020 Intel Corporation
3 # SPDX-License-Identifier: Apache-2.0
4
5 CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6 command -v realpath >/dev/null 2>&1 || { echo >&2 "cpplint require realpath executable but it's not installed.  Aborting."; exit 1; }
7 SOURCE_DIR=$(realpath ${CURRENT_DIR}/..)
8 REPORT_DIR="${SOURCE_DIR}/report"
9 CPPLINT_REPORT_DIR="${REPORT_DIR}/cpplint"
10 PROJECT_NAME="Inference Engine"
11
12 function run_cpplint() {
13     echo "-> CppLint started..."
14     if [ -d ${CPPLINT_REPORT_DIR} ]; then
15         rm -Rf ${CPPLINT_REPORT_DIR}
16     fi
17
18     mkdir -p ${CPPLINT_REPORT_DIR}
19     python ${CURRENT_DIR}/cpplint.py --linelength=160 --counting=detailed --quiet --filter="
20         -build/header_guard,
21         -build/include,
22         -build/include_order,
23         -build/include_subdir,
24         -build/include_what_you_use,
25         -build/namespaces,
26         -build/c++11,
27         -whitespace/indent,
28         -whitespace/comments,
29         -whitespace/ending_newline,
30         -runtime/references,
31         -runtime/int,
32         -runtime/explicit,
33         -readability/todo,
34         -readability/fn_size
35     " $(find ${SOURCE_DIR} -name '*.h' -or -name '*.cc' -or -name '*.c' -or -name '*.cpp' -or -name '*.hpp' |
36         grep -v 'inference-engine/bin\|inference-engine/build\|inference-engine/report\|inference-engine/scripts\|inference-engine/temp\|inference-engine/tests_deprecated/\|gtest\|inference-engine/ie_bridges\|pugixml\|inference-engine/tools/vpu_perfcheck\|thirdparty/gflags\|thirdparty/ade\|thirdparty/fluid\|thirdparty/mkl-dnn\|thirdparty/movidius\|thirdparty/ocv\|thirdparty/plugixml\|thirdparty/std_lib\|thirdparty/clDNN/common\|thirdparty/clDNN/tutorial\|thirdparty/clDNN/utils' |
37         grep 'include\|src\|inference-engine/samples\|thirdparty/clDNN/kernel_selector\|thirdparty/clDNN/api\|thirdparty/clDNN/api_extension\|inference-engine/tests_' ) 2>&1 |
38         sed 's/"/\&quot;/g' >&1| sed 's/</\&lt;/g' >&1| sed 's/>/\&gt;/g' >&1| sed "s/'/\&apos;/g" >&1|
39         sed 's/\&/\&amp;/g' >&1| python ${CURRENT_DIR}/cpplint_to_cppcheckxml.py &> ${CPPLINT_REPORT_DIR}/cpplint-cppcheck-result.xml
40
41         # Generate html from it
42         ${CURRENT_DIR}/cppcheck-htmlreport.py --file=${CPPLINT_REPORT_DIR}/cpplint-cppcheck-result.xml --report-dir=${CPPLINT_REPORT_DIR} --source-dir=${SOURCE_DIR} --title=${PROJECT_NAME}
43
44         # Change Cppcheck things to cpplint
45         sed -i.bak 's/Cppcheck/cpplint/g' ${CPPLINT_REPORT_DIR}/index.html
46         sed -i.bak 's/a\ tool\ for\ static\ C\/C++\ code\ analysis/an\ open\ source\ lint\-like\ tool\ from\ Google/g' ${CPPLINT_REPORT_DIR}/index.html
47         sed -i.bak 's/http:\/\/cppcheck.sourceforge.net/http:\/\/google\-styleguide.googlecode.com\/svn\/trunk\/cpplint\/cpplint.py/g' ${CPPLINT_REPORT_DIR}/index.html
48         sed -i.bak 's/IRC: <a href=\"irc:\/\/irc.freenode.net\/cppcheck\">irc:\/\/irc.freenode.net\/cppcheck<\/a>/\ /g' ${CPPLINT_REPORT_DIR}/index.html
49
50     echo "-> CppLint finished..."
51 }
52
53 function run_cpp_check() {
54     echo "-> Cppcheck started..."
55     CPPCHECK_REPORT_DIR="${REPORT_DIR}/cppcheck"
56     if [ -d ${CPPCHECK_REPORT_DIR} ]; then
57         rm -Rf ${CPPCHECK_REPORT_DIR}
58     fi
59
60     mkdir -p ${CPPCHECK_REPORT_DIR}
61
62         # Generate cppcheck xml
63         cppcheck -v --enable=all --suppress=missingIncludeSystem --std=c++11 ${SOURCE_DIR} -i${SOURCE_DIR}/thirdparty -i${SOURCE_DIR}/tests/libs -i${SOURCE_DIR}/temp -i${SOURCE_DIR}/build \
64           -i${SOURCE_DIR}/bin -i${SOURCE_DIR}/report -I${SOURCE_DIR}/include -I${SOURCE_DIR}/src -I${SOURCE_DIR}/thirdparty/pugixml/src -I${SOURCE_DIR}/thirdparty/gflags/src -I${SOURCE_DIR}/samples/scoring_agent/HTTPClient -I${SOURCE_DIR}/src/inference_engine --xml-version=2 2> ${CPPCHECK_REPORT_DIR}/cppcheck-only-result.xml
65
66         # Generate html from it
67         python ${CURRENT_DIR}/cppcheck-htmlreport.py\
68                 --file=${CPPCHECK_REPORT_DIR}/cppcheck-only-result.xml\
69                 --report-dir=${CPPCHECK_REPORT_DIR}\
70                 --source-dir=${SOURCE_DIR}\
71                 --title=${PROJECT_NAME}
72     echo "-> Cppcheck finished..."
73 }
74
75 if [ ! -d ${REPORT_DIR} ]; then
76     mkdir -p ${REPORT_DIR}
77 fi
78
79 run_cpplint
80
81 out_cpp_lint=`cat ${CPPLINT_REPORT_DIR}/cpplint-cppcheck-result.xml`
82 if [[ ${out_cpp_lint} == *"error"* ]]; then
83     exit 1
84 fi
85 #run_cpp_check