Paul Sokolovsky | 5772f92 | 2023-05-30 20:57:26 +0300 | [diff] [blame] | 1 | #!/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). |
| 10 | export _ECLAIR_UTILS_DIR="$(cd "$(dirname "$BASH_SOURCE")" ; echo "${PWD}")" |
| 11 | |
| 12 | # Absolute path of the ECLAIR bin directory. |
| 13 | ECLAIR_BIN_DIR="/opt/bugseng/eclair/bin" |
| 14 | |
Paul Sokolovsky | 5772f92 | 2023-05-30 20:57:26 +0300 | [diff] [blame] | 15 | |
Paul Sokolovsky | fb11ee2 | 2023-06-13 13:19:44 +0300 | [diff] [blame] | 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). |
| 20 | eclair_set_paths() { |
| 21 | if [ -z "${ECLAIR_ANALYSIS}" ]; then |
| 22 | echo "ECLAIR_ANALYSIS is not defined" |
| 23 | exit 1 |
| 24 | fi |
Paul Sokolovsky | 5772f92 | 2023-05-30 20:57:26 +0300 | [diff] [blame] | 25 | |
Paul Sokolovsky | fb11ee2 | 2023-06-13 13:19:44 +0300 | [diff] [blame] | 26 | # Directory where to put all ECLAIR output and temporary files. |
| 27 | ECLAIR_OUTPUT_DIR="${WORKSPACE}/ECLAIR/out" |
Paul Sokolovsky | 5772f92 | 2023-05-30 20:57:26 +0300 | [diff] [blame] | 28 | |
Paul Sokolovsky | fb11ee2 | 2023-06-13 13:19:44 +0300 | [diff] [blame] | 29 | # 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 Sokolovsky | 5772f92 | 2023-05-30 20:57:26 +0300 | [diff] [blame] | 34 | |
| 35 | eclair_prepare() { |
Paul Sokolovsky | fb11ee2 | 2023-06-13 13:19:44 +0300 | [diff] [blame] | 36 | eclair_set_paths |
Paul Sokolovsky | 5772f92 | 2023-05-30 20:57:26 +0300 | [diff] [blame] | 37 | mkdir -p "${ECLAIR_DATA_DIR}" |
| 38 | } |
| 39 | |
| 40 | eclair_analyze() { |
Paul Sokolovsky | fb11ee2 | 2023-06-13 13:19:44 +0300 | [diff] [blame] | 41 | eclair_set_paths |
Paul Sokolovsky | 5772f92 | 2023-05-30 20:57:26 +0300 | [diff] [blame] | 42 | ( |
| 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 Sokolovsky | fb11ee2 | 2023-06-13 13:19:44 +0300 | [diff] [blame] | 50 | # Create the project database. |
Paul Sokolovsky | 5772f92 | 2023-05-30 20:57:26 +0300 | [diff] [blame] | 51 | eclair_make_ecd() { |
Paul Sokolovsky | fb11ee2 | 2023-06-13 13:19:44 +0300 | [diff] [blame] | 52 | eclair_set_paths |
Paul Sokolovsky | 5772f92 | 2023-05-30 20:57:26 +0300 | [diff] [blame] | 53 | 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 | |
| 60 | eclair_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 | |
| 69 | eclair_make_reports() { |
Paul Sokolovsky | fb11ee2 | 2023-06-13 13:19:44 +0300 | [diff] [blame] | 70 | eclair_set_paths |
Paul Sokolovsky | 5772f92 | 2023-05-30 20:57:26 +0300 | [diff] [blame] | 71 | ${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 | } |