blob: b5142cbae3feb7a3b7a790e2e98ded0fe39173e2 [file] [log] [blame]
Paul Sokolovsky5772f922023-05-30 20:57:26 +03001#!/usr/bin/env python3
2#
3# Copyright (c) 2022-2023 Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7# Common utility functions for Bugseng ECLAIR tool.
8
9# Directory where this script resides (assuming it was sourced).
10export _ECLAIR_UTILS_DIR="$(cd "$(dirname "$BASH_SOURCE")" ; echo "${PWD}")"
11
12# Absolute path of the ECLAIR bin directory.
13ECLAIR_BIN_DIR="/opt/bugseng/eclair/bin"
14
Paul Sokolovsky5772f922023-05-30 20:57:26 +030015
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030016# Set various path variables based on ECLAIR_ANALYSIS var (which is a name
17# of top-level dir to hold internal files and results of anaylisis). We
18# need to support this variability to e.g. support delta reports
19# between two analyses (before and after a patch).
20eclair_set_paths() {
21 if [ -z "${ECLAIR_ANALYSIS}" ]; then
22 echo "ECLAIR_ANALYSIS is not defined"
23 exit 1
24 fi
Paul Sokolovsky5772f922023-05-30 20:57:26 +030025
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030026 # Directory where to put all ECLAIR output and temporary files.
Paul Sokolovsky78cb2772023-06-17 11:11:15 +030027 ECLAIR_OUTPUT_DIR="${WORKSPACE}/${ECLAIR_ANALYSIS}/out"
Paul Sokolovsky5772f922023-05-30 20:57:26 +030028
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030029 # ECLAIR binary data directory and workspace.
30 export ECLAIR_DATA_DIR="${ECLAIR_OUTPUT_DIR}/.data"
31
32 PROJECT_ECD="${ECLAIR_OUTPUT_DIR}/PROJECT.ecd"
33}
Paul Sokolovsky5772f922023-05-30 20:57:26 +030034
35eclair_prepare() {
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030036 eclair_set_paths
Paul Sokolovsky5772f922023-05-30 20:57:26 +030037 mkdir -p "${ECLAIR_DATA_DIR}"
38}
39
40eclair_analyze() {
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030041 eclair_set_paths
Paul Sokolovsky5772f922023-05-30 20:57:26 +030042 (
43 # Run a build in the ECLAIR environment.
44 "${ECLAIR_BIN_DIR}/eclair_env" \
45 "-eval_file='${ECLAIR_CONFIG_DIR}/MISRA_C_2012_selection.ecl'" \
46 -- "$@"
47 )
48}
49
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030050# Create the project database.
Paul Sokolovsky5772f922023-05-30 20:57:26 +030051eclair_make_ecd() {
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030052 eclair_set_paths
Paul Sokolovsky5772f922023-05-30 20:57:26 +030053 find "${ECLAIR_DATA_DIR}" -maxdepth 1 -name "FRAME.*.ecb" \
54 | sort | xargs cat \
55 | "${ECLAIR_BIN_DIR}/eclair_report" \
56 "-create_db='${PROJECT_ECD}'" \
57 -load=/dev/stdin
58}
59
60eclair_make_report_self_contained() {
61 dir=$1
62 mkdir -p $dir/lib
63
64 cp -r /opt/bugseng/eclair-3.12.0/lib/html $dir/lib
65
66 ${_ECLAIR_UTILS_DIR}/relativize_urls.py $dir
67}
68
69eclair_make_reports() {
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030070 eclair_set_paths
Paul Sokolovsky5772f922023-05-30 20:57:26 +030071 ${ECLAIR_BIN_DIR}/eclair_report -db=${PROJECT_ECD} \
72 -summary_txt=${ECLAIR_OUTPUT_DIR}/../summary_txt \
73 -full_txt=${ECLAIR_OUTPUT_DIR}/../full_txt \
74 -reports1_html=strictness,${ECLAIR_OUTPUT_DIR}/../full_html/by_strictness/@TAG@.html \
Paul Sokolovskyea113b32023-06-24 17:43:41 +030075 -full_html=${ECLAIR_OUTPUT_DIR}/../full_html
Paul Sokolovsky5772f922023-05-30 20:57:26 +030076
77 # summary_txt contains just a single report file not present in full_txt, move it there and be done with it.
78 mv ${ECLAIR_OUTPUT_DIR}/../summary_txt/by_service.txt ${ECLAIR_OUTPUT_DIR}/../full_txt/
79 rm -rf ${ECLAIR_OUTPUT_DIR}/../summary_txt
80
81 eclair_make_report_self_contained ${ECLAIR_OUTPUT_DIR}/../full_html
82}
Paul Sokolovskyeaaeb312023-06-20 21:02:03 +030083
84eclair_make_delta_report() {
Paul Sokolovsky29747a02023-06-20 21:45:09 +030085 base_dir=$1
86 target_dir=$2
87
Paul Sokolovskyeaaeb312023-06-20 21:02:03 +030088 diff -I '^Timestamp:' -x frames.txt -x files.txt -x explain.txt \
Paul Sokolovsky29747a02023-06-20 21:45:09 +030089 -ur ${WORKSPACE}/${base_dir}/summary_txt/ ${WORKSPACE}/${target_dir}/summary_txt/ > ${WORKSPACE}/${target_dir}/summary_txt.diff || true
90
91 ${ECLAIR_BIN_DIR}/eclair_report -diff_criteria=fingerprint -diff_full_txt=${base_dir}/out/PROJECT.ecd,${target_dir}/out/PROJECT.ecd
92 ls -l diff_output
93
94 ${ECLAIR_BIN_DIR}/eclair_report -db=${base_dir}/out/PROJECT.ecd -sel_tag_glob=new,diff,missing -full_html=resolved_issues_html
95 eclair_make_report_self_contained resolved_issues_html
96
Paul Sokolovsky078028e2023-06-24 20:53:48 +020097 ${ECLAIR_BIN_DIR}/eclair_report -db=${target_dir}/out/PROJECT.ecd -sel_tag_glob=new,diff,missing -full_html=new_issues_html
Paul Sokolovsky29747a02023-06-20 21:45:09 +030098 eclair_make_report_self_contained new_issues_html
99
100 xz ${base_dir}/out/PROJECT.ecd ${target_dir}/out/PROJECT.ecd
Paul Sokolovskyeaaeb312023-06-20 21:02:03 +0300101}