2021-11-15 16:41:12 +08:00
|
|
|
# Copyright 2018 Oticon A/S
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2023-03-20 18:08:34 +08:00
|
|
|
source ${ZEPHYR_BASE}/tests/bsim/sh_common.source
|
2023-03-09 20:23:56 +08:00
|
|
|
|
2024-03-21 22:07:17 +08:00
|
|
|
: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}"
|
|
|
|
|
|
|
|
WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}"
|
|
|
|
|
2023-01-24 18:41:00 +08:00
|
|
|
function print_error_info(){
|
|
|
|
echo -e "\033[0;31mFailure building ${app} ${conf_file} for ${BOARD}\033[0m\n\
|
|
|
|
You can rebuild it with\n\
|
2024-01-25 17:59:37 +08:00
|
|
|
"${cmake_cmd[@]@Q}" && ninja ${ninja_args}"
|
2023-01-24 18:41:00 +08:00
|
|
|
}
|
|
|
|
|
2023-03-09 20:23:56 +08:00
|
|
|
function _compile(){
|
2021-11-15 16:41:12 +08:00
|
|
|
: "${app:?app must be defined}"
|
|
|
|
|
|
|
|
local app_root="${app_root:-${ZEPHYR_BASE}}"
|
2023-10-26 20:02:17 +08:00
|
|
|
local BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}"
|
2021-11-15 16:41:12 +08:00
|
|
|
local conf_file="${conf_file:-prj.conf}"
|
2024-04-16 20:31:14 +08:00
|
|
|
local extra_conf_file="${extra_conf_file:-""}"
|
2021-11-15 16:41:12 +08:00
|
|
|
local conf_overlay="${conf_overlay:-""}"
|
|
|
|
|
2024-01-25 17:59:37 +08:00
|
|
|
default_cmake_args=(-DCONFIG_COVERAGE=y -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
2024-05-24 14:16:47 +08:00
|
|
|
-DCONFIG_COMPILER_WARNINGS_AS_ERRORS=y -DCONFIG_ASSERT=y)
|
2024-01-25 17:59:37 +08:00
|
|
|
local cmake_args=(${cmake_args:-"${default_cmake_args[@]}"})
|
2023-11-24 20:44:56 +08:00
|
|
|
local cmake_extra_args="${cmake_extra_args:-""}"
|
2021-11-15 16:41:12 +08:00
|
|
|
local ninja_args="${ninja_args:-""}"
|
2024-01-25 17:59:37 +08:00
|
|
|
local cc_flags="${cc_flags:-""}"
|
2021-11-15 16:41:12 +08:00
|
|
|
|
2023-01-20 17:53:43 +08:00
|
|
|
if [ "${conf_overlay}" ]; then
|
2024-04-16 20:31:14 +08:00
|
|
|
overlay_basename="${conf_overlay##*/}"
|
|
|
|
overlay_file="${overlay_basename//;/_}"
|
|
|
|
local exe_basename="${exe_name:-bs_${BOARD}_${app}_${conf_file}_${overlay_file}}"
|
2023-01-20 17:53:43 +08:00
|
|
|
else
|
2023-03-21 18:52:24 +08:00
|
|
|
local exe_basename="${exe_name:-bs_${BOARD}_${app}_${conf_file}}"
|
2023-01-20 17:53:43 +08:00
|
|
|
fi
|
|
|
|
|
2023-03-21 18:52:24 +08:00
|
|
|
local exe_basename=$(echo ${exe_basename} | tr \"/\\.\; _ )
|
|
|
|
local exe_name=${BSIM_OUT_PATH}/bin/$exe_basename
|
2021-11-15 16:41:12 +08:00
|
|
|
local map_file_name=${exe_name}.Tsymbols
|
|
|
|
|
2023-03-21 18:52:24 +08:00
|
|
|
local this_dir=${WORK_DIR}/${app}/${exe_basename}
|
2021-11-15 16:41:12 +08:00
|
|
|
|
2022-09-19 22:44:50 +08:00
|
|
|
local modules_arg="${ZEPHYR_MODULES:+-DZEPHYR_MODULES=${ZEPHYR_MODULES}}"
|
|
|
|
|
2021-11-15 16:41:12 +08:00
|
|
|
echo "Building $exe_name"
|
|
|
|
|
2022-09-19 22:44:50 +08:00
|
|
|
local ret=0
|
|
|
|
|
2023-03-21 19:12:22 +08:00
|
|
|
local cmake_cmd=(cmake -GNinja -DBOARD_ROOT=${BOARD_ROOT} -DBOARD=${BOARD})
|
|
|
|
if [ $conf_file != "prj.conf" ]; then
|
|
|
|
local cmake_cmd+=( -DCONF_FILE=${conf_file})
|
|
|
|
fi
|
2024-01-25 17:59:37 +08:00
|
|
|
orifs="$IFS"; IFS=
|
2023-07-20 22:51:03 +08:00
|
|
|
local cmake_cmd+=( -DOVERLAY_CONFIG="${conf_overlay}" \
|
2024-04-16 20:31:14 +08:00
|
|
|
-DEXTRA_CONF_FILE="${extra_conf_file}" \
|
2023-01-24 18:41:00 +08:00
|
|
|
${modules_arg} \
|
2024-01-25 17:59:37 +08:00
|
|
|
"${cmake_args[@]}" ${cc_flags:+-DCMAKE_C_FLAGS=${cc_flags}} ${cmake_extra_args})
|
2023-10-26 20:02:17 +08:00
|
|
|
if [ -v sysbuild ]; then
|
|
|
|
local cmake_cmd+=( -DAPP_DIR=${app_root}/${app} ${ZEPHYR_BASE}/share/sysbuild/)
|
|
|
|
else
|
|
|
|
local cmake_cmd+=( ${app_root}/${app})
|
|
|
|
fi
|
2024-01-25 17:59:37 +08:00
|
|
|
IFS="$orifs"
|
2023-01-24 18:41:00 +08:00
|
|
|
|
2021-11-15 16:41:12 +08:00
|
|
|
# Set INCR_BUILD when calling to only do an incremental build
|
|
|
|
if [ ! -v INCR_BUILD ] || [ ! -d "${this_dir}" ]; then
|
2024-01-25 17:59:37 +08:00
|
|
|
[ -d "${this_dir}" ] && rm "${this_dir}" -rf
|
|
|
|
mkdir -p "${this_dir}" && cd "${this_dir}"
|
|
|
|
"${cmake_cmd[@]}" &> cmake.out || \
|
2023-01-24 18:41:00 +08:00
|
|
|
{ ret="$?"; print_error_info ; cat cmake.out && return $ret; }
|
2021-11-15 16:41:12 +08:00
|
|
|
else
|
2024-01-25 17:59:37 +08:00
|
|
|
cd "${this_dir}"
|
2021-11-15 16:41:12 +08:00
|
|
|
fi
|
2023-01-24 18:41:00 +08:00
|
|
|
ninja ${ninja_args} &> ninja.out || \
|
|
|
|
{ ret="$?"; print_error_info ; cat ninja.out && return $ret; }
|
2021-11-15 16:41:12 +08:00
|
|
|
cp ${this_dir}/zephyr/zephyr.exe ${exe_name}
|
|
|
|
|
|
|
|
nm ${exe_name} | grep -v " [U|w] " | sort | cut -d" " -f1,3 > ${map_file_name}
|
|
|
|
sed -i "1i $(wc -l ${map_file_name} | cut -d" " -f1)" ${map_file_name}
|
|
|
|
}
|
2023-03-09 20:23:56 +08:00
|
|
|
|
|
|
|
function compile(){
|
|
|
|
run_in_background _compile
|
|
|
|
}
|