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 | #Fail if any executed command fails. |
| 10 | set -e |
| 11 | |
| 12 | ## |
| 13 | ##@file |
| 14 | ##@brief This script is to make a summary of cppcheck XML output files. |
| 15 | ## |
| 16 | ##The generated summary will hold the number of messages of each severity type. |
| 17 | ## |
| 18 | ##The first parameter of the script must be the location of the XML file. |
| 19 | ## |
| 20 | ##The script uses regual expressions to identify and count messages. |
| 21 | ## |
| 22 | ##Usage: |
| 23 | ## command | result |
| 24 | ## --------|------- |
| 25 | ## make_cppcheck_summary.sh foo/bar/build.xml | Summary text. |
| 26 | ## |
| 27 | |
| 28 | #Check parameter |
| 29 | if [ -z ${1+x} ] |
| 30 | then |
| 31 | echo "Cppcheck output file not specified!" |
| 32 | exit 1 |
| 33 | fi |
| 34 | |
| 35 | xml_file="$1" |
| 36 | |
| 37 | #List of error types cmake reports. |
| 38 | severity_list=( "none" "error" "warning" "style" "performance" "portability" |
| 39 | "information" "debug") |
| 40 | |
| 41 | #Count each severity type and build result message. |
| 42 | for severity in "${severity_list[@]}" |
| 43 | do |
| 44 | #Count lines with this severity type. |
| 45 | n=$(grep -c "severity=\"$severity\"" "$xml_file" || true) |
| 46 | #Start of report line |
| 47 | line=$'\n\tIssues with severity '"\"$severity\":" |
| 48 | #Indentatin to character position 46. |
| 49 | indent=$(eval "printf ' %.0s' {1..$(( 46-${#line} ))}") |
| 50 | #Add identation and number |
| 51 | line="$line$indent$n" |
| 52 | #Extend issue list |
| 53 | issue_list="$issue_list$line" |
| 54 | done |
| 55 | msg="Cppcheck results: $issue_list" |
| 56 | |
| 57 | echo "$msg" |