Files
lbmk/script/handle/make/file
Leah Rowe 8c03b886c4 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>
2023-10-01 22:47:02 +01:00

55 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env sh
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2023 Leah Rowe <leah@libreboot.org>
[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e
. "include/err.sh"
eval "$(setvars "" mode project)"
main()
{
while getopts b:c: option
do
case "${1}" in
-b) : ;;
-c) mode="distclean" ;;
*) err "Invalid option" ;;
esac
shift; project="${OPTARG}"; shift
done
[ -z "${project}" ] && err "project name not specified"
handle_dependencies
run_make_command
}
handle_dependencies()
{
[ -d "${project}" ] || x_ ./update project repo "${project%/*}"
[ -d "${project}" ] || \
err "handle_dependencies: ${project%/*} not downloaded"
[ "${project}" = "uefitool" ] || return 0 # TODO: remove hardcoding
(
x_ cd uefitool
cmake UEFIExtract/ || [ -f Makefile ] || \
err "handle_dependencies: !cmake UEFIExtract/"
)
}
run_make_command()
{
if [ -z "${mode}" ]; then
x_ make -C "${project}" -j$(nproc)
else
x_ make -C "${project}" clean
make -C "${project}" distclean || :
fi
}
main $@