blob: 36170639420688e6f8ba560e425b1bc4dd5eb4fc [file] [log] [blame]
Paul Sokolovsky3486b4e2022-09-06 13:33:57 +03001#!/bin/bash
2#
3# Copyright (c) 2021-2022 BUGSENG srl. All rights reserved.
4# Copyright (c) 2022 Arm Limited. All rights reserved.
5#
6# SPDX-License-Identifier: BSD-3-Clause
7
8# Stop immediately if any executed command has exit status different from 0.
9set -ex
10
11usage() {
12 echo "Usage: analyze.sh CONF" 1>&2
13 echo " where CONF is the build configuration id passed to build.sh" 1>&2
14}
15
16if [ $# -ne 1 ]
17then
18 usage
19 exit 1
20fi
21
Paul Sokolovsky4c859012022-10-08 14:50:34 +030022TF_CONFIG="$1"
Paul Sokolovsky3486b4e2022-09-06 13:33:57 +030023
Paul Sokolovsky4c859012022-10-08 14:50:34 +030024# Directory where this script resides.
Paul Sokolovsky3486b4e2022-09-06 13:33:57 +030025SCRIPT_DIR="$(cd "$(dirname "$0")" ; echo "${PWD}")"
26
Paul Sokolovsky4c859012022-10-08 14:50:34 +030027. ${SCRIPT_DIR}/analyze_common.sh
Paul Sokolovsky3486b4e2022-09-06 13:33:57 +030028
29function do_analyze() {
30
31 # ECLAIR binary data directory and workspace.
32 export ECLAIR_DATA_DIR="${ECLAIR_OUTPUT_DIR}/.data"
33 # ECLAIR workspace.
34 export ECLAIR_WORKSPACE="${ECLAIR_DATA_DIR}/eclair_workspace"
35 # Destination file for the ECLAIR diagnostics.
36 export ECLAIR_DIAGNOSTICS_OUTPUT="${ECLAIR_OUTPUT_DIR}/DIAGNOSTICS.txt"
37
38 # Erase and recreate the output directory and the data directory.
39 rm -rf "${ECLAIR_OUTPUT_DIR}"
40 mkdir -p "${ECLAIR_DATA_DIR}"
41
42 (
43 # Perform the build (from scratch) in an ECLAIR environment.
44 "${ECLAIR_BIN_DIR}/eclair_env" \
45 "-eval_file='${SCRIPT_DIR}/MISRA_C_2012_selection.ecl'" \
Paul Sokolovsky4c859012022-10-08 14:50:34 +030046 -- "${SCRIPT_DIR}/build-tfa.sh" "${TF_CONFIG}"
Paul Sokolovsky3486b4e2022-09-06 13:33:57 +030047 )
48
49 # Create the project database.
50 PROJECT_ECD="${ECLAIR_OUTPUT_DIR}/PROJECT.ecd"
51 find "${ECLAIR_DATA_DIR}" -maxdepth 1 -name "FRAME.*.ecb" \
52 | sort | xargs cat \
53 | "${ECLAIR_BIN_DIR}/eclair_report" \
54 "-create_db='${PROJECT_ECD}'" \
55 -load=/dev/stdin
56
57
58 function make_self_contained() {
59 dir=$1
60 mkdir -p $dir/lib
61
62 cp -r /opt/bugseng/eclair-3.12.0/lib/html $dir/lib
63
64 ${SCRIPT_DIR}/relativize_urls.py $dir
65 }
66
67 ${ECLAIR_BIN_DIR}/eclair_report -db=${PROJECT_ECD} \
68 -summary_txt=${ECLAIR_OUTPUT_DIR}/../summary_txt \
69 -full_txt=${ECLAIR_OUTPUT_DIR}/../full_txt \
70 -full_html=${ECLAIR_OUTPUT_DIR}/../full_html
71
72 # summary_txt contains just a single report file not present in full_txt, move it there and be done with it.
73 mv ${ECLAIR_OUTPUT_DIR}/../summary_txt/by_service.txt ${ECLAIR_OUTPUT_DIR}/../full_txt/
74 rm -rf ${ECLAIR_OUTPUT_DIR}/../summary_txt
75 make_self_contained ${ECLAIR_OUTPUT_DIR}/../full_html
76
77 # Create the Jenkins reports file.
78 JENKINS_XML="${ECLAIR_OUTPUT_DIR}/../jenkins.xml"
79 ${ECLAIR_BIN_DIR}/eclair_report -db=${PROJECT_ECD} -reports_jenkins=${JENKINS_XML}
80
81}
82
83# Directory where to put all ECLAIR output and temporary files.
84ECLAIR_OUTPUT_DIR="${WORKSPACE}/ECLAIR/out"
85
86do_analyze
87
88ECLAIR_OUTPUT_DIR="${WORKSPACE}/ECLAIR_BASE/out"
89
90(
91 cd ${ECLAIR_PROJECT_ROOT}
92 git checkout HEAD^
93 git log --oneline -n5
94)
95
96do_analyze
97
98diff -I '^Timestamp:' -x frames.txt -x files.txt -x explain.txt \
99 -ur ${WORKSPACE}/ECLAIR_BASE/summary_txt/ ${WORKSPACE}/ECLAIR/summary_txt/ > ${WORKSPACE}/ECLAIR/summary_txt.diff || true
100
101
102(
103${ECLAIR_BIN_DIR}/eclair_report -diff_criteria=fingerprint -diff_full_txt=ECLAIR_BASE/out/PROJECT.ecd,ECLAIR/out/PROJECT.ecd
104ls -l diff_output
105
106eclair_report -db=ECLAIR_BASE/out/PROJECT.ecd -sel_tag_glob=new,diff,missing -full_html=resolved_issues_html
107make_self_contained resolved_issues_html
108
109eclair_report -db=ECLAIR/out/PROJECT.ecd -sel_tag_glob=new,diff,missing -full_html=new_issues_html
110make_self_contained new_issues_html
111
112xz ECLAIR_BASE/out/PROJECT.ecd ECLAIR/out/PROJECT.ecd
113)
114
115${SCRIPT_DIR}/eclair_diff_report.py diff_output > misra_delta.txt
116
117
118cat <<EOF >index.html
119<html>
120<body>
121<h1>MISRA Delta reports for the patch</h1>
Paul Sokolovskya1be51a2022-09-29 18:37:15 +0300122
123<p>
124Patch: <a href="${GERRIT_CHANGE_URL}/${GERRIT_PATCHSET_NUMBER}">${GERRIT_CHANGE_URL}/${GERRIT_PATCHSET_NUMBER}</a><br />
125CI Build: <a href="${BUILD_URL}">${BUILD_URL}</a>
126</p>
127
Paul Sokolovsky3486b4e2022-09-06 13:33:57 +0300128<li><a href="misra_delta.txt">Cumulative TXT report</a>
129<li><a href="diff_output/">Per MISRA rule TXT reports</a>
130<li><a href="new_issues_html/by_service.html#first_file/service&kind">New issues, groupped per file changed (HTML).</a>
131<li><a href="resolved_issues_html/by_service.html#first_file/service&kind">Resolved issues, groupped per file changed (HTML).</a>
132</body>
133</html>
134EOF