summaryrefslogtreecommitdiff
path: root/include/lib.sh
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2024-06-22 02:35:25 +0100
committerLeah Rowe <leah@libreboot.org>2024-06-22 13:44:27 +0100
commitfc7ae3e5903c176584cfefd6d3cf4c1549c4eaaa (patch)
treed13789beaaa3c1215607dda17fada1b322b5db49 /include/lib.sh
parentad1602569ebf1404c47fb8ea4b39d0f8e844b840 (diff)
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 <leah@libreboot.org>
Diffstat (limited to 'include/lib.sh')
-rwxr-xr-xinclude/lib.sh34
1 files changed, 12 insertions, 22 deletions
diff --git a/include/lib.sh b/include/lib.sh
index 2fc17cfe..3e137d63 100755
--- a/include/lib.sh
+++ b/include/lib.sh
@@ -60,9 +60,7 @@ read -r projectsite < projectsite || :
install_packages()
{
[ $# -lt 2 ] && badcmd "fewer than two arguments"
- [ -f "config/dependencies/$2" ] || badcmd "unsupported target"
-
- . "config/dependencies/$2" || $err "! . config/dependencies/$2"
+ eval `setcfg "config/dependencies/$2"`
$pkg_add $pkglist || $err "Cannot install packages"
@@ -127,25 +125,6 @@ done
relname="$projectname-$version"
export LOCALVERSION="-$projectname-${version%%-*}"
-scan_config()
-{
- awkstr=" /\{.*$1.*}{/ {flag=1;next} /\}/{flag=0} flag { print }"
- confdir="$2"
- revfile="$(mktemp -t sources.XXXXXXXXXX)"
- cat "$confdir/"* > "$revfile" || $err "$confdir: can't cat files"
- while read -r line ; do
- set $line 1>/dev/null 2>/dev/null || :
- if [ "${1%:}" = "depend" ]; then
- depend="$depend $2"
- else
- eval "${1%:}=\"$2\""
- fi
- done << EOF
- $(eval "awk '$awkstr' \"$revfile\"")
-EOF
- rm -f "$revfile" || $err "scan_config: Cannot remove tmpfile"
-}
-
check_defconfig()
{
[ -d "$1" ] || $err "Target '$1' not defined."
@@ -253,3 +232,14 @@ cbfs()
lzma="-c lzma" && [ $# -gt 3 ] && lzma="-t raw"
x_ "$cbfstool" "$1" $ccmd -f "$2" -n "$3" $lzma
}
+
+setcfg()
+{
+ if [ $# -gt 1 ]; then
+ printf "e \"%s\" f missing && return %s;\n" "$1" "$2"
+ else
+ printf "e \"%s\" f missing && %s \"Missing config\";\n" "$1" \
+ "$err"
+ fi
+ printf ". \"%s\" || %s \"Could not read config\";\n" "$1" "$err"
+}