Add eclair scripts
copy these scripts from ci/tf-ci-scripts
Signed-off-by: Arthur She <arthur.she@linaro.org>
Change-Id: I555cb85bcb207d247d84e06fcd47d22e55b4ac10
diff --git a/eclair/utils.sh b/eclair/utils.sh
new file mode 100644
index 0000000..84efeb1
--- /dev/null
+++ b/eclair/utils.sh
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2022-2023 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Common utility functions for Bugseng ECLAIR tool.
+
+# Directory where this script resides (assuming it was sourced).
+export _ECLAIR_UTILS_DIR="$(cd "$(dirname "$BASH_SOURCE")" ; echo "${PWD}")"
+
+# Absolute path of the ECLAIR bin directory.
+ECLAIR_BIN_DIR="/opt/bugseng/eclair/bin"
+
+
+# Set various path variables based on ECLAIR_ANALYSIS var (which is a name
+# of top-level dir to hold internal files and results of anaylisis). We
+# need to support this variability to e.g. support delta reports
+# between two analyses (before and after a patch).
+eclair_set_paths() {
+ if [ -z "${ECLAIR_ANALYSIS}" ]; then
+ echo "ECLAIR_ANALYSIS is not defined"
+ exit 1
+ fi
+
+ # Directory where to put all ECLAIR output and temporary files.
+ ECLAIR_OUTPUT_DIR="${WORKSPACE}/${ECLAIR_ANALYSIS}/out"
+
+ # ECLAIR binary data directory and workspace.
+ export ECLAIR_DATA_DIR="${ECLAIR_OUTPUT_DIR}/.data"
+
+ # Destination file for the ECLAIR diagnostics.
+ export ECLAIR_DIAGNOSTICS_OUTPUT="${ECLAIR_OUTPUT_DIR}/DIAGNOSTICS.txt"
+
+ PROJECT_ECD="${ECLAIR_OUTPUT_DIR}/PROJECT.ecd"
+}
+
+eclair_prepare() {
+ eclair_set_paths
+ mkdir -p "${ECLAIR_DATA_DIR}"
+}
+
+eclair_analyze() {
+ eclair_set_paths
+ (
+ # Run a build in the ECLAIR environment.
+ "${ECLAIR_BIN_DIR}/eclair_env" \
+ "-eval_file='${ECLAIR_CONFIG_DIR}/MISRA_C_2012_selection.ecl'" \
+ -- "$@"
+ )
+}
+
+# Create the project database.
+eclair_make_ecd() {
+ eclair_set_paths
+ find "${ECLAIR_DATA_DIR}" -maxdepth 1 -name "FRAME.*.ecb" \
+ | sort | xargs cat \
+ | "${ECLAIR_BIN_DIR}/eclair_report" \
+ "-create_db='${PROJECT_ECD}'" \
+ -load=/dev/stdin
+}
+
+eclair_make_report_self_contained() {
+ dir=$1
+ mkdir -p $dir/lib
+
+ cp -r /opt/bugseng/eclair/lib/html $dir/lib
+
+ ${_ECLAIR_UTILS_DIR}/relativize_urls.py $dir
+}
+
+eclair_make_reports() {
+ eclair_set_paths
+ ${ECLAIR_BIN_DIR}/eclair_report -db=${PROJECT_ECD} \
+ -summary_txt=${ECLAIR_OUTPUT_DIR}/../summary_txt \
+ -full_txt=${ECLAIR_OUTPUT_DIR}/../full_txt \
+ -reports1_html=strictness,${ECLAIR_OUTPUT_DIR}/../full_html/by_strictness/@TAG@.html \
+ -full_html=${ECLAIR_OUTPUT_DIR}/../full_html
+
+ # summary_txt contains just a single report file not present in full_txt, move it there and be done with it.
+ mv ${ECLAIR_OUTPUT_DIR}/../summary_txt/by_service.txt ${ECLAIR_OUTPUT_DIR}/../full_txt/
+ rm -rf ${ECLAIR_OUTPUT_DIR}/../summary_txt
+
+ eclair_make_report_self_contained ${ECLAIR_OUTPUT_DIR}/../full_html
+}
+
+eclair_compress_db() {
+ eclair_set_paths
+
+ # Compress database to take less disk space in Jenkins archive
+ xz ${PROJECT_ECD}
+}
+
+eclair_make_delta_report() {
+ base_dir=$1
+ target_dir=$2
+
+ diff -I '^Timestamp:' -x frames.txt -x files.txt -x explain.txt \
+ -ur ${WORKSPACE}/${base_dir}/summary_txt/ ${WORKSPACE}/${target_dir}/summary_txt/ > ${WORKSPACE}/${target_dir}/summary_txt.diff || true
+
+ ${ECLAIR_BIN_DIR}/eclair_report -diff_criteria=fingerprint -diff_full_txt=${base_dir}/out/PROJECT.ecd,${target_dir}/out/PROJECT.ecd
+ ls -l diff_output
+
+ ${ECLAIR_BIN_DIR}/eclair_report \
+ -db=${base_dir}/out/PROJECT.ecd \
+ -eval_file=${_ECLAIR_UTILS_DIR}/sel_tag_and_not_glob.ecl \
+ -sel_tag_and_not_glob=new_no_expl,diff,missing,service,B.EXPLAIN \
+ -full_html=resolved_issues_html
+ eclair_make_report_self_contained resolved_issues_html
+
+ ${ECLAIR_BIN_DIR}/eclair_report \
+ -db=${target_dir}/out/PROJECT.ecd \
+ -eval_file=${_ECLAIR_UTILS_DIR}/sel_tag_and_not_glob.ecl \
+ -sel_tag_and_not_glob=new_no_expl,diff,missing,service,B.EXPLAIN \
+ -full_html=new_issues_html
+ eclair_make_report_self_contained new_issues_html
+
+ xz ${base_dir}/out/PROJECT.ecd ${target_dir}/out/PROJECT.ecd
+}