diff options
author | Leah Rowe <leah@libreboot.org> | 2023-10-01 06:33:43 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2023-10-01 22:47:02 +0100 |
commit | 8c03b886c4d4b9bcfb1cb30b3704b8af561c2f45 (patch) | |
tree | 828eb1ad589300517e9a41581eee4b5d9605d3e8 /script/build/fw/serprog | |
parent | 5f914a4d00da5ab9324c55eaecc40aa2ee000f63 (diff) |
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 <leah@libreboot.org>
Diffstat (limited to 'script/build/fw/serprog')
-rwxr-xr-x | script/build/fw/serprog | 26 |
1 files changed, 11 insertions, 15 deletions
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" } |