mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-12 22:42:54 +02:00
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>
This commit is contained in:
+11
-20
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user