summaryrefslogtreecommitdiff
path: root/include/tree.sh
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2025-09-24 13:19:23 +0100
committerLeah Rowe <leah@libreboot.org>2025-09-24 13:19:23 +0100
commit8347e2c85da0841dd35d6f94a5b3cf14bd1adff0 (patch)
tree1b0a5cd08058e8824e036d7f41f9246a4724175d /include/tree.sh
parent03bf6c185b96e631d0f52a67b685628514b3776c (diff)
xbmk: cleanup of recent code refactoring
be a bit less pedantic about if else clauses. leave the big ones still with then on separate lines, where else is specified. also unroll a few condensed code lines where i missed a few. sloccount 2303 in lbmk. that's still only slightly bigger than libreboot 20260907 which was 2180, and still much smaller than libreboot 20230625 which was 3322. this is *without* the condensed codelines, so now the only thing that's reduced is the overall amount of logic present in the build system. and i should clarify that lbmk is presently much more powerful than both of those two versions (20160907/20230625). the 2016 one is useful for comparison historically, since that was the last major version of libreboot prior to the great second coming of leah in 2021; and the 2023 june release was basically the last one before the great audits of 2023 to 2025 began. not to brag (not much anyway), but all of this means that lbmk is an insanely efficient build system, considering all the features it has and what it does. i unrolled the condensed code style in lbmk, making the scripts a lot easier to read, because i received complainst about the condensed style previously used; nicholas chin and alper nebi yasak both told me that it sucked, and riku viitanen had hinted at that same fact several months prior. so hopefully now, lbmk is a bit nicer. those and other people often find it challenging to challenge me because for reason they assume i'll get upset and fly off the handle, but it's the opposite. i want constant criticism, so that i know to improve! Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'include/tree.sh')
-rw-r--r--include/tree.sh208
1 files changed, 69 insertions, 139 deletions
diff --git a/include/tree.sh b/include/tree.sh
index c367010f..859ef200 100644
--- a/include/tree.sh
+++ b/include/tree.sh
@@ -15,8 +15,7 @@ trees()
while getopts $flags option
do
- if [ -n "$_f" ]
- then
+ if [ -n "$_f" ]; then
err "only one flag is permitted" "trees" "$@"
fi
@@ -61,19 +60,16 @@ trees()
shift 2
done
- if [ -z "$_f" ]
- then
+ if [ -z "$_f" ]; then
err "missing flag ($flags)" "trees" "$@"
fi
- if [ -z "$project" ]
- then
+ if [ -z "$project" ]; then
fx_ "x_ ./mk $_f" x_ ls -1 config/git
return 1
fi
- if [ ! -f "config/git/$project/pkg.cfg" ]
- then
+ if [ ! -f "config/git/$project/pkg.cfg" ]; then
err "config/git/$project/pkg.cfg missing" "trees" "$@"
fi
@@ -84,14 +80,12 @@ trees()
dest_dir="$elfdir"
listfile="$datadir/build.list"
- if [ ! -f "$listfile" ]
- then
+ if [ ! -f "$listfile" ]; then
listfile="" # build.list is optional on all projects
fi
mkhelpercfg="$datadir/mkhelper.cfg"
- if e "$mkhelpercfg" f missing
- then
+ if e "$mkhelpercfg" f missing; then
mkhelpercfg="$xbtmp/mkhelper.cfg"
x_ touch "$mkhelpercfg"
fi
@@ -105,34 +99,28 @@ trees()
build_project()
{
- if ! configure_project "$configdir"
- then
+ if ! configure_project "$configdir"; then
return 0
- elif [ -f "$listfile" ]
- then
+ elif [ -f "$listfile" ]; then
$dry elfcheck || return 0; :
fi
- if [ "$mode" = "distclean" ]
- then
+ if [ "$mode" = "distclean" ]; then
mode="clean"
fi
run_make_command || return 0
- if [ -z "$mode" ]
- then
+ if [ -z "$mode" ]; then
$dry copy_elf; :
fi
}
build_targets()
{
- if [ ! -d "$configdir" ]
- then
+ if [ ! -d "$configdir" ]; then
err "directory '$configdir' doesn't exist" "build_targets" "$@"
- elif [ $# -lt 1 ]
- then
+ elif [ $# -lt 1 ]; then
targets="$(ls -1 "$configdir")" || \
err "'$configdir': can't list targets" "build_targets" "$@"
fi
@@ -142,8 +130,7 @@ build_targets()
unset CROSS_COMPILE
export PATH="$xbmkpath"
- if [ "$x" = "list" ]
- then
+ if [ "$x" = "list" ]; then
x_ ls -1 "config/$project"
listfile=""
break
@@ -155,8 +142,7 @@ build_targets()
x_ handle_defconfig
- if [ -z "$mode" ]
- then
+ if [ -z "$mode" ]; then
x_ $postmake
fi
done; :
@@ -166,41 +152,34 @@ handle_defconfig()
{
target_dir="$configdir/$target"
- if [ ! -f "CHANGELOG" ]
- then
+ if [ ! -f "CHANGELOG" ]; then
fetch_project "$project"
fi
- if ! configure_project "$target_dir"
- then
+ if ! configure_project "$target_dir"; then
return 0
fi
chkvars tree
srcdir="src/$project/$tree"
- if [ "$mode" = "${mode%clean}" ] && [ ! -d "$srcdir" ]
- then
+ if [ "$mode" = "${mode%clean}" ] && [ ! -d "$srcdir" ]; then
return 0
fi
for y in "$target_dir/config"/*
do
- if [ "$_f" != "-d" ] && [ ! -f "$y" ]
- then
+ if [ "$_f" != "-d" ] && [ ! -f "$y" ]; then
continue
- elif [ "$_f" != "-d" ]
- then
+ elif [ "$_f" != "-d" ]; then
defconfig="$y"
fi
- if [ -z "$mode" ]
- then
+ if [ -z "$mode" ]; then
check_defconfig || continue; :
fi
- if [ -z "$mode" ]
- then
+ if [ -z "$mode" ]; then
for _xarch in $xarch; do
if [ -n "$_xarch" ]
then
@@ -211,8 +190,7 @@ handle_defconfig()
handle_makefile
- if [ -z "$mode" ]
- then
+ if [ -z "$mode" ]; then
$dry copy_elf
fi
done; :
@@ -226,15 +204,13 @@ configure_project()
_tcfg="$1/target.cfg"
- if [ ! -f "$_tcfg" ]
- then
+ if [ ! -f "$_tcfg" ]; then
btype="auto"
fi
# globally initialise all variables for a source tree / target:
- if e "$datadir/mkhelper.cfg" f
- then
+ if e "$datadir/mkhelper.cfg" f; then
eval "`setcfg "$datadir/mkhelper.cfg"`"
fi
@@ -254,21 +230,18 @@ configure_project()
eval "`setvars "" rev tree`"
eval "`setcfg "$_tcfg"`"
- if [ "$_f" = "-d" ]
- then
+ if [ "$_f" = "-d" ]; then
build_depend="" # dry run
fi
- if [ "$cmd" = "build_project" ]
- then
+ 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 [ "$do_make" != "n" ]; then
# if we're *downloading* a project, then
# we don't need to to change the target.cfg
@@ -287,34 +260,28 @@ configure_project()
done
- if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]
- then
+ if [ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ]; then
return 1
fi
- if [ -n "$btype" ] && [ "${mode%config}" != "$mode" ]
- then
+ if [ -n "$btype" ] && [ "${mode%config}" != "$mode" ]; then
return 1
fi
- if [ -z "$mode" ]
- then
+ if [ -z "$mode" ]; then
$dry build_dependencies; :
fi
mdir="$xbmkpwd/config/submodule/$project"
- if [ -n "$tree" ]
- then
+ if [ -n "$tree" ]; then
mdir="$mdir/$tree"
fi
- if [ ! -f "CHANGELOG" ]
- then
+ if [ ! -f "CHANGELOG" ]; then
delete_old_project_files
fi
- if [ "$do_make" = "n" ]
- then
+ if [ "$do_make" = "n" ]; then
if [ ! -f "CHANGELOG" ]
then
fetch_${cmd#build_}
@@ -336,19 +303,16 @@ build_dependencies()
bd_project="${bd%%/*}"
bd_tree="${bd##*/}"
- if [ -z "$bd_project" ]
- then
+ if [ -z "$bd_project" ]; then
$dry err "$project/$tree: !bd '$bd'" \
"build_dependencies" "$@"
fi
- if [ "${bd##*/}" = "$bd" ]
- then
+ if [ "${bd##*/}" = "$bd" ]; then
bd_tree=""
fi
- if [ -n "$bd_project" ]
- then
+ if [ -n "$bd_project" ]; then
$dry x_ ./mk -b $bd_project $bd_tree; :
fi
done; :
@@ -366,8 +330,7 @@ delete_old_project_files()
{
# delete an entire source tree along with its builds:
if ! project_up_to_date hash "$tree" badhash "$datadir" \
- "$configdir/$tree" "$mdir"
- then
+ "$configdir/$tree" "$mdir"; then
x_ rm -Rf "src/$project/$tree" "elf/$project/$tree"
fi
@@ -402,8 +365,7 @@ project_up_to_date()
x_ mkdir -p "$XBMK_CACHE/$hashdir"
- if [ -f "$XBMK_CACHE/$hashdir/$project$hashname" ]
- then
+ if [ -f "$XBMK_CACHE/$hashdir/$project$hashname" ]; then
read -r old_hash < \
"$XBMK_CACHE/$hashdir/$project$hashname" \
|| err \
@@ -421,8 +383,7 @@ project_up_to_date()
"project_up_to_date" "$hashdir" "$hashname" "$badhashvar" "$@"
if [ "$hash" != "$old_hash" ] || \
- [ ! -f "$XBMK_CACHE/$hashdir/$project$hashname" ]
- then
+ [ ! -f "$XBMK_CACHE/$hashdir/$project$hashname" ]; then
eval "$badhashvar=\"y\""
fi
@@ -437,19 +398,16 @@ check_cross_compiler()
{
cbdir="src/coreboot/$tree"
- if [ "$project" != "coreboot" ]
- then
+ if [ "$project" != "coreboot" ]; then
cbdir="src/coreboot/default"
fi
- if [ -n "$xtree" ]
- then
+ if [ -n "$xtree" ]; then
cbdir="src/coreboot/$xtree"
fi
xfix="${1%-*}"
- if [ "$xfix" = "x86_64" ]
- then
+ if [ "$xfix" = "x86_64" ]; then
xfix="x64"
fi
@@ -462,13 +420,11 @@ check_cross_compiler()
export PATH="$xbmkpwd/$cbdir/util/crossgcc/xgcc/bin:$PATH"
export CROSS_COMPILE="${xarch% *}-"
- if [ -n "$xlang" ]
- then
+ if [ -n "$xlang" ]; then
export BUILD_LANGUAGES="$xlang"
fi
- if [ -f "$xgccfile" ]
- then
+ if [ -f "$xgccfile" ]; then
return 0 # a build already exists
fi
@@ -485,23 +441,22 @@ check_cross_compiler()
# gnat in PATH never resolves to gnat-14, because gnat-14 was "experimental"
check_gnu_path()
{
- if ! command -v "$1" 1>/dev/null
- then
+ if ! command -v "$1" 1>/dev/null; then
err "Host '$1' unavailable" "check_gnu_path" "$@"
fi
eval "`setvars "" gccver gccfull gnatver gnatfull gccdir gnatdir`"
- if ! gnu_setver "$1" "$1"
- then
+ if ! gnu_setver "$1" "$1"; then
err "Command '$1' unavailable." "check_gnu_path" "$@"
fi
gnu_setver "$2" "$2" || :
eval "[ -z \"\$$1ver\" ] && err \"Cannot detect host '$1' version\""
- if [ "$gnatfull" = "$gccfull" ]
- then
- return 0 # matching gcc/gnat versions
+ if [ "$gnatfull" = "$gccfull" ]; then
+ # matching gcc/gnat versions
+
+ return 0
fi
eval "$1dir=\"$(dirname "$(command -v "$1")")\""
@@ -517,16 +472,13 @@ check_gnu_path()
fi
done
- if ! gnu_setver "$2" "$_gnudir/$2-$_gnuver"
- then
+ if ! gnu_setver "$2" "$_gnudir/$2-$_gnuver"; then
return 1
- elif [ "$gnatfull" != "$gccfull" ]
- then
+ elif [ "$gnatfull" != "$gccfull" ]; then
return 1
fi
(
-
remkdir "$xbtmp/gnupath"
x_ cd "$xbtmp/gnupath"
@@ -534,8 +486,7 @@ check_gnu_path()
for _gnubin in "$_gnudir/$2"*"-$_gnuver"
do
_gnuutil="${_gnubin##*/}"
- if [ -e "$_gnubin" ]
- then
+ if [ -e "$_gnubin" ]; then
x_ ln -s "$_gnubin" "${_gnuutil%"-$_gnuver"}"
fi
done
@@ -556,8 +507,7 @@ gnu_setver()
check_defconfig()
{
- if [ ! -f "$defconfig" ]
- then
+ if [ ! -f "$defconfig" ]; then
$dry err "$project/$target: missing defconfig" \
"check_defconfig" "$@"
fi
@@ -571,11 +521,7 @@ elfcheck()
{
# TODO: *STILL* very hacky check. do it properly (based on build.list)
- (
-
- fx_ "eval exit 1 && err" find "$dest_dir" -type f
-
- ) || return 1; :
+ ( fx_ "eval exit 1 && err" find "$dest_dir" -type f ) || return 1; :
}
handle_makefile()
@@ -583,8 +529,7 @@ handle_makefile()
$dry check_makefile "$srcdir" && \
$dry x_ make -C "$srcdir" $cleanargs clean
- if [ -f "$defconfig" ]
- then
+ if [ -f "$defconfig" ]; then
x_ cp "$defconfig" "$srcdir/.config"
fi
@@ -593,27 +538,23 @@ handle_makefile()
_copy=".config"
- if [ "$mode" = "savedefconfig" ]
- then
+ if [ "$mode" = "savedefconfig" ]; then
_copy="defconfig"
fi
- if [ "${mode%config}" != "$mode" ]
- then
+ if [ "${mode%config}" != "$mode" ]; then
$dry x_ cp "$srcdir/$_copy" "$defconfig"; :
fi
if [ -e "$srcdir/.git" ] && [ "$project" = "u-boot" ] && \
- [ "$mode" = "distclean" ]
- then
+ [ "$mode" = "distclean" ]; then
$dry x_ git -C "$srcdir" $cleanargs clean -fdx; :
fi
}
run_make_command()
{
- if [ -z "$mode" ]
- then
+ if [ -z "$mode" ]; then
x_ $premake
fi
@@ -623,15 +564,13 @@ run_make_command()
$dry x_ make -C "$srcdir" $mode -j$XBMK_THREADS $makeargs
- if [ -z "$mode" ]
- then
+ if [ -z "$mode" ]; then
x_ $mkhelper
fi
check_makefile "$srcdir" || return 0
- if [ "$mode" = "clean" ]
- then
+ if [ "$mode" = "clean" ]; then
$dry make -C "$srcdir" $cleanargs distclean || \
$dry x_ make -C "$srcdir" $cleanargs clean; :
fi
@@ -639,8 +578,7 @@ run_make_command()
check_cmake()
{
- if [ -n "$cmakedir" ]
- then
+ if [ -n "$cmakedir" ]; then
$dry check_makefile "$1" || cmake -B "$1" \
"$1/$cmakedir" || $dry x_ check_makefile "$1"
$dry x_ check_makefile "$1"; :
@@ -650,7 +588,6 @@ check_cmake()
check_autoconf()
{
(
-
x_ cd "$1"
if [ -f "bootstrap" ]
@@ -674,25 +611,21 @@ check_autoconf()
check_makefile()
{
if [ ! -f "$1/Makefile" ] && [ ! -f "$1/makefile" ] && \
- [ ! -f "$1/GNUmakefile" ]
- then
+ [ ! -f "$1/GNUmakefile" ]; then
return 1
fi
}
copy_elf()
{
- if [ -f "$listfile" ]
- then
+ if [ -f "$listfile" ]; then
x_ mkdir -p "$dest_dir"
fi
- if [ -f "$listfile" ]
- then
+ if [ -f "$listfile" ]; then
while read -r f
do
- if [ -f "$srcdir/$f" ]
- then
+ if [ -f "$srcdir/$f" ]; then
x_ cp "$srcdir/$f" "$dest_dir"
fi
@@ -700,9 +633,6 @@ copy_elf()
"cannot read '$listfile'" "copy_elf" "$@"; :
fi
- (
-
- x_ make clean -C "$srcdir" $cleanargs
-
- ) || err "can't make-clean '$srcdir'" "copy_elf" "$@"; :
+ ( x_ make clean -C "$srcdir" $cleanargs ) || \
+ err "can't make-clean '$srcdir'" "copy_elf" "$@"; :
}