summaryrefslogtreecommitdiff
path: root/script/build/coreboot/utils
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-10-01 06:33:43 +0100
committerLeah Rowe <leah@libreboot.org>2023-10-01 22:47:02 +0100
commit8c03b886c4d4b9bcfb1cb30b3704b8af561c2f45 (patch)
tree828eb1ad589300517e9a41581eee4b5d9605d3e8 /script/build/coreboot/utils
parent5f914a4d00da5ab9324c55eaecc40aa2ee000f63 (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/coreboot/utils')
-rwxr-xr-xscript/build/coreboot/utils31
1 files changed, 11 insertions, 20 deletions
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
}