| 1 | #!/bin/bash |
| 2 | # Stop immediately if any executed command has exit status different from 0. |
| 3 | set -e |
| 4 | set -o pipefail |
| 5 | |
| 6 | script_name="$(basename "$0")" |
| 7 | |
| 8 | fatal() { |
| 9 | echo "${script_name}: $*" >&2 |
| 10 | exit 1 |
| 11 | } |
| 12 | |
| 13 | usage() { |
| 14 | fatal "Usage: ${script_name} <ARM64|X86_64> <accepted|monitored>" |
| 15 | } |
| 16 | |
| 17 | if [[ $# -ne 2 ]]; then |
| 18 | usage |
| 19 | fi |
| 20 | |
| 21 | # Absolute path of the ECLAIR bin directory. |
| 22 | export ECLAIR_BIN_DIR=/opt/bugseng/eclair/bin/ |
| 23 | |
| 24 | # Directory where this script resides: usually in a directory named "ECLAIR". |
| 25 | SCRIPT_DIR="$( |
| 26 | cd "$(dirname "$0")" |
| 27 | echo "${PWD}" |
| 28 | )" |
| 29 | # Directory where to put all ECLAIR output and temporary files. |
| 30 | if [[ -z "${ECLAIR_OUTPUT_DIR:-}" ]]; then |
| 31 | ECLAIR_OUTPUT_DIR="${PWD}/ECLAIR/out" |
| 32 | fi |
| 33 | |
| 34 | export ECLAIR_DIAGNOSTICS_OUTPUT="${ECLAIR_OUTPUT_DIR}/ANALYSIS.log" |
| 35 | # Set the variable for the build log file. |
| 36 | ECLAIR_BUILD_LOG=${ECLAIR_OUTPUT_DIR}/BUILD.log |
| 37 | # Set the variable for the report log file. |
| 38 | ECLAIR_REPORT_LOG=${ECLAIR_OUTPUT_DIR}/REPORT.log |
| 39 | |
| 40 | if [[ "$1" = "X86_64" ]]; then |
| 41 | export CROSS_COMPILE= |
| 42 | export XEN_TARGET_ARCH=x86_64 |
| 43 | elif [[ "$1" = "ARM64" ]]; then |
| 44 | export CROSS_COMPILE=aarch64-linux-gnu- |
| 45 | export XEN_TARGET_ARCH=arm64 |
| 46 | else |
| 47 | fatal "Unknown configuration: $1" |
| 48 | fi |
| 49 | |
| 50 | VARIANT="${XEN_TARGET_ARCH}" |
| 51 | |
| 52 | # Used in analysis.ecl |
| 53 | case "$2" in |
| 54 | accepted|monitored) |
| 55 | export SET="$2" |
| 56 | ;; |
| 57 | *) |
| 58 | fatal "Unknown configuration: $2" |
| 59 | ;; |
| 60 | esac |
| 61 | |
| 62 | export CC_ALIASES="${CROSS_COMPILE}gcc-12" |
| 63 | export CXX_ALIASES="${CROSS_COMPILE}g++-12" |
| 64 | export LD_ALIASES="${CROSS_COMPILE}ld" |
| 65 | export AR_ALIASES="${CROSS_COMPILE}ar" |
| 66 | export AS_ALIASES="${CROSS_COMPILE}as" |
| 67 | export FILEMANIP_ALIASES="cp mv ${CROSS_COMPILE}objcopy" |
| 68 | |
| 69 | # ECLAIR binary data directory and workspace. |
| 70 | export ECLAIR_DATA_DIR="${ECLAIR_OUTPUT_DIR}/.data" |
| 71 | # ECLAIR workspace. |
| 72 | export ECLAIR_WORKSPACE="${ECLAIR_DATA_DIR}/eclair_workspace" |
| 73 | |
| 74 | # Identifies the particular build of the project. |
| 75 | export ECLAIR_PROJECT_NAME="XEN_${VARIANT}-${SET}" |
| 76 | |
| 77 | # Erase and recreate the output directory and the data directory. |
| 78 | rm -rf "${ECLAIR_OUTPUT_DIR:?}/*" |
| 79 | mkdir -p "${ECLAIR_DATA_DIR}" |
| 80 | |
| 81 | # Perform the build (from scratch) in an ECLAIR environment. |
| 82 | "${ECLAIR_BIN_DIR}eclair_env" \ |
| 83 | "-config_file='${SCRIPT_DIR}/analysis.ecl'" \ |
| 84 | "${EXTRA_ECLAIR_ENV_OPTIONS}" \ |
| 85 | -- "${SCRIPT_DIR}/../build.sh" "$1" | tee "${ECLAIR_BUILD_LOG}" |
| 86 | |
| 87 | |
| 88 | # Create the project database. |
| 89 | PROJECT_ECD="${ECLAIR_OUTPUT_DIR}/PROJECT.ecd" |
| 90 | find "${ECLAIR_DATA_DIR}" -maxdepth 1 -name "FRAME.*.ecb" | |
| 91 | sort | xargs cat | |
| 92 | "${ECLAIR_BIN_DIR}eclair_report" \ |
| 93 | "-create_db='${PROJECT_ECD}'" \ |
| 94 | -quiet \ |
| 95 | -load=/dev/stdin > "${ECLAIR_REPORT_LOG}" 2>&1 |
| 96 | |
| 97 | # Create the Jenkins reports file. |
| 98 | "${ECLAIR_BIN_DIR}eclair_report" \ |
| 99 | "-db='${PROJECT_ECD}'" \ |
| 100 | -quiet \ |
| 101 | "-eval_file='${SCRIPT_DIR}/report.ecl'" \ |
| 102 | >> "${ECLAIR_REPORT_LOG}" 2>&1 |
| 103 | |
| 104 | "${SCRIPT_DIR}/print_analyzed_files.sh" "${PROJECT_ECD}" "${ECLAIR_OUTPUT_DIR}" |