mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-03-25 13:29:03 +02:00
xbmk: tidy up some if statements
this is an extension of the previous work to unroll most of the condensed code lines. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -28,7 +28,6 @@ fetch_project()
|
||||
if [ -n "$xtree" ]; then
|
||||
x_ ./mk -f coreboot "$xtree"
|
||||
fi
|
||||
|
||||
if [ -n "$depend" ]; then
|
||||
for d in $depend ; do
|
||||
x_ ./mk -f $d
|
||||
@@ -118,9 +117,7 @@ xbget()
|
||||
do
|
||||
if [ -z "$url" ]; then
|
||||
err "empty URL given in" "xbget" "$@"
|
||||
fi
|
||||
|
||||
if ! try_file "$url" "$@"; then
|
||||
elif ! try_file "$url" "$@"; then
|
||||
continue
|
||||
fi
|
||||
|
||||
|
||||
@@ -283,27 +283,22 @@ xbmk_set_pyver()
|
||||
if ! pybin python3 1>/dev/null; then
|
||||
python="python"
|
||||
fi
|
||||
|
||||
if [ "$python" = "python3" ]; then
|
||||
pyver="3"
|
||||
fi
|
||||
|
||||
if ! pybin "$python" 1>/dev/null; then
|
||||
pyver=""
|
||||
fi
|
||||
|
||||
if [ -n "$pyver" ]; then
|
||||
"`x_ pybin "$python"`" -c "$pyv" 1>/dev/null \
|
||||
2>/dev/null || \
|
||||
err "Can't detect Python version." "xbmk_set_pyver" "$@"
|
||||
fi
|
||||
|
||||
if [ -n "$pyver" ]; then
|
||||
pyver="$("$(pybin "$python")" -c "$pyv" | awk '{print $1}')"
|
||||
pyver="${pyver#(}"
|
||||
pyver="${pyver%,}"
|
||||
fi
|
||||
|
||||
if [ "${pyver%%.*}" != "3" ]; then
|
||||
err "Bad python version (must by 3.x)" "xbmk_set_pyver" "$@"
|
||||
fi
|
||||
@@ -331,7 +326,6 @@ pybin()
|
||||
if ! command -v "$1" 1>/dev/null 2>/dev/null; then
|
||||
venv=0
|
||||
fi
|
||||
|
||||
if [ $venv -gt 0 ]; then
|
||||
if ! "$1" -c "$py" 1>/dev/null 2>/dev/null; then
|
||||
venv=0
|
||||
@@ -354,11 +348,14 @@ pybin()
|
||||
fi
|
||||
fi
|
||||
|
||||
# if python venv: fall back to common PATH directories for checking
|
||||
# if python venv: fall back to common PATH directories for checking:
|
||||
|
||||
[ $venv -gt 0 ] && for pypath in "/usr/local/bin" "/usr/bin"; do
|
||||
[ -e "$pypath/$1" ] && [ ! -d "$pypath/$1" ] && \
|
||||
[ -x "$pypath/$1" ] && printf "%s/%s\n" "$pypath" "$1" && \
|
||||
return 0
|
||||
if [ -e "$pypath/$1" ] && [ ! -d "$pypath/$1" ] && \
|
||||
[ -x "$pypath/$1" ]; then
|
||||
printf "%s/%s\n" "$pypath" "$1"
|
||||
return 0
|
||||
fi
|
||||
done && return 1
|
||||
|
||||
# Defer to normal command -v if not a venv
|
||||
|
||||
@@ -58,7 +58,6 @@ inject()
|
||||
if check_target; then
|
||||
patch_release
|
||||
fi
|
||||
|
||||
if [ "$xchanged" = "y" ]; then
|
||||
remktar
|
||||
fi
|
||||
@@ -149,9 +148,7 @@ patch_release()
|
||||
# prohibits direct exits. should probably return?
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -n "$new_mac" ] && [ -n "$CONFIG_GBE_BIN_PATH" ]; then
|
||||
elif [ -n "$new_mac" ] && [ -n "$CONFIG_GBE_BIN_PATH" ]; then
|
||||
modify_mac
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -89,24 +89,25 @@ e()
|
||||
setvars()
|
||||
{
|
||||
_setvars=""
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
printf "err \"setvars: too few args\\n\""
|
||||
return 0
|
||||
fi
|
||||
val="$1"
|
||||
shift 1
|
||||
while [ $# -gt 0 ]; do
|
||||
printf "%s=\"%s\"\n" "$1" "$val"
|
||||
else
|
||||
val="$1"
|
||||
shift 1
|
||||
done
|
||||
while [ $# -gt 0 ]; do
|
||||
printf "%s=\"%s\"\n" "$1" "$val"
|
||||
shift 1
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
setcfg()
|
||||
{
|
||||
if [ $# -gt 1 ]; then
|
||||
printf "e \"%s\" f missing && return %s;\n" "$1" "$2"
|
||||
fi
|
||||
if [ $# -lt 2 ]; then
|
||||
else
|
||||
printf "e \"%s\" f not && err \"Missing config '$1'\";\n" "$1"
|
||||
fi
|
||||
printf ". \"%s\" || err \"Could not read config '$1'\";\n" "$1"
|
||||
@@ -205,19 +206,18 @@ x_()
|
||||
{
|
||||
if [ $# -lt 1 ]; then
|
||||
return 0
|
||||
fi
|
||||
if [ -z "$1" ]; then
|
||||
elif [ -z "$1" ]; then
|
||||
err "Empty first arg" "x_" "$@"
|
||||
else
|
||||
"$@" || err "Unhandled error" "x_" "$@"
|
||||
fi
|
||||
"$@" || err "Unhandled error" "x_" "$@"
|
||||
}
|
||||
|
||||
xchk()
|
||||
{
|
||||
if [ $# -lt 3 ]; then
|
||||
err "$1 needs at least two arguments" "xchk" "$@"
|
||||
fi
|
||||
if [ -z "$2" ] || [ -z "$3" ]; then
|
||||
elif [ -z "$2" ] || [ -z "$3" ]; then
|
||||
err "arguments must not be empty" "xchk" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -197,7 +197,6 @@ mkcorebootbin_real()
|
||||
if [ -z "$grub_scan_disk" ]; then
|
||||
grub_scan_disk="nvme ahci ata"
|
||||
fi
|
||||
|
||||
if [ -z "$grubtree" ]; then
|
||||
grubtree="default"
|
||||
fi
|
||||
@@ -408,7 +407,6 @@ cprom()
|
||||
if [ -n "$displaymode" ]; then
|
||||
newrom="${newrom%.rom}_$displaymode.rom"
|
||||
fi
|
||||
|
||||
if [ $# -gt 0 ] && [ "${1%.gkb}" != "$1" ]; then
|
||||
tmpnew="${1##*/}"
|
||||
newrom="${newrom%.rom}_${tmpnew%.gkb}.rom"
|
||||
|
||||
@@ -63,14 +63,10 @@ trees()
|
||||
|
||||
if [ -z "$_f" ]; then
|
||||
err "missing flag ($flags)" "trees" "$@"
|
||||
fi
|
||||
|
||||
if [ -z "$project" ]; then
|
||||
elif [ -z "$project" ]; then
|
||||
fx_ "x_ ./mk $_f" x_ ls -1 config/git
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -f "config/git/$project/pkg.cfg" ]; then
|
||||
elif [ ! -f "config/git/$project/pkg.cfg" ]; then
|
||||
err "config/git/$project/pkg.cfg missing" "trees" "$@"
|
||||
fi
|
||||
|
||||
@@ -156,7 +152,6 @@ handle_defconfig()
|
||||
if [ ! -f "CHANGELOG" ]; then
|
||||
fetch_project "$project"
|
||||
fi
|
||||
|
||||
if ! configure_project "$target_dir"; then
|
||||
return 0
|
||||
fi
|
||||
@@ -234,21 +229,18 @@ configure_project()
|
||||
if [ "$_f" = "-d" ]; then
|
||||
build_depend="" # dry run
|
||||
fi
|
||||
|
||||
if [ "$cmd" = "build_project" ]; then
|
||||
# single-tree, so it can't be a target pointing
|
||||
# to a main source tree
|
||||
|
||||
break
|
||||
fi
|
||||
|
||||
if [ "$do_make" != "n" ]; then
|
||||
# if we're *downloading* a project, then
|
||||
# we don't need to to change the target.cfg
|
||||
|
||||
break
|
||||
fi
|
||||
|
||||
if [ "${_tcfg%/*/target.cfg}" = "${_tcfg%"/$tree/target.cfg"}" ]
|
||||
then
|
||||
# we have found the main source tree that
|
||||
@@ -264,7 +256,6 @@ configure_project()
|
||||
if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -n "$btype" ] && [ "${mode%config}" != "$mode" ]; then
|
||||
return 1
|
||||
fi
|
||||
@@ -281,10 +272,8 @@ configure_project()
|
||||
if [ ! -f "CHANGELOG" ]; then
|
||||
delete_old_project_files
|
||||
fi
|
||||
|
||||
if [ "$do_make" = "n" ]; then
|
||||
if [ ! -f "CHANGELOG" ]
|
||||
then
|
||||
if [ ! -f "CHANGELOG" ]; then
|
||||
fetch_${cmd#build_}
|
||||
fi
|
||||
|
||||
@@ -308,11 +297,9 @@ build_dependencies()
|
||||
$dry err "$project/$tree: !bd '$bd'" \
|
||||
"build_dependencies" "$@"
|
||||
fi
|
||||
|
||||
if [ "${bd##*/}" = "$bd" ]; then
|
||||
bd_tree=""
|
||||
fi
|
||||
|
||||
if [ -n "$bd_project" ]; then
|
||||
$dry x_ ./mk -b $bd_project $bd_tree; :
|
||||
fi
|
||||
@@ -591,18 +578,13 @@ check_autoconf()
|
||||
(
|
||||
x_ cd "$1"
|
||||
|
||||
if [ -f "bootstrap" ]
|
||||
then
|
||||
if [ -f "bootstrap" ]; then
|
||||
x_ ./bootstrap $bootstrapargs
|
||||
fi
|
||||
|
||||
if [ -f "autogen.sh" ]
|
||||
then
|
||||
if [ -f "autogen.sh" ]; then
|
||||
x_ ./autogen.sh $autogenargs
|
||||
fi
|
||||
|
||||
if [ -f "configure" ]
|
||||
then
|
||||
if [ -f "configure" ]; then
|
||||
x_ ./configure $autoconfargs; :
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user