Skip to content

Commit

Permalink
[script] misc. script improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lmnotran committed Jul 22, 2024
1 parent 0efeba9 commit ca3985c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 45 deletions.
42 changes: 23 additions & 19 deletions script/build
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -52,7 +71,6 @@ set -euxo pipefail
# ==============================================================================
# Pre-build checks
# ==============================================================================

init_silabs_sdk_lfs()
{
set +x
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -279,6 +283,7 @@ build_soc()
cd "${repo_dir}"
}

# ==============================================================================
main()
{
local usage="usage: $0 [-h] [--skip-silabs-apps] <brdXXXXy> [-D<OT_XXXX=ON> -D<OT_YYYY=OFF>]"
Expand Down Expand Up @@ -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=()

Expand All @@ -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/*
Expand Down
6 changes: 0 additions & 6 deletions script/build_example_apps
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
50 changes: 30 additions & 20 deletions script/efr32-definitions
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

# ==============================================================================
# Bash definitions
# ==============================================================================

if [[ -n ${BASH_SOURCE[0]} ]]; then
script_path="${BASH_SOURCE[0]}"
Expand All @@ -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
Expand All @@ -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 <efr32_board> \n" "${doc}" "${FUNCNAME[0]}" >&2
printf "%s\n\nUsage:\n\t%s [efr32_board] \n" "${doc}" "${FUNCNAME[0]}" >&2
return 1
fi

Expand All @@ -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 <efr32_board> \n" "${doc}" "${FUNCNAME[0]}" >&2
return 1
Expand All @@ -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 <platform> \n" "${doc}" "${FUNCNAME[0]}" >&2
return 1
fi

local match=false
local platform="${1?}"

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions script/generate
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down

0 comments on commit ca3985c

Please sign in to comment.