From fc7ae3e5903c176584cfefd6d3cf4c1549c4eaaa Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 22 Jun 2024 02:35:25 +0100 Subject: lib.sh: more unified config handling replace it with logic that simply uses "." to load files directly. for this, "vcfg" is added as a variable in coreboot target.cfg files, referring to a directory in config/vendor/ containing a file named pkg.cfg, and this file then contains the same variables as the erstwhile config/vendor/sources config/git files are now directories, also containing pkg.cfg files each with the same variables as before, such as repository link and commit hash this change results in a noticeable reduction in code complexity within the build system. unified reading of config files: new function setcfg() added to lib.sh setcfg checks if a config exists. if a 2nd argument is passed, it is used as a return value for eval, otherwise a string calling err is passed. setcfg output is passed through eval, to set strings based on config; eval must be used, so that the variables are set within the same scope, otherwise they'd be set within setcfg which could lead to some whacky results. there's still a bit more more to do, but this single change results in a substantial reduction in code complexity. Signed-off-by: Leah Rowe --- script/trees | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'script/trees') diff --git a/script/trees b/script/trees index b2b1e561..6a3c1ebd 100755 --- a/script/trees +++ b/script/trees @@ -35,7 +35,7 @@ main() [ -z "$_f" ] && $err "missing flag (-m/-u/-b/-c/-x/-f/-s/-l/-n)" [ -z "$project" ] && $err "project name not specified" - [ -f "config/git/$project" ] || $err "project '$project' not defined" + [ -f "config/git/$project/pkg.cfg" ] || $err "'$project' not defined" elfdir="elf/$project" datadir="config/data/$project" @@ -154,9 +154,7 @@ load_project_config() { eval "$(setvars "" xarch xlang tree bootstrapargs autoconfargs xtree \ tree_depend makeargs)" - - [ -f "$1/target.cfg" ] || return 0 - . "$1/target.cfg" || $err "loadp $1: can't load target.cfg"; return 0 + eval `setcfg "$1/target.cfg" 0`; return 0 } check_cross_compiler() @@ -274,15 +272,12 @@ check_makefile() mkpayload_grub() { - [ -f "$grubdata/module/$tree" ] || $err "$tree: grub modules missing" - x_ rm -f "$cdir/grub.elf" - eval "$(setvars "" grub_modules grub_install_modules)" - - . "$grubdata/module/$tree" || $err "$tree: !source grub modules" - + eval `setcfg "$grubdata/module/$tree"` chkvars "grub_install_modules" "grub_modules" + x_ rm -f "$cdir/grub.elf" + "${cdir}/grub-mkstandalone" --grub-mkimage="${cdir}/grub-mkimage" \ -O i386-coreboot -o "${cdir}/grub.elf" -d "${cdir}/grub-core/" \ --fonts= --themes= --locales= --modules="$grub_modules" \ @@ -290,7 +285,7 @@ mkpayload_grub() "/boot/grub/grub_default.cfg=${cdir}/.config" \ "/boot/grub/grub.cfg=$grubdata/memdisk.cfg" \ "/background.png=$grubdata/background/background1280x800.png" || \ - $err "$tree: cannot build grub.elf" + $err "$tree: cannot build grub.elf"; return 0 } copy_elf() -- cgit v1.2.1