diff options
author | Leah Rowe <leah@libreboot.org> | 2025-09-26 00:09:46 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2025-09-26 00:09:46 +0100 |
commit | e42cb4f4cd513f512397ff7a46b6174b39a9708e (patch) | |
tree | ab6ba25c737cfa17ed6bc6eb9e1c4f5419ff892b | |
parent | f5060232e16ab1c041f0108a5f65d8f96f79756d (diff) |
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>
-rw-r--r-- | include/get.sh | 5 | ||||
-rw-r--r-- | include/init.sh | 17 | ||||
-rw-r--r-- | include/inject.sh | 5 | ||||
-rw-r--r-- | include/lib.sh | 26 | ||||
-rw-r--r-- | include/rom.sh | 2 | ||||
-rw-r--r-- | include/tree.sh | 30 | ||||
-rwxr-xr-x | mk | 2 |
7 files changed, 28 insertions, 59 deletions
diff --git a/include/get.sh b/include/get.sh index cd5d0960..d5be5a73 100644 --- a/include/get.sh +++ b/include/get.sh @@ -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 diff --git a/include/init.sh b/include/init.sh index 488b87f0..ed60bfc2 100644 --- a/include/init.sh +++ b/include/init.sh @@ -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 diff --git a/include/inject.sh b/include/inject.sh index cd5be73b..bc47d23e 100644 --- a/include/inject.sh +++ b/include/inject.sh @@ -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 } diff --git a/include/lib.sh b/include/lib.sh index 499fb329..2ff410eb 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -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 } diff --git a/include/rom.sh b/include/rom.sh index a105ea3a..30d07d28 100644 --- a/include/rom.sh +++ b/include/rom.sh @@ -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" diff --git a/include/tree.sh b/include/tree.sh index 51a7f2ff..9e4b13b3 100644 --- a/include/tree.sh +++ b/include/tree.sh @@ -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 @@ -12,11 +12,9 @@ ispwd="true" if [ "$0" != "./mk" ]; then ispwd="false" fi - if [ "$ispwd" = "true" ] && [ -L "mk" ]; then ispwd="false" fi - if [ "$ispwd" = "false" ]; then printf "You must run this in the proper work directory.\n" 1>&2 exit 1 |