blob: aff1909374d75d2a9f1c9b05e1895f3bd476cf54 [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#Fail if any executed command fails.
10set -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
29if [ -z ${1+x} ]
30then
31 echo "Cppcheck output file not specified!"
32 exit 1
33fi
34
35xml_file="$1"
36
37#List of error types cmake reports.
38severity_list=( "none" "error" "warning" "style" "performance" "portability"
39 "information" "debug")
40
41#Count each severity type and build result message.
42for severity in "${severity_list[@]}"
43do
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"
54done
55msg="Cppcheck results: $issue_list"
56
57echo "$msg"