blob: 59a35e553f5a4c0a38fb1af3ddac50548dbdc717 [file] [log] [blame]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +01001#!/bin/bash
2#-------------------------------------------------------------------------------
3# Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7#-------------------------------------------------------------------------------
8
9##
10##@file
11##@brief Execute cppcheck
12##
13##This bash script can be used to execute cppcheck for the tf-m project.
14##It will use the CMake generated "compile_commands.json" file.
15##CMake is executed to generate the build commands for the "default" build
16##configuration (i.e. no build config file is specifyed on the command-line).
17##
18##This file shall be executed from the root directory of the tf-m working copy.
19##
20##In order to have all include file in place, some CMake external projects will
21##be built, and thus C build tools for the default build configuration must be
22##available.
23##
24##The script will generate two XML output files:
25##file | description
26##--------|--------
27##chk-config.xml | The result of cppcheck configuration verification.
28##chk-src.xml. | The result of source file verification.
29##
30##@todo The current version of cppcheck seems to ignore command line parameters
31## when using the --project command line switch. As a result it is not
32## possible to define additional macros and include paths on the command
33## line. This results in some incorrect error and warning messages.
34##@todo The file cppcheck/arm-cortex-m.cfg needs to be revised. Some settings
35## might be invalid, and also a differnet file may be needed based on
36## used compiler switches (i.e. to match witdh specification and or default
37## sign for some types).
38##@todo Currently cppcheck is only executed for the default build configuration
39## "ConfigDefault.cmake"for target AN521 of the "top level" project.
40## This might need to be revied/changed in the future.
41##
42
43#Fail if any command exit with error.
44set -e
45
46#The location from where the script executes
47mypath=$(dirname $0)
48
49. "$mypath/util_cmake.sh"
50
51
52#Library file for cppcheck
53library_file="$(fix_win_path $(get_full_path $mypath))/cppcheck/arm-cortex-m.cfg"
54suppress_file="$(fix_win_path $(get_full_path $mypath))/cppcheck/tfm-suppress-list.txt"
55
56#Run cmake to get the compile_commands.json file
57echo
58echo '******* Generating compile_commandas.json ***************'
59echo
60generate_project $(fix_win_path $(get_full_path ./)) "./" "cppcheck" "-DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DTARGET_PLATFORM=AN521 -DCOMPILER=GNUARM"
61#Enter the build directory
62bdir=$(make_build_dir_name "./" "cppcheck")
63pushd "$bdir" >/dev/null
64#Build the external projects to get all headers installed to plases from where
65#tf-m code uses them
66echo
67echo '******* Install external projects to their final place ***************'
68echo
69make -j mbedtls_sst_lib_install mbedtls_mcuboot_lib_install
70
71#Now run cppcheck.
72echo
73echo '******* checking cppcheck configuration ***************'
74echo
75cppcheck --xml -j 4 --check-config --enable=all --library="$library_file" --project=compile_commands.json --suppressions-list="$suppress_file" --inline-suppr 2>chk-config.xml
76
77echo
78echo '******* analyzing files with cppcheck ***************'
79echo
80cppcheck --xml -j 4 --enable=all --library="$library_file" --project=compile_commands.json --suppressions-list="$suppress_file" --inline-suppr 2>chk-src.xml
81popd
82
83echo
84echo '******* Please check chk-config.xml and chk-src.xml for the results. ***************'
85echo