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/coreboot/utils | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'script/build/coreboot/utils') diff --git a/script/build/coreboot/utils b/script/build/coreboot/utils index 8498897a..9dddc440 100755 --- a/script/build/coreboot/utils +++ b/script/build/coreboot/utils @@ -13,14 +13,12 @@ main() if [ $# -gt 0 ]; then for board in "${@}"; do - build_for_mainboard ${board} || \ - err "cannot build cbutils for target, ${board}" + x_ build_for_mainboard ${board} done else for boarddir in config/coreboot/*; do [ ! -d "${boarddir}" ] && continue - build_for_mainboard ${boarddir##*/} || \ - err "cannot build cbutils for target, ${board}" + x_ build_for_mainboard ${boarddir##*/} done fi } @@ -28,36 +26,29 @@ main() build_for_mainboard() { board="${1}" [ -d "config/coreboot/${board}" ] || \ - err "build_for_mainboard ${board}: boarddir does not exist" + err "build_for_mainboard ${board}: boarddir does not exist" [ -f "config/coreboot/${board}/target.cfg" ] || \ - err "build_for_mainboard ${board}: target.cfg does not exist" + err "build_for_mainboard ${board}: target.cfg does not exist" tree="undefined" . "config/coreboot/${board}/target.cfg" # source [ "${tree}" = "undefined" ] && \ - err "build_for_mainboard: improper tree definition for '${board}'" + err "build_for_mainboard ${board}: improper tree definition" buildutils "${tree}" } buildutils() { tree="${1}" [ -d "coreboot/${tree}/" ] || \ - ./update project trees coreboot $tree || \ - err "buildutils: cannot fetch ${tree}" + x_ ./update project trees coreboot ${tree} for util in cbfstool ifdtool; do [ -f "cbutils/${tree}/${util}" ] && continue - [ -d "cbutils/${tree}" ] || \ - mkdir -p "cbutils/${tree}" || \ - err "buildutils: can't mkdir cbutils/${tree}" + [ -d "cbutils/${tree}" ] || x_ mkdir -p "cbutils/${tree}" utildir="coreboot/${tree}/util/${util}" - make distclean -C "${utildir}" || \ - err "buildutils: cannot clean ${utildir}" - make -j$(nproc) -C "${utildir}" || \ - err "buildutils: cannot build ${utildir}" - cp "${utildir}/${util}" "cbutils/${tree}" || \ - err "buildutils: can't cp ${util} cbutils/${tree}/" - make distclean -C "${utildir}" || \ - err "buildutils: can't clean ${utildir}" + x_ make distclean -C "${utildir}" + x_ make -j$(nproc) -C "${utildir}" + x_ cp "${utildir}/${util}" "cbutils/${tree}" + x_ make distclean -C "${utildir}" done } -- cgit v1.2.1