Paul Sokolovsky | 3486b4e | 2022-09-06 13:33:57 +0300 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2021-2022 BUGSENG srl. All rights reserved. |
| 4 | # Copyright (c) 2022 Arm Limited. All rights reserved. |
| 5 | # |
| 6 | # SPDX-License-Identifier: BSD-3-Clause |
| 7 | |
| 8 | # Stop immediately if any executed command has exit status different from 0. |
| 9 | set -ex |
| 10 | |
| 11 | usage() { |
| 12 | echo "Usage: analyze.sh CONF" 1>&2 |
| 13 | echo " where CONF is the build configuration id passed to build.sh" 1>&2 |
| 14 | } |
| 15 | |
| 16 | if [ $# -ne 1 ] |
| 17 | then |
| 18 | usage |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
Paul Sokolovsky | 4c85901 | 2022-10-08 14:50:34 +0300 | [diff] [blame] | 22 | TF_CONFIG="$1" |
Paul Sokolovsky | 3486b4e | 2022-09-06 13:33:57 +0300 | [diff] [blame] | 23 | |
Paul Sokolovsky | 4c85901 | 2022-10-08 14:50:34 +0300 | [diff] [blame] | 24 | # Directory where this script resides. |
Paul Sokolovsky | 3486b4e | 2022-09-06 13:33:57 +0300 | [diff] [blame] | 25 | SCRIPT_DIR="$(cd "$(dirname "$0")" ; echo "${PWD}")" |
| 26 | |
Paul Sokolovsky | 4c85901 | 2022-10-08 14:50:34 +0300 | [diff] [blame] | 27 | . ${SCRIPT_DIR}/analyze_common.sh |
Paul Sokolovsky | 3486b4e | 2022-09-06 13:33:57 +0300 | [diff] [blame] | 28 | |
| 29 | function do_analyze() { |
| 30 | |
| 31 | # ECLAIR binary data directory and workspace. |
| 32 | export ECLAIR_DATA_DIR="${ECLAIR_OUTPUT_DIR}/.data" |
| 33 | # ECLAIR workspace. |
| 34 | export ECLAIR_WORKSPACE="${ECLAIR_DATA_DIR}/eclair_workspace" |
| 35 | # Destination file for the ECLAIR diagnostics. |
| 36 | export ECLAIR_DIAGNOSTICS_OUTPUT="${ECLAIR_OUTPUT_DIR}/DIAGNOSTICS.txt" |
| 37 | |
| 38 | # Erase and recreate the output directory and the data directory. |
| 39 | rm -rf "${ECLAIR_OUTPUT_DIR}" |
| 40 | mkdir -p "${ECLAIR_DATA_DIR}" |
| 41 | |
| 42 | ( |
| 43 | # Perform the build (from scratch) in an ECLAIR environment. |
| 44 | "${ECLAIR_BIN_DIR}/eclair_env" \ |
| 45 | "-eval_file='${SCRIPT_DIR}/MISRA_C_2012_selection.ecl'" \ |
Paul Sokolovsky | 4c85901 | 2022-10-08 14:50:34 +0300 | [diff] [blame] | 46 | -- "${SCRIPT_DIR}/build-tfa.sh" "${TF_CONFIG}" |
Paul Sokolovsky | 3486b4e | 2022-09-06 13:33:57 +0300 | [diff] [blame] | 47 | ) |
| 48 | |
| 49 | # Create the project database. |
| 50 | PROJECT_ECD="${ECLAIR_OUTPUT_DIR}/PROJECT.ecd" |
| 51 | find "${ECLAIR_DATA_DIR}" -maxdepth 1 -name "FRAME.*.ecb" \ |
| 52 | | sort | xargs cat \ |
| 53 | | "${ECLAIR_BIN_DIR}/eclair_report" \ |
| 54 | "-create_db='${PROJECT_ECD}'" \ |
| 55 | -load=/dev/stdin |
| 56 | |
| 57 | |
| 58 | function make_self_contained() { |
| 59 | dir=$1 |
| 60 | mkdir -p $dir/lib |
| 61 | |
| 62 | cp -r /opt/bugseng/eclair-3.12.0/lib/html $dir/lib |
| 63 | |
| 64 | ${SCRIPT_DIR}/relativize_urls.py $dir |
| 65 | } |
| 66 | |
| 67 | ${ECLAIR_BIN_DIR}/eclair_report -db=${PROJECT_ECD} \ |
| 68 | -summary_txt=${ECLAIR_OUTPUT_DIR}/../summary_txt \ |
| 69 | -full_txt=${ECLAIR_OUTPUT_DIR}/../full_txt \ |
| 70 | -full_html=${ECLAIR_OUTPUT_DIR}/../full_html |
| 71 | |
| 72 | # summary_txt contains just a single report file not present in full_txt, move it there and be done with it. |
| 73 | mv ${ECLAIR_OUTPUT_DIR}/../summary_txt/by_service.txt ${ECLAIR_OUTPUT_DIR}/../full_txt/ |
| 74 | rm -rf ${ECLAIR_OUTPUT_DIR}/../summary_txt |
| 75 | make_self_contained ${ECLAIR_OUTPUT_DIR}/../full_html |
| 76 | |
| 77 | # Create the Jenkins reports file. |
| 78 | JENKINS_XML="${ECLAIR_OUTPUT_DIR}/../jenkins.xml" |
| 79 | ${ECLAIR_BIN_DIR}/eclair_report -db=${PROJECT_ECD} -reports_jenkins=${JENKINS_XML} |
| 80 | |
| 81 | } |
| 82 | |
| 83 | # Directory where to put all ECLAIR output and temporary files. |
| 84 | ECLAIR_OUTPUT_DIR="${WORKSPACE}/ECLAIR/out" |
| 85 | |
| 86 | do_analyze |
| 87 | |
| 88 | ECLAIR_OUTPUT_DIR="${WORKSPACE}/ECLAIR_BASE/out" |
| 89 | |
| 90 | ( |
| 91 | cd ${ECLAIR_PROJECT_ROOT} |
| 92 | git checkout HEAD^ |
| 93 | git log --oneline -n5 |
| 94 | ) |
| 95 | |
| 96 | do_analyze |
| 97 | |
| 98 | diff -I '^Timestamp:' -x frames.txt -x files.txt -x explain.txt \ |
| 99 | -ur ${WORKSPACE}/ECLAIR_BASE/summary_txt/ ${WORKSPACE}/ECLAIR/summary_txt/ > ${WORKSPACE}/ECLAIR/summary_txt.diff || true |
| 100 | |
| 101 | |
| 102 | ( |
| 103 | ${ECLAIR_BIN_DIR}/eclair_report -diff_criteria=fingerprint -diff_full_txt=ECLAIR_BASE/out/PROJECT.ecd,ECLAIR/out/PROJECT.ecd |
| 104 | ls -l diff_output |
| 105 | |
| 106 | eclair_report -db=ECLAIR_BASE/out/PROJECT.ecd -sel_tag_glob=new,diff,missing -full_html=resolved_issues_html |
| 107 | make_self_contained resolved_issues_html |
| 108 | |
| 109 | eclair_report -db=ECLAIR/out/PROJECT.ecd -sel_tag_glob=new,diff,missing -full_html=new_issues_html |
| 110 | make_self_contained new_issues_html |
| 111 | |
| 112 | xz ECLAIR_BASE/out/PROJECT.ecd ECLAIR/out/PROJECT.ecd |
| 113 | ) |
| 114 | |
| 115 | ${SCRIPT_DIR}/eclair_diff_report.py diff_output > misra_delta.txt |
| 116 | |
| 117 | |
| 118 | cat <<EOF >index.html |
| 119 | <html> |
| 120 | <body> |
| 121 | <h1>MISRA Delta reports for the patch</h1> |
Paul Sokolovsky | a1be51a | 2022-09-29 18:37:15 +0300 | [diff] [blame] | 122 | |
| 123 | <p> |
| 124 | Patch: <a href="${GERRIT_CHANGE_URL}/${GERRIT_PATCHSET_NUMBER}">${GERRIT_CHANGE_URL}/${GERRIT_PATCHSET_NUMBER}</a><br /> |
| 125 | CI Build: <a href="${BUILD_URL}">${BUILD_URL}</a> |
| 126 | </p> |
| 127 | |
Paul Sokolovsky | 3486b4e | 2022-09-06 13:33:57 +0300 | [diff] [blame] | 128 | <li><a href="misra_delta.txt">Cumulative TXT report</a> |
| 129 | <li><a href="diff_output/">Per MISRA rule TXT reports</a> |
| 130 | <li><a href="new_issues_html/by_service.html#first_file/service&kind">New issues, groupped per file changed (HTML).</a> |
| 131 | <li><a href="resolved_issues_html/by_service.html#first_file/service&kind">Resolved issues, groupped per file changed (HTML).</a> |
| 132 | </body> |
| 133 | </html> |
| 134 | EOF |