From 8c03b886c4d4b9bcfb1cb30b3704b8af561c2f45 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 1 Oct 2023 06:33:43 +0100 Subject: Greatly simplify error handling in shell scripts Instead of having detailed error messages, run most commands through a function that calls err() under fault conditions. Where detail is still required, err() is still called manually. Where it isn't, the error message is simply whatever command was executed to cause the error. This results in a massive sloccount reduction for lbmk; specifically, 178 sloc reduction, or a 8.1% reduction. The total sloccount is now 2022, for shell scripts. Signed-off-by: Leah Rowe --- script/build/fw/serprog | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'script/build/fw') diff --git a/script/build/fw/serprog b/script/build/fw/serprog index 211948ac..cdbf07e1 100755 --- a/script/build/fw/serprog +++ b/script/build/fw/serprog @@ -28,8 +28,7 @@ main() else err "${usage}" fi - mkdir -p "bin/serprog_${platform}" || \ - err "can't create dir: bin/serprog_${platform}" + x_ mkdir -p "bin/serprog_${platform}" if [ $# -gt 1 ] ; then if [ "${2}" = "list" ] ; then @@ -47,20 +46,18 @@ main() fetch_repo() { - ./update project repo "${1}" || err "fetch ${1} failed!\n" + x_ ./update project repo "${1}" } build_rp2040_rom() { board=${1} printf "Building pico-serprog for ${board}\n" - cmake -DPICO_BOARD="${board}" -DPICO_SDK_PATH="${pico_sdk_dir}" \ - -B "${pico_src_dir}/build" "${pico_src_dir}" \ - || err "can't cmake ${pico_src_dir}" - cmake --build "${pico_src_dir}/build" - mv ${pico_src_dir}/build/pico_serprog.uf2 \ - bin/serprog_rp2040/serprog_${board}.uf2 \ - || err "${board} serprog build failed!" + x_ cmake -DPICO_BOARD="${board}" -DPICO_SDK_PATH="${pico_sdk_dir}" \ + -B "${pico_src_dir}/build" "${pico_src_dir}" + x_ cmake --build "${pico_src_dir}/build" + x_ mv ${pico_src_dir}/build/pico_serprog.uf2 \ + bin/serprog_rp2040/serprog_${board}.uf2 printf "output to bin/serprog_rp2040/serprog_${board}.uf2\n" } @@ -68,11 +65,10 @@ build_stm32_rom() { board=${1} printf "Building stm32-vserprog for ${board}\n" - make -C ${stm32_src_dir} libopencm3-just-make BOARD=${board} - make -C ${stm32_src_dir} BOARD=${board} - mv ${stm32_src_dir}/stm32-vserprog.hex \ - bin/serprog_stm32/serprog_${board}.hex \ - || err "${board} serprog build failed!" + x_ make -C ${stm32_src_dir} libopencm3-just-make BOARD=${board} + x_ make -C ${stm32_src_dir} BOARD=${board} + x_ mv ${stm32_src_dir}/stm32-vserprog.hex \ + bin/serprog_stm32/serprog_${board}.hex printf "output to bin/serprog_stm32/serprog_${board}.hex\n" } -- cgit v1.2.1