From 3cfab2eb776a3caf6363d8a546d6862eecf5d92a Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 8 Mar 2025 15:14:51 -0800 Subject: [PATCH] Pulled in changes from other version I wrote. +Added refs to flashing +new mocking functions +new menu options. --- otto.sh | 118 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 102 insertions(+), 16 deletions(-) diff --git a/otto.sh b/otto.sh index 465befc..f3c15f9 100755 --- a/otto.sh +++ b/otto.sh @@ -26,7 +26,6 @@ format_source_code () { echo "Applying Formating standard!" } - add_compile_commands () { if [ -f ./compile_commands.json ]; then echo "compile_commands.json already exists!\n" @@ -52,6 +51,16 @@ does_module_exist () { fi } +does_mock_exist () { + local basename="$1" + + if [ -d "mocks/${basename}" ]; then + echo "1" + else + echo "0" + fi +} + add_module_to_cmakes () { local basename="$1" @@ -60,7 +69,7 @@ add_module_to_cmakes () { # Tests cmake file needs to be edited in place. sed -i'' "s/# TEST_DIRS.*$/# TEST_DIRS\r\nadd_subdirectory(${basename})/g" ./tests/CMakeLists.txt - sed -i'' "s/# TEST_LINKS.*$/# TEST_LINKS\r\n\t${basename}/g" ./tests/CMakeLists.txt + sed -i'' "s/# TEST_LINKS.*$/# TEST_LINKS\r\n\ttest_${basename}/g" ./tests/CMakeLists.txt } remove_module_from_cmakes () { @@ -68,7 +77,7 @@ remove_module_from_cmakes () { sed -i'' "s/^.*add_subdirectory(${basename}).*$//g" ./src/CMakeLists.txt sed -i'' "s/^.*add_subdirectory(${basename}).*$//g" ./tests/CMakeLists.txt - sed -i'' "s/^.*${basename}.*$//g" ./tests/CMakeLists.txt + sed -i'' "s/^.*test_${basename}.*$//g" ./tests/CMakeLists.txt } git_add_module () { @@ -116,6 +125,50 @@ git_remove_module () { } +add_mock_module () { + read -p "Enter the name of the module:" modname + result=$(does_mock_exist "$modname") + + if [ "${result}" -eq "1" ]; then + echo "Module already exists!" + echo "Exiting without changing anything" + exit + fi + + modname_cap=$(echo $modname | sed 's/[a-z]/\U&/g') + modsrc_dir="./mocks/${modname}" + modtest_dir="./tests/${modname}" + + echo "creating: ${modsrc_dir}, ${modtest_dir}" + mkdir $modsrc_dir + mkdir $modtest_dir + + #copy the template files. + echo "copying & customizing template files..." + + sed "s/module_name/${modname}/" $MODULE_DIR/module_name.c > $modsrc_dir/${modname}.c + sed -i'' "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.c + + sed "s/module_name/${modname_cap}/" $MODULE_DIR/module_name.h > $modsrc_dir/${modname}.h + sed -i'' "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.h + + sed "s/module_name/${modname}/" $MODULE_DIR/CMakeLists.txt > $modsrc_dir/CMakeLists.txt + + sed "s/module_name/${modname}/" $MODULE_DIR/test_module_name.cpp > $modtest_dir/test_${modname}.cpp + sed "s/module_name/${modname}/" $MODULE_DIR/TestCMakeLists.txt > $modtest_dir/CMakeLists.txt + + # Add the module to the cmake lists files. + add_module_to_cmakes "${modname}" + + echo "Resulting files/dirs:" + tree -L 2 $modsrc_dir + tree -L 2 $modtest_dir + + # Now we add the new files to the git tracked files + git_add_module "${modname}" + +} + add_new_module () { read -p "Enter the name of the module:" modname @@ -176,12 +229,9 @@ cross_compile () { } build_release() { - clear_cmake_cache - CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE}" - CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${WCH_TC}" - - cmake ${CMAKE_ARGS} ../ - make main + clear_cmake_cache + cmake -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../ + make } build_main () { @@ -190,19 +240,50 @@ build_main () { make main } +build_hex () { + clear_cmake_cache + + CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE}" + CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${WCH_TC}" + + cmake ${CMAKE_ARGS} ../ + make all + make hex +} + +build_hex_optimized () { + clear_cmake_cache + + CMAKE_ARGS="-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE}" + CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${WCH_TC}" + + cmake ${CMAKE_ARGS} ../ + make all + make hex-release +} + +flash_microcontroller () { + build_hex_optimized + make upload +} + run_c_tests () { format_source_code clear_cmake_cache cmake -DUNIT_TESTING=ON -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE} ../ - make AllTests && ./tests/AllTests -c -v + make AllTests + make Mock_Tests + ./tests/AllTests -v -c + ./tests/Mock_Tests -v -c } print_menu () { echo "BUILD MENU:" + echo "0. Add Mock Module" echo "1. Run Tests" - echo "2. Build Project" - echo "3. Build for release" - echo "4. cross compile for XXXXXX" + echo "2. Build Project(hex)" + echo "3. Build for release(hex)" + echo "4. Flash to MicroController" echo "5. Add new module to project" echo "6. Delete module from project" echo "7. Exit" @@ -218,6 +299,11 @@ main() { read -p "Enter your choice: " choice case $choice in + 0) + echo "You selected Option 0" + valid_choice=true + add_mock_module + ;; 1) echo "You selected Option 1" valid_choice=true @@ -226,17 +312,17 @@ main() { 2) echo "You selected Option 2" valid_choice=true - build_main + build_hex ;; 3) echo "You selected Option 3" valid_choice=true - build_release + build_hex_optimized ;; 4) echo "You selected Option 4" valid_choice=true - cross_compile + flash_microcontroller ;; 5) echo "You selected Option 5"