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