trees: use wrapper for dry-running make commands
instead of using lots of if/else conditions, do that once and set a variable, dry, to : if not doing a dry run, the variable is empty. prefix this variable in places where you don't want a certain action to be performed, on dry runs. more specifically, : does *nothing* and always returns with zero status (success). this results in cleaner code, and a small sloccount reduction. Signed-off-by: Leah Rowe <leah@libreboot.org>audit2
parent
a258eb231a
commit
1a95c0cf30
|
@ -26,13 +26,12 @@ mkserprog()
|
||||||
|
|
||||||
mkpayload_grub()
|
mkpayload_grub()
|
||||||
{
|
{
|
||||||
[ "$_f" = "-d" ] && return 0 # dry run
|
|
||||||
eval `setvars "" grub_modules grub_install_modules`
|
eval `setvars "" grub_modules grub_install_modules`
|
||||||
eval `setcfg "$grubdata/module/$tree"`
|
$dry eval `setcfg "$grubdata/module/$tree"`
|
||||||
|
|
||||||
x_ rm -f "$cdir/grub.elf"
|
$dry x_ rm -f "$cdir/grub.elf"
|
||||||
|
|
||||||
"${cdir}/grub-mkstandalone" --grub-mkimage="${cdir}/grub-mkimage" \
|
$dry "${cdir}/grub-mkstandalone" --grub-mkimage="${cdir}/grub-mkimage" \
|
||||||
-O i386-coreboot -o "${cdir}/grub.elf" -d "${cdir}/grub-core/" \
|
-O i386-coreboot -o "${cdir}/grub.elf" -d "${cdir}/grub-core/" \
|
||||||
--fonts= --themes= --locales= --modules="$grub_modules" \
|
--fonts= --themes= --locales= --modules="$grub_modules" \
|
||||||
--install-modules="$grub_install_modules" \
|
--install-modules="$grub_install_modules" \
|
||||||
|
@ -44,12 +43,9 @@ mkpayload_grub()
|
||||||
|
|
||||||
mkvendorfiles()
|
mkvendorfiles()
|
||||||
{
|
{
|
||||||
if [ "$_f" = "-d" ]; then
|
|
||||||
check_coreboot_utils "$tree"
|
check_coreboot_utils "$tree"
|
||||||
elif [ "$_f" = "-b" ]; then
|
|
||||||
printf "%s\n" "${version%%-*}" > "$cdir/.coreboot-version" || \
|
printf "%s\n" "${version%%-*}" > "$cdir/.coreboot-version" || \
|
||||||
$err "!mk $cdir .coreboot-version"
|
$err "!mk $cdir .coreboot-version"
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_coreboot_utils()
|
check_coreboot_utils()
|
||||||
|
@ -71,7 +67,6 @@ check_coreboot_utils()
|
||||||
|
|
||||||
mkcorebootbin()
|
mkcorebootbin()
|
||||||
{
|
{
|
||||||
[ "$_f" = "-d" ] && return 0 # dry run
|
|
||||||
[ "$target" = "$tree" ] && return 0
|
[ "$target" = "$tree" ] && return 0
|
||||||
|
|
||||||
tmprom="$cdir/build/coreboot.rom"
|
tmprom="$cdir/build/coreboot.rom"
|
||||||
|
@ -84,7 +79,7 @@ mkcorebootbin()
|
||||||
[ "$payload_uboot" = "y" ] || payload_seabios="y"
|
[ "$payload_uboot" = "y" ] || payload_seabios="y"
|
||||||
[ "$payload_grub" = "y" ] && payload_seabios="y"
|
[ "$payload_grub" = "y" ] && payload_seabios="y"
|
||||||
[ "$payload_seabios" = "y" ] && [ "$payload_uboot" = "y" ] && \
|
[ "$payload_seabios" = "y" ] && [ "$payload_uboot" = "y" ] && \
|
||||||
$err "$target: U-Boot and SeaBIOS/GRUB are both enabled."
|
$dry $err "$target: U-Boot and SeaBIOS/GRUB are both enabled."
|
||||||
|
|
||||||
[ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"
|
[ -z "$grub_scan_disk" ] && grub_scan_disk="nvme ahci ata"
|
||||||
|
|
||||||
|
@ -94,11 +89,11 @@ mkcorebootbin()
|
||||||
[ "$payload_memtest" = "y" ] || payload_memtest="n"
|
[ "$payload_memtest" = "y" ] || payload_memtest="n"
|
||||||
[ "$(uname -m)" = "x86_64" ] || payload_memtest="n"
|
[ "$(uname -m)" = "x86_64" ] || payload_memtest="n"
|
||||||
|
|
||||||
[ "$payload_seabios" = "y" ] && pname="seabios" && add_seabios
|
[ "$payload_seabios" = "y" ] && pname="seabios" && $dry add_seabios
|
||||||
[ "$payload_uboot" = "y" ] && pname="uboot" && add_uboot
|
[ "$payload_uboot" = "y" ] && pname="uboot" && $dry add_uboot
|
||||||
|
|
||||||
newrom="bin/$target/${pname}_${target}_$initmode$displaymode.rom"
|
newrom="bin/$target/${pname}_${target}_$initmode$displaymode.rom"
|
||||||
x_ mkdir -p "${newrom%/*}"; x_ mv "$tmprom" "$newrom"
|
$dry x_ mkdir -p "${newrom%/*}"; $dry x_ mv "$tmprom" "$newrom"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_seabios()
|
add_seabios()
|
||||||
|
@ -141,7 +136,6 @@ add_uboot()
|
||||||
|
|
||||||
mkcoreboottar()
|
mkcoreboottar()
|
||||||
{
|
{
|
||||||
[ "$_f" = "-d" ] && return 0 # dry run
|
|
||||||
[ "$target" = "$tree" ] && return 0; [ "$XBMK_RELEASE" = "y" ] && \
|
[ "$target" = "$tree" ] && return 0; [ "$XBMK_RELEASE" = "y" ] && \
|
||||||
[ "$release" != "n" ] && mkrom_tarball "bin/$target"; return 0
|
[ "$release" != "n" ] && $dry mkrom_tarball "bin/$target"; return 0
|
||||||
}
|
}
|
||||||
|
|
66
script/trees
66
script/trees
|
@ -12,13 +12,13 @@ set -u -e
|
||||||
eval `setvars "" xarch cdir defconfig cmakedir xlang mode makeargs elfdir cmd \
|
eval `setvars "" xarch cdir defconfig cmakedir xlang mode makeargs elfdir cmd \
|
||||||
project target target_dir targets xtree _f release bootstrapargs mkhelper \
|
project target target_dir targets xtree _f release bootstrapargs mkhelper \
|
||||||
autoconfargs listfile autogenargs btype tree rev tree_depend build_depend \
|
autoconfargs listfile autogenargs btype tree rev tree_depend build_depend \
|
||||||
premake postmake mkhelpercfg`
|
premake postmake mkhelpercfg dry`
|
||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
while getopts f:b:m:u:c:x:s:l:n:d: option; do
|
while getopts f:b:m:u:c:x:s:l:n:d: option; do
|
||||||
[ -n "$_f" ] && $err "only one flag is permitted"
|
[ -n "$_f" ] && $err "only one flag is permitted"
|
||||||
_f="$1"
|
_f="$1" && [ "$_f" = "-d" ] && dry=":"
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-d) mode="" ;;
|
-d) mode="" ;;
|
||||||
-b) mode="" ;;
|
-b) mode="" ;;
|
||||||
|
@ -62,8 +62,7 @@ handle_project()
|
||||||
cmd="build_project"; $cmd
|
cmd="build_project"; $cmd
|
||||||
|
|
||||||
[ -f "$listfile" ] || return 0
|
[ -f "$listfile" ] || return 0
|
||||||
[ -z "$mode" ] && [ "$_f" = "-b" ] && \
|
[ -z "$mode" ] && $dry printf "\n\nOK! Check %s/\n\n" "$elfdir"; :
|
||||||
printf "\n\nOK! Check %s/\n\n" "$elfdir"; return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
build_project()
|
build_project()
|
||||||
|
@ -79,7 +78,7 @@ build_project()
|
||||||
[ "$mode" = "distclean" ] && mode="clean"
|
[ "$mode" = "distclean" ] && mode="clean"
|
||||||
run_make_command || return 0
|
run_make_command || return 0
|
||||||
|
|
||||||
[ -n "$mode" ] || copy_elf; return 0
|
[ -n "$mode" ] || $dry copy_elf; return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
build_targets()
|
build_targets()
|
||||||
|
@ -115,7 +114,7 @@ handle_defconfig()
|
||||||
|
|
||||||
[ -n "$mode" ] || check_defconfig || continue
|
[ -n "$mode" ] || check_defconfig || continue
|
||||||
handle_makefile
|
handle_makefile
|
||||||
[ -n "$mode" ] || copy_elf
|
[ -n "$mode" ] || $dry copy_elf
|
||||||
done; return 0
|
done; return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +134,7 @@ handle_src_tree()
|
||||||
fi
|
fi
|
||||||
x_ ./update trees -f "$project" "$target"
|
x_ ./update trees -f "$project" "$target"
|
||||||
|
|
||||||
[ -z "$mode" ] && [ "$_f" = "-b" ] && check_cross_compiler; return 0
|
[ -z "$mode" ] && $dry check_cross_compiler; return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_project()
|
configure_project()
|
||||||
|
@ -163,16 +162,13 @@ configure_project()
|
||||||
[ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ] && return 1
|
[ "$XBMK_RELEASE" = "y" ] && [ "$release" = "n" ] && return 1
|
||||||
[ -z "$btype" ] || [ "${mode%config}" = "$mode" ] || return 1
|
[ -z "$btype" ] || [ "${mode%config}" = "$mode" ] || return 1
|
||||||
|
|
||||||
if [ "$_f" = "-d" ]; then
|
if [ -z "$mode" ]; then
|
||||||
:
|
|
||||||
elif [ -z "$mode" ]; then
|
|
||||||
for bd in $build_depend; do
|
for bd in $build_depend; do
|
||||||
bd_project="${bd%%/*}"; bd_tree="${bd##*/}"
|
bd_p="${bd%%/*}"; bd_t="${bd##*/}"
|
||||||
[ -z "$bd_project" ] && \
|
[ -z "$bd_p" ] && $dry $err "$project/$tree: !bd '$bd'"
|
||||||
$err "$project/$tree: bad bd: '$bd'"
|
[ "${bd##*/}" = "$bd" ] && bd_t=""
|
||||||
[ "${bd##*/}" = "$bd" ] && bd_tree=""
|
[ -z "$bd_p" ] || $dry ./update trees -b $bd_p $bd_t \
|
||||||
[ -z "$bd_project" ] || ./update trees -b $bd_project \
|
|| $err "!mk $project/$tree $bd_p/$bd_t"
|
||||||
$bd_tree || $err "$project/$tree: !bd $bd"
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -202,19 +198,16 @@ check_cross_compiler()
|
||||||
|
|
||||||
check_defconfig()
|
check_defconfig()
|
||||||
{
|
{
|
||||||
[ "$_f" = "-d" ] && return 0
|
[ -f "$defconfig" ] || $dry $err "$project/$target: missing defconfig"
|
||||||
[ -f "$defconfig" ] || $err "$project/$target: missing defconfig"
|
|
||||||
|
|
||||||
dest_dir="$elfdir/$target/${defconfig#"$target_dir/config/"}"
|
dest_dir="$elfdir/$target/${defconfig#"$target_dir/config/"}"
|
||||||
elfcheck || return 1 # skip build if a previous one exists
|
$dry elfcheck || return 1 # skip build if a previous one exists
|
||||||
|
|
||||||
x_ mkdir -p "$dest_dir"
|
$dry x_ mkdir -p "$dest_dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
elfcheck()
|
elfcheck()
|
||||||
{
|
{
|
||||||
[ "$_f" = "-d" ] && return 0 # dry run. assume a build exists.
|
|
||||||
|
|
||||||
# TODO: very hacky check. do it properly (based on build.list)
|
# TODO: very hacky check. do it properly (based on build.list)
|
||||||
for elftest in "$dest_dir"/*; do
|
for elftest in "$dest_dir"/*; do
|
||||||
[ -e "$elftest" ] && e "$elftest" f && return 1
|
[ -e "$elftest" ] && e "$elftest" f && return 1
|
||||||
|
@ -223,48 +216,45 @@ elfcheck()
|
||||||
|
|
||||||
handle_makefile()
|
handle_makefile()
|
||||||
{
|
{
|
||||||
check_makefile "$cdir" && x_ make clean -C "$cdir"
|
$dry check_makefile "$cdir" && x_ make clean -C "$cdir"
|
||||||
[ -f "$defconfig" ] && x_ cp "$defconfig" "$cdir/.config"
|
[ -f "$defconfig" ] && x_ cp "$defconfig" "$cdir/.config"
|
||||||
[ "$_f" = "-d" ] || [ -n "$mode" ] || [ -n "$btype" ] || make -C \
|
[ -n "$mode" ] || [ -n "$btype" ] || $dry make -C \
|
||||||
"$cdir" silentoldconfig || make -C "$cdir" oldconfig || :
|
"$cdir" silentoldconfig || make -C "$cdir" oldconfig || :
|
||||||
|
|
||||||
run_make_command || $err "handle_makefile $cdir: no makefile!"
|
run_make_command || $err "handle_makefile $cdir: no makefile!"
|
||||||
[ "$_f" = "-d" ] && return 0
|
|
||||||
|
|
||||||
_copy=".config" && [ "$mode" = "savedefconfig" ] && _copy="defconfig"
|
_copy=".config" && [ "$mode" = "savedefconfig" ] && _copy="defconfig"
|
||||||
[ "${mode%config}" = "$mode" ] || x_ cp "$cdir/$_copy" "$defconfig"
|
[ "${mode%config}" = "$mode" ] || $dry x_ cp "$cdir/$_copy" "$defconfig"
|
||||||
|
|
||||||
[ -e "$cdir/.git" ] && [ "$project" = "u-boot" ] && \
|
[ -e "$cdir/.git" ] && [ "$project" = "u-boot" ] && \
|
||||||
[ "$mode" = "distclean" ] && x_ git -C "$cdir" clean -fdx; return 0
|
[ "$mode" = "distclean" ] && $dry x_ git -C "$cdir" clean -fdx; :
|
||||||
}
|
}
|
||||||
|
|
||||||
run_make_command()
|
run_make_command()
|
||||||
{
|
{
|
||||||
[ -z "$premake" ] || [ -n "$mode" ] || $premake || $err "!$premake"
|
[ -z "$premake" ] || [ -n "$mode" ] || $premake || $err "!$premake"
|
||||||
|
|
||||||
check_cmake "$cdir" && [ -z "$mode" ] && check_autoconf "$cdir"
|
$dry check_cmake "$cdir" && [ -z "$mode" ] && $dry check_autoconf \
|
||||||
check_makefile "$cdir" || return 1
|
"$cdir"; $dry check_makefile "$cdir" || return 1
|
||||||
|
|
||||||
[ "$_f" = "-d" ] || make -C "$cdir" $mode -j$XBMK_THREADS $makeargs \
|
$dry make -C "$cdir" $mode -j$XBMK_THREADS $makeargs \
|
||||||
|| $err "$cdir mk$mode"
|
|| $err "$cdir mk$mode"
|
||||||
[ -z "$mkhelper" ] || [ -n "$mode" ] || $mkhelper || $err "!$mkhelper"
|
[ -z "$mkhelper" ] || [ -n "$mode" ] || $mkhelper || $err "!$mkhelper"
|
||||||
|
|
||||||
[ "$_f" = "-d" ] && return 0
|
[ "$mode" = "clean" ] && $dry make -C "$cdir" distclean || :; return 0
|
||||||
[ "$mode" = "clean" ] && make -C "$cdir" distclean || :; return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_cmake()
|
check_cmake()
|
||||||
{
|
{
|
||||||
[ "$_f" = "-d" ] && return 0 # dry run
|
[ -z "$cmakedir" ] || $dry check_makefile "$1" || cmake -B "$1" \
|
||||||
[ -z "$cmakedir" ] || check_makefile "$1" || cmake -B "$1" \
|
"$1/$cmakedir" || $dry check_makefile "$1" || $err \
|
||||||
"$1/$cmakedir" || check_makefile "$1" || $err "$1: !cmk $cmakedir"
|
"$1: !cmk $cmakedir"
|
||||||
[ -z "$cmakedir" ] || check_makefile "$1" || \
|
[ -z "$cmakedir" ] || $dry check_makefile "$1" || \
|
||||||
$err "check_cmake $1: can't generate Makefile"; return 0
|
$err "check_cmake $1: can't generate Makefile"; return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
check_autoconf()
|
check_autoconf()
|
||||||
{
|
{
|
||||||
[ "$_f" = "-d" ] && return 0 # dry run
|
|
||||||
(
|
(
|
||||||
cd "$1" || $err "!cd $1"
|
cd "$1" || $err "!cd $1"
|
||||||
[ -f "bootstrap" ] && x_ ./bootstrap $bootstrapargs
|
[ -f "bootstrap" ] && x_ ./bootstrap $bootstrapargs
|
||||||
|
@ -275,14 +265,12 @@ check_autoconf()
|
||||||
|
|
||||||
check_makefile()
|
check_makefile()
|
||||||
{
|
{
|
||||||
[ "$_f" = "-d" ] && return 0 # dry run
|
|
||||||
[ -f "$1/Makefile" ] || [ -f "$1/makefile" ] || \
|
[ -f "$1/Makefile" ] || [ -f "$1/makefile" ] || \
|
||||||
[ -f "$1/GNUmakefile" ] || return 1; return 0
|
[ -f "$1/GNUmakefile" ] || return 1; return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_elf()
|
copy_elf()
|
||||||
{
|
{
|
||||||
[ "$_f" = "-d" ] && return 0 # dry run
|
|
||||||
[ -f "$listfile" ] && x_ mkdir -p "$dest_dir" && while read -r f; do
|
[ -f "$listfile" ] && x_ mkdir -p "$dest_dir" && while read -r f; do
|
||||||
[ -f "$cdir/$f" ] && x_ cp "$cdir/$f" "$dest_dir"
|
[ -f "$cdir/$f" ] && x_ cp "$cdir/$f" "$dest_dir"
|
||||||
done < "$listfile"; x_ make clean -C "$cdir"
|
done < "$listfile"; x_ make clean -C "$cdir"
|
||||||
|
|
Loading…
Reference in New Issue