From 8f4f0e00ec3c307599f7f27777e3e92c1f9f6e4e Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Thu, 24 Aug 2023 00:30:07 +0100 Subject: use the new coding style in scripts there were stragglers left over from the last audit, and these stragglers still exist even after all the major re-factoring as of late the new style is: bsd-like coding style and error handling. verbose yet simple error handling. we use an "err" function in a way reminiscent of most C programs that you see in openbsd base (err.h) this style is very clean, resulting in readable code Signed-off-by: Leah Rowe --- resources/scripts/build/coreboot/utils | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'resources/scripts/build/coreboot/utils') diff --git a/resources/scripts/build/coreboot/utils b/resources/scripts/build/coreboot/utils index e24378d3..d381f9e2 100755 --- a/resources/scripts/build/coreboot/utils +++ b/resources/scripts/build/coreboot/utils @@ -21,10 +21,12 @@ [ "x${DEBUG+set}" = 'xset' ] && set -v set -u -e -printf "Building coreboot utils\n" +. "include/err.sh" main() { + printf "Building coreboot utils\n" + if [ $# -gt 0 ]; then for board in "${@}"; do build_for_mainboard ${board} || \ @@ -45,28 +47,28 @@ build_for_mainboard() { [ -f "resources/coreboot/${board}/target.cfg" ] || continue tree="undefined" . "resources/coreboot/${board}/target.cfg" # source - if [ "${tree}" = "undefined" ]; then - printf "build/cbutils: improper tree definition for '%s'" \ - "${board}" - return 1 - fi - buildutils "${tree}" || return 1 + [ "${tree}" = "undefined" ] && \ + err "build/cbutils: improper tree definition for '${board}'" + buildutils "${tree}" } buildutils() { tree="${1}" [ -d "coreboot/${tree}/" ] || \ - ./fetch_trees coreboot $tree || return 1 + ./fetch_trees coreboot $tree || \ + err "cannot fetch ${tree}" for util in cbfstool ifdtool; do [ -f "cbutils/${tree}/${util}" ] && continue [ -d "cbutils/${tree}" ] || \ - mkdir -p "cbutils/${tree}" || return 1 + mkdir -p "cbutils/${tree}" || \ + err "cannot create directory, cbutils/${tree}" utildir="coreboot/${tree}/util/${util}" - make distclean -C "${utildir}" || return 1 - make -j$(nproc) -C "${utildir}" || return 1 - mv "${utildir}/${util}" "cbutils/${tree}" || return 1 - make distclean -C "${utildir}" || return 1 + make distclean -C "${utildir}" || err "cannot clean ${utildir}" + make -j$(nproc) -C "${utildir}" || err "cannot build ${utildir}" + cp "${utildir}/${util}" "cbutils/${tree}" || \ + err "cannot copy util, ${util}, to cbutils/${tree}/" + make distclean -C "${utildir}" || err "can't clean ${utildir}" done } -- cgit v1.2.1