blob: c6f18cc8a486a8be31ef4f46d8c59b606063e240 [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.
27 ECLAIR_OUTPUT_DIR="${WORKSPACE}/ECLAIR/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 \
75 -full_html=${ECLAIR_OUTPUT_DIR}/../full_html \
76 -full_xml=${ECLAIR_OUTPUT_DIR}/../full_xml
77
78 # summary_txt contains just a single report file not present in full_txt, move it there and be done with it.
79 mv ${ECLAIR_OUTPUT_DIR}/../summary_txt/by_service.txt ${ECLAIR_OUTPUT_DIR}/../full_txt/
80 rm -rf ${ECLAIR_OUTPUT_DIR}/../summary_txt
81
82 eclair_make_report_self_contained ${ECLAIR_OUTPUT_DIR}/../full_html
83}