blob: 84efeb1df42bb5443d883bc6952794db509a3e84 [file] [log] [blame]
Arthur Shece0323a2025-04-01 21:12:02 -07001#!/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
15
16# 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
25
26 # Directory where to put all ECLAIR output and temporary files.
27 ECLAIR_OUTPUT_DIR="${WORKSPACE}/${ECLAIR_ANALYSIS}/out"
28
29 # ECLAIR binary data directory and workspace.
30 export ECLAIR_DATA_DIR="${ECLAIR_OUTPUT_DIR}/.data"
31
32 # Destination file for the ECLAIR diagnostics.
33 export ECLAIR_DIAGNOSTICS_OUTPUT="${ECLAIR_OUTPUT_DIR}/DIAGNOSTICS.txt"
34
35 PROJECT_ECD="${ECLAIR_OUTPUT_DIR}/PROJECT.ecd"
36}
37
38eclair_prepare() {
39 eclair_set_paths
40 mkdir -p "${ECLAIR_DATA_DIR}"
41}
42
43eclair_analyze() {
44 eclair_set_paths
45 (
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
53# Create the project database.
54eclair_make_ecd() {
55 eclair_set_paths
56 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/lib/html $dir/lib
68
69 ${_ECLAIR_UTILS_DIR}/relativize_urls.py $dir
70}
71
72eclair_make_reports() {
73 eclair_set_paths
74 ${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 \
78 -full_html=${ECLAIR_OUTPUT_DIR}/../full_html
79
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}
86
87eclair_compress_db() {
88 eclair_set_paths
89
90 # Compress database to take less disk space in Jenkins archive
91 xz ${PROJECT_ECD}
92}
93
94eclair_make_delta_report() {
95 base_dir=$1
96 target_dir=$2
97
98 diff -I '^Timestamp:' -x frames.txt -x files.txt -x explain.txt \
99 -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
104 ${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
109 eclair_make_report_self_contained resolved_issues_html
110
111 ${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
116 eclair_make_report_self_contained new_issues_html
117
118 xz ${base_dir}/out/PROJECT.ecd ${target_dir}/out/PROJECT.ecd
119}