blob: 790081e9eb48a428a75b878bd61daab2d9083cbc [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
Paul Sokolovskyc0fcf512023-07-03 22:10:35 +030032 # Destination file for the ECLAIR diagnostics.
33 export ECLAIR_DIAGNOSTICS_OUTPUT="${ECLAIR_OUTPUT_DIR}/DIAGNOSTICS.txt"
34
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030035 PROJECT_ECD="${ECLAIR_OUTPUT_DIR}/PROJECT.ecd"
36}
Paul Sokolovsky5772f922023-05-30 20:57:26 +030037
38eclair_prepare() {
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030039 eclair_set_paths
Paul Sokolovsky5772f922023-05-30 20:57:26 +030040 mkdir -p "${ECLAIR_DATA_DIR}"
41}
42
43eclair_analyze() {
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030044 eclair_set_paths
Paul Sokolovsky5772f922023-05-30 20:57:26 +030045 (
46 # Run a build in the ECLAIR environment.
47 "${ECLAIR_BIN_DIR}/eclair_env" \
48 "-eval_file='${ECLAIR_CONFIG_DIR}/MISRA_C_2012_selection.ecl'" \
49 -- "$@"
50 )
51}
52
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030053# Create the project database.
Paul Sokolovsky5772f922023-05-30 20:57:26 +030054eclair_make_ecd() {
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030055 eclair_set_paths
Paul Sokolovsky5772f922023-05-30 20:57:26 +030056 find "${ECLAIR_DATA_DIR}" -maxdepth 1 -name "FRAME.*.ecb" \
57 | sort | xargs cat \
58 | "${ECLAIR_BIN_DIR}/eclair_report" \
59 "-create_db='${PROJECT_ECD}'" \
60 -load=/dev/stdin
61}
62
63eclair_make_report_self_contained() {
64 dir=$1
65 mkdir -p $dir/lib
66
67 cp -r /opt/bugseng/eclair-3.12.0/lib/html $dir/lib
68
69 ${_ECLAIR_UTILS_DIR}/relativize_urls.py $dir
70}
71
72eclair_make_reports() {
Paul Sokolovskyfb11ee22023-06-13 13:19:44 +030073 eclair_set_paths
Paul Sokolovsky5772f922023-05-30 20:57:26 +030074 ${ECLAIR_BIN_DIR}/eclair_report -db=${PROJECT_ECD} \
75 -summary_txt=${ECLAIR_OUTPUT_DIR}/../summary_txt \
76 -full_txt=${ECLAIR_OUTPUT_DIR}/../full_txt \
77 -reports1_html=strictness,${ECLAIR_OUTPUT_DIR}/../full_html/by_strictness/@TAG@.html \
Paul Sokolovskyea113b32023-06-24 17:43:41 +030078 -full_html=${ECLAIR_OUTPUT_DIR}/../full_html
Paul Sokolovsky5772f922023-05-30 20:57:26 +030079
80 # summary_txt contains just a single report file not present in full_txt, move it there and be done with it.
81 mv ${ECLAIR_OUTPUT_DIR}/../summary_txt/by_service.txt ${ECLAIR_OUTPUT_DIR}/../full_txt/
82 rm -rf ${ECLAIR_OUTPUT_DIR}/../summary_txt
83
84 eclair_make_report_self_contained ${ECLAIR_OUTPUT_DIR}/../full_html
85}
Paul Sokolovskyeaaeb312023-06-20 21:02:03 +030086
Paul Sokolovsky6fe262c2023-07-03 00:05:36 +030087eclair_compress_db() {
88 eclair_set_paths
89
90 # Compress database to take less disk space in Jenkins archive
91 xz ${PROJECT_ECD}
92}
93
Paul Sokolovskyeaaeb312023-06-20 21:02:03 +030094eclair_make_delta_report() {
Paul Sokolovsky29747a02023-06-20 21:45:09 +030095 base_dir=$1
96 target_dir=$2
97
Paul Sokolovskyeaaeb312023-06-20 21:02:03 +030098 diff -I '^Timestamp:' -x frames.txt -x files.txt -x explain.txt \
Paul Sokolovsky29747a02023-06-20 21:45:09 +030099 -ur ${WORKSPACE}/${base_dir}/summary_txt/ ${WORKSPACE}/${target_dir}/summary_txt/ > ${WORKSPACE}/${target_dir}/summary_txt.diff || true
100
101 ${ECLAIR_BIN_DIR}/eclair_report -diff_criteria=fingerprint -diff_full_txt=${base_dir}/out/PROJECT.ecd,${target_dir}/out/PROJECT.ecd
102 ls -l diff_output
103
Paul Sokolovskyd51d9da2023-06-29 21:46:08 +0300104 ${ECLAIR_BIN_DIR}/eclair_report \
105 -db=${base_dir}/out/PROJECT.ecd \
106 -eval_file=${_ECLAIR_UTILS_DIR}/sel_tag_and_not_glob.ecl \
107 -sel_tag_and_not_glob=new_no_expl,diff,missing,service,B.EXPLAIN \
108 -full_html=resolved_issues_html
Paul Sokolovsky29747a02023-06-20 21:45:09 +0300109 eclair_make_report_self_contained resolved_issues_html
110
Paul Sokolovskyd51d9da2023-06-29 21:46:08 +0300111 ${ECLAIR_BIN_DIR}/eclair_report \
112 -db=${target_dir}/out/PROJECT.ecd \
113 -eval_file=${_ECLAIR_UTILS_DIR}/sel_tag_and_not_glob.ecl \
114 -sel_tag_and_not_glob=new_no_expl,diff,missing,service,B.EXPLAIN \
115 -full_html=new_issues_html
Paul Sokolovsky29747a02023-06-20 21:45:09 +0300116 eclair_make_report_self_contained new_issues_html
117
118 xz ${base_dir}/out/PROJECT.ecd ${target_dir}/out/PROJECT.ecd
Paul Sokolovskyeaaeb312023-06-20 21:02:03 +0300119}