From ca3985cff5e4808decdf336f1e4b0b66ab2d8b81 Mon Sep 17 00:00:00 2001 From: Mason Tran Date: Wed, 10 Jul 2024 16:30:53 -0400 Subject: [PATCH] [script] misc. script improvements --- script/build | 42 +++++++++++++++++--------------- script/build_example_apps | 6 ----- script/efr32-definitions | 50 +++++++++++++++++++++++---------------- script/generate | 1 + 4 files changed, 54 insertions(+), 45 deletions(-) diff --git a/script/build b/script/build index 5a54c605..475fc356 100755 --- a/script/build +++ b/script/build @@ -38,12 +38,31 @@ fi script_dir="$(realpath "$(dirname "${script_path}")")" repo_dir="$(dirname "${script_dir}")" +# CMake Build targets +OT_CMAKE_NINJA_TARGET=${OT_CMAKE_NINJA_TARGET-} +# CMake Build options +OT_OPTIONS=( + "-DCMAKE_BUILD_TYPE=Release" + "-DOT_DIAGNOSTIC=ON" + "-DOT_EXTERNAL_HEAP=ON" + "-DOT_SLAAC=ON" +) + +# Check if ccache is installed and use it if available +if command -v ccache >/dev/null; then + OT_OPTIONS+=("-DCMAKE_C_COMPILER_LAUNCHER=ccache") + OT_OPTIONS+=("-DCMAKE_CXX_COMPILER_LAUNCHER=ccache") +fi +readonly OT_OPTIONS # ============================================================================== # shellcheck source=script/efr32-definitions source "${repo_dir}/script/efr32-definitions" +# shellcheck source=script/slc_cli +source "${repo_dir}/script/slc_cli" + # shellcheck source=script/util source "${repo_dir}/script/util" @@ -52,7 +71,6 @@ set -euxo pipefail # ============================================================================== # Pre-build checks # ============================================================================== - init_silabs_sdk_lfs() { set +x @@ -126,22 +144,8 @@ init_silabs_sdk() } # ============================================================================== -OT_CMAKE_NINJA_TARGET=${OT_CMAKE_NINJA_TARGET-} - -OT_OPTIONS=( - "-DCMAKE_BUILD_TYPE=Release" - "-DOT_DIAGNOSTIC=ON" - "-DOT_EXTERNAL_HEAP=ON" - "-DOT_SLAAC=ON" -) - -# Check if ccache is installed and use it if available -if command -v ccache >/dev/null; then - OT_OPTIONS+=("-DCMAKE_C_COMPILER_LAUNCHER=ccache") - OT_OPTIONS+=("-DCMAKE_CXX_COMPILER_LAUNCHER=ccache") -fi -readonly OT_OPTIONS - +# Build functions +# ============================================================================== generate() { if [ "${skip_generation}" = true ]; then @@ -279,6 +283,7 @@ build_soc() cd "${repo_dir}" } +# ============================================================================== main() { local usage="usage: $0 [-h] [--skip-silabs-apps] [-D -D]" @@ -379,7 +384,7 @@ main() fi # Build silabs apps - if [ "${skip_silabs_apps}" = false ]; then + if [ -z ${OT_CMAKE_NINJA_TARGET+x} ] && [ "${skip_silabs_apps}" = false ]; then local before_flags=() local after_flags=() @@ -388,7 +393,6 @@ main() fi "${repo_dir}"/script/build_example_apps "${before_flags[@]-}" "${board}" "${after_flags[@]-}" "$@" - fi ls -alh "${OT_CMAKE_BUILD_DIR}"/openthread/*/bin/* diff --git a/script/build_example_apps b/script/build_example_apps index d8d1a56c..7f5ac146 100755 --- a/script/build_example_apps +++ b/script/build_example_apps @@ -44,9 +44,6 @@ repo_dir="$(dirname "${script_dir}")" # shellcheck source=script/efr32-definitions source "${repo_dir}/script/efr32-definitions" -# shellcheck source=script/slc_cli -source "${repo_dir}/script/slc_cli" - # shellcheck source=script/util source "${repo_dir}/script/util" @@ -246,9 +243,6 @@ main() options+=("-DCMAKE_TOOLCHAIN_FILE=src/${platform}/arm-none-eabi.cmake") - # Find slc-cli installation - slc_init - options+=("$@") export OT_CMAKE_BUILD_DIR="$repo_dir/build/${board}" slc_generated_projects_dir="${OT_CMAKE_BUILD_DIR}"/slc diff --git a/script/efr32-definitions b/script/efr32-definitions index f582467d..263f2528 100755 --- a/script/efr32-definitions +++ b/script/efr32-definitions @@ -29,6 +29,7 @@ # ============================================================================== # Bash definitions +# ============================================================================== if [[ -n ${BASH_SOURCE[0]} ]]; then script_path="${BASH_SOURCE[0]}" @@ -42,18 +43,21 @@ if [ -z ${repo_dir+x} ]; then repo_dir="$(dirname "${script_dir}")" fi -efr32_device_regex="" -efr32_device_regex+="\(efr32\)*" # Group 1 - efr32 (optional) -efr32_device_regex+="\([[:alpha:]]\{2\}\)" # Group 2 - mg, bg, xg (product line) -efr32_device_regex+="\(m*\)" # Group 3 - m (optional, modules only) -efr32_device_regex+="\([[:digit:]]\{1,2\}\)[[:digit:]]\{0,1\}" # Group 4 - 1, 12, 13, 21, 24, 210, 240 etc (series and configuration) -efr32_device_regex+="\([[:alpha:]]\{1\}\)" # Group 5 - a, b, c, p, v (revision) -efr32_device_regex+="\([[:alpha:]]\{0,1\}[[:digit:]]\{1,3\}\)" # Group 6 - xxx, a32, 032 -efr32_device_regex+="\(f[[:digit:]]\{1,\}\)*" # Group 7 - fXXX (flash size) -efr32_device_regex+="\([[:alpha:]]\{2,3\}\)*" # Group 8 - im, gl, gm, jia, vna, etc -efr32_device_regex+="\(f[[:digit:]]\{1,\}\)*" # Group 9 - 32, 40, 48, 68, 125 -efr32_device_regex+=".*" # Rest of line -readonly efr32_device_regex +# Define the regex for efr32 devices if not already defined +if [ -z ${efr32_device_regex+x} ]; then + efr32_device_regex="" + efr32_device_regex+="\(efr32\)*" # Group 1 - efr32 (optional) + efr32_device_regex+="\([[:alpha:]]\{2\}\)" # Group 2 - mg, bg, xg (product line) + efr32_device_regex+="\(m*\)" # Group 3 - m (optional, modules only) + efr32_device_regex+="\([[:digit:]]\{1,2\}\)[[:digit:]]\{0,1\}" # Group 4 - 1, 12, 13, 21, 24, 210, 240 etc (series and configuration) + efr32_device_regex+="\([[:alpha:]]\{1\}\)" # Group 5 - a, b, c, p, v (revision) + efr32_device_regex+="\([[:alpha:]]\{0,1\}[[:digit:]]\{1,3\}\)" # Group 6 - xxx, a32, 032 + efr32_device_regex+="\(f[[:digit:]]\{1,\}\)*" # Group 7 - fXXX (flash size) + efr32_device_regex+="\([[:alpha:]]\{2,3\}\)*" # Group 8 - im, gl, gm, jia, vna, etc + efr32_device_regex+="\(f[[:digit:]]\{1,\}\)*" # Group 9 - 32, 40, 48, 68, 125 + efr32_device_regex+=".*" # Rest of line + readonly efr32_device_regex +fi # ============================================================================== # SDKs @@ -71,10 +75,10 @@ efr32_get_board_slcc() local -r \ doc="Gets the latest revision .slcc file for a efr32 board" # - # Arg $1 -- efr32 board - # Arg $2 -- SDK directory (optional) + # Arg $1 -- efr32 board (optional) (default: $board) + # Arg $2 -- SDK directory (optional) (default: $sdk_dir) if [ $# -lt 1 ] || [ -z "$1" ]; then - printf "%s\n\nUsage:\n\t%s \n" "${doc}" "${FUNCNAME[0]}" >&2 + printf "%s\n\nUsage:\n\t%s [efr32_board] \n" "${doc}" "${FUNCNAME[0]}" >&2 return 1 fi @@ -97,8 +101,8 @@ efr32_get_platform() local -r \ doc="Gets the platform for a efr32 board" # - # Arg $1 -- efr32 board (optional) - # Arg $2 -- SDK directory (optional) + # Arg $1 -- efr32 board (optional) (default: $board) + # Arg $2 -- SDK directory (optional) (default: $sdk_dir) if [ $# -gt 2 ]; then printf "%s\n\nUsage:\n\t%s \n" "${doc}" "${FUNCNAME[0]}" >&2 return 1 @@ -125,16 +129,21 @@ efr32_get_platform() efr32_get_platforms() { - # TODO: local platform_dir="$repo_dir/src" \ && find "$platform_dir" -type d -name '*efr32*' -exec basename {} \; | sort } efr32_check_platform() { - # Checks if a value is a valid efr32 platform + local -r \ + doc="Checks if a value is a valid efr32 platform" # - # Arg $1 -- value + # Arg $1 -- platform + if [ $# -ne 1 ]; then + printf "%s\n\nUsage:\n\t%s \n" "${doc}" "${FUNCNAME[0]}" >&2 + return 1 + fi + local match=false local platform="${1?}" @@ -145,6 +154,7 @@ efr32_check_platform() fi done + # if no match, print error message if ! $match; then set +x printf "\n\nERROR: Unsupported platform\n" >&2 diff --git a/script/generate b/script/generate index 2570b958..ce3a8bf0 100755 --- a/script/generate +++ b/script/generate @@ -217,6 +217,7 @@ generate() run_slc -v 1 generate \ -data "${openthread_slc_data?}" \ + --cache-home "${build_dir}/slc/slcc_components.cache" \ --sdk="${sdk_dir?}" \ --clear-cache \ --project-file="${slcp}" \