Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame^] | 1 | #!/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. |
| 44 | set -e |
| 45 | |
| 46 | #The location from where the script executes |
| 47 | mypath=$(dirname $0) |
| 48 | |
| 49 | . "$mypath/util_cmake.sh" |
| 50 | |
| 51 | |
| 52 | #Library file for cppcheck |
| 53 | library_file="$(fix_win_path $(get_full_path $mypath))/cppcheck/arm-cortex-m.cfg" |
| 54 | suppress_file="$(fix_win_path $(get_full_path $mypath))/cppcheck/tfm-suppress-list.txt" |
| 55 | |
| 56 | #Run cmake to get the compile_commands.json file |
| 57 | echo |
| 58 | echo '******* Generating compile_commandas.json ***************' |
| 59 | echo |
| 60 | generate_project $(fix_win_path $(get_full_path ./)) "./" "cppcheck" "-DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DTARGET_PLATFORM=AN521 -DCOMPILER=GNUARM" |
| 61 | #Enter the build directory |
| 62 | bdir=$(make_build_dir_name "./" "cppcheck") |
| 63 | pushd "$bdir" >/dev/null |
| 64 | #Build the external projects to get all headers installed to plases from where |
| 65 | #tf-m code uses them |
| 66 | echo |
| 67 | echo '******* Install external projects to their final place ***************' |
| 68 | echo |
| 69 | make -j mbedtls_sst_lib_install mbedtls_mcuboot_lib_install |
| 70 | |
| 71 | #Now run cppcheck. |
| 72 | echo |
| 73 | echo '******* checking cppcheck configuration ***************' |
| 74 | echo |
| 75 | cppcheck --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 | |
| 77 | echo |
| 78 | echo '******* analyzing files with cppcheck ***************' |
| 79 | echo |
| 80 | cppcheck --xml -j 4 --enable=all --library="$library_file" --project=compile_commands.json --suppressions-list="$suppress_file" --inline-suppr 2>chk-src.xml |
| 81 | popd |
| 82 | |
| 83 | echo |
| 84 | echo '******* Please check chk-config.xml and chk-src.xml for the results. ***************' |
| 85 | echo |