Skip to content

Commit

Permalink
add tbd tool baking mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
mjleehh committed Dec 15, 2024
1 parent 8c0aa4f commit 71aa659
Show file tree
Hide file tree
Showing 10 changed files with 407 additions and 0 deletions.
97 changes: 97 additions & 0 deletions tools/resources/bake_tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env bash

# @file merge common helpers and script into a single script without dependencies
#
#
#

set -e

# find script resources directory
if [ -z "$TBD_PROJECT_DIR" ]; then
scripts_srcs_dir="$(realpath -- $(dirname -- ${BASH_SOURCE[0]}))"
else
scripts_srcs_dir="$TBD_PROJECT_DIR/tools/resources"
fi

source "$scripts_srcs_dir/common_header.sh"

# @brief parameter defaults
#
#
tbd_logging_tag="bake_tools"
script_files="$scripts_srcs_dir"/src/*.sh
process_only=false
header_file=$scripts_srcs_dir/common_header.sh

# @brief parse command line options
#
#
parse_args() {
while [ $# -gt 0 ]; do
arg=$1

case $arg in
-o|--out-dir)
out_dir=$2
shift
;;
-p|--process-ony)
process_only=true
;;
*)
break
;;
esac
shift
done

if [ $# -gt 0 ]; then
script_files=$@
fi


if [ -z "$out_dir" ]; then
out_dir=$(dirname -- "$scripts_srcs_dir")/bin
fi
}


parse_args $@

tbd_logi "writing baked script files to $out_dir"

if ! [ -d "$out_dir" ]; then
mkdir -p "$out_dir"
fi

for script_file in $script_files; do
if ! [ -f "$script_file" ]; then
tbd_loge "$script_file: input file not found"
continue
fi

# remove .sh extension from final tool name
out_file=$out_dir/$(basename -- ${script_file%.sh})

num_header_lines=$(awk '/-- END OF HEADER --/{ print NR; exit }' "$script_file")
if [ -z "$num_header_lines" ]; then
if $process_only; then
continue
fi

if cp "$script_file" "$out_file"; then
tbd_logi "$script_file: copied"
else
tbd_loge "$script_file: failed to copy"
fi
else
if cat "$header_file" > "$out_file" \
&& tail -n +$num_header_lines "$script_file" >> $out_file
then
tbd_logi "$script_file: baked"
else
tbd_loge "$script_file: failed to bake"
fi
fi
done
28 changes: 28 additions & 0 deletions tools/resources/helpers.sh → tools/resources/common_header.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/usr/bin/env bash

set -e

#### logging utils ####

c_none="0"
c_black="0;30"
c_red="0;31"
Expand Down Expand Up @@ -55,6 +61,8 @@ tbd_abort() {
exit 1
}

#### script execution utils ####

# @brief run a bash command with output
#
# @arg 1 [enum] display or hide stdout of command (SILENT/VERBOSE)
Expand All @@ -72,6 +80,8 @@ tbd_run() {
fi
}

#### TBD project utils ####

# @brief quick check if the given directory looks like a TBD project root
#
# A tbd, ports and apps folder and CMakeLists.txt file should be present.
Expand Down Expand Up @@ -126,3 +136,21 @@ tbd_project_root() {

return 1
}

tbd_get_platforms() {
local project_dir=$1
if [ -z "$project_dir" ]; then
project_dir=$(tbd_project_root)
fi

if [ -z "$project_dir" ]; then
return 1
fi

for platform_file in "$project_dir"/config/platforms/platform.*.json; do
platform=$(basename -- ${platform_file%.json})
platform=${platform#platform.}
echo $platform
done

}
27 changes: 27 additions & 0 deletions tools/resources/src/gdb-device.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -e

tbd_logging_tag="tbd_gbd_emu"

resource_path=$(dirname -- $(dirname -- ${BASH_SOURCE[0]}))/resources
source "$resource_path/helpers.sh"

project_dir=$(tbd_project_root)
if [ -z "$project_dir" ]; then
tbd_abort "could not find TBD project in path"
fi

if ! which xtensa-esp32s3-elf-gdb; then
tbd_abort "debugger 'xtensa-esp32s3-elf-gdb' not in PATH, please activate ESP IDF using '. <idf-path>/export.sh'"
fi

symbols_file=${project_dir}/build/$1/ctag-tbd.elf
if ! [ -f "$symbols_file" ]; then
tbd_abort "symbols file does not exist, no file ${symbols_file}"
fi

exec xtensa-esp32s3-elf-gdb \
-x "$resource_path/device.gdb" \
"$symbols_file" \
$@
27 changes: 27 additions & 0 deletions tools/resources/src/gdb-emu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -e

tbd_logging_tag="tbd_gbd_emu"

resource_path=$(dirname -- $(dirname -- ${BASH_SOURCE[0]}))/resources
source "$resource_path/helpers.sh"

project_dir=$(tbd_project_root)
if [ -z "$project_dir" ]; then
tbd_abort "could not find TBD project in path"
fi

if ! which xtensa-esp32s3-elf-gdb; then
tbd_abort "debugger 'xtensa-esp32s3-elf-gdb' not in PATH, please activate ESP IDF using '. <idf-path>/export.sh'"
fi

symbols_file=$project_dir/build/emu/ctag-tbd.elf
if ! [ -f "$symbols_file" ]; then
tbd_abort "symbols file does not exist, no file ${symbols_file}"
fi

exec xtensa-esp32s3-elf-gdb \
-x "$resource_path/emu.gdb" \
"$symbols_file" \
$@
69 changes: 69 additions & 0 deletions tools/resources/src/tbb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

resource_path=$(dirname -- $(dirname -- ${BASH_SOURCE[0]}))
source "$resource_path/common_header.sh"

# -- END OF HEADER --

tbd_logging_tag="tbd build"

project_dir=$(tbd_project_root)
if [ -z "$project_dir" ]; then
tbd_abort "could not find TBD project in path"
fi

cmake_args=

# @brief parse command line options
#
# All options unknown to tbb are passed on to CMake
#
parse_args() {
while [ $# -gt 0 ]; do
arg=$1
case $arg in
--refresh)
refresh=true
;;
--silent)
tbd_cmd_verbosity="SILENT"
;;
*)
break
;;
esac
shift
done

if [ $# -lt 1 ]; then
tbd_abort "no platform specified"
fi
platform=$1
shift

cmake_args=$@
}

parse_args $@
tbd_get_platforms "$project_dir"



# if [ -z "$ESP_IDF_VERSION" ] && [ $TBD_IN_CONTAINER -eq 1 ]; then
# source "$TBD_IDF_ACTIVATE"
# fi

# if [ -z "$TBD_PROJECT_DIR" ]; then
# TBD_TOOL_MAIN="$(dirname -- $(dirname -- ${BASH_SOURCE[0]}))/tbdtools/__main__.py"
# else
# cd "$TBD_PROJECT_DIR"
# TBD_TOOL_MAIN="$TBD_PROJECT_DIR/tools/tbdtools/__main__.py"
# fi

# export

# export LOGURU_LEVEL=DEBUG
# platform="$1"
# shift

# exec python "$TBD_TOOL_MAIN" -p "${platform}" firmware $@
5 changes: 5 additions & 0 deletions tools/resources/src/tbd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

TBD_TOOL_MAIN="$(dirname -- $(dirname -- ${BASH_SOURCE[0]}))/tbdtools/__main__.py"
export LOGURU_LEVEL=WARNING
exec python "$TBD_TOOL_MAIN" $@
23 changes: 23 additions & 0 deletions tools/resources/src/tbd_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

if [ -z "$ESP_IDF_VERSION" ] || [ -z "$IDF_PYTHON_ENV_PATH" ]; then
echo "no esp idf python env seems to be active, make sure to source export.sh from idf dir before running this script"
exit 1
fi

if ! echo pip install \
sphinx \
pydata-sphinx-theme \
sphinxcontrib-youtube \
breathe \
typer \
cxxheaderparser \
jinja2 \
GitPython \
loguru \
pyhumps \
pydantic \
pyyaml
then
echo "an error occurred during installation of TBD python dependencies"
fi
Loading

0 comments on commit 71aa659

Please sign in to comment.