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>
This commit is contained in:
Leah Rowe
2024-06-22 02:35:25 +01:00
parent ad1602569e
commit fc7ae3e590
83 changed files with 190 additions and 306 deletions
+7 -9
View File
@@ -31,10 +31,8 @@ fetch_config()
load_target_config()
{
[ -f "$cfgsdir/$1/target.cfg" ] || $err "$1: target.cfg missing"
[ -f "$cfgsdir/$1/seen" ] && $err "$_xm cfg: infinite loop in trees"
. "$cfgsdir/$1/target.cfg" || $err "load_target_config !$cfgsdir/$1"
eval `setcfg "$cfgsdir/$1/target.cfg"`
touch "$cfgsdir/$1/seen" || $err "load_config $cfgsdir/$1: !mk seen"
}
@@ -50,9 +48,9 @@ prepare_new_tree()
fetch_project_repo()
{
eval "$(setvars "" xtree tree_depend)"
eval `setcfg "config/git/$project/pkg.cfg"`
scan_config "$project" "config/git"
chkvars loc url
chkvars url
[ -n "$xtree" ] && [ ! -d "src/coreboot/$xtree" ] && \
x_ ./update trees -f coreboot "$xtree"
@@ -63,14 +61,14 @@ fetch_project_repo()
clone_project
for x in config/git/*; do
[ -f "$x" ] && nuke "${x##*/}" "src/${x##*/}" 2>/dev/null
done
[ -d "$x" ] && nuke "${x##*/}" "src/${x##*/}" 2>/dev/null
done; return 0
}
clone_project()
{
loc="${loc#src/}"
loc="src/$loc"
loc="src/$project"
singletree "$project" || loc="src/$project/$project"
printf "Downloading project '%s' to '%s'\n" "$project" "$loc"
e "$loc" d && return 0
+12 -22
View File
@@ -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"
}
+13 -17
View File
@@ -14,7 +14,7 @@ vendir="vendorfiles"
appdir="$vendir/app"
cbcfgsdir="config/coreboot"
eval "$(setvars "" _b EC_url_bkup EC_hash DL_hash DL_url_bkup MRC_refcode_gbe \
eval "$(setvars "" EC_url_bkup EC_hash DL_hash DL_url_bkup MRC_refcode_gbe \
E6400_VGA_DL_hash E6400_VGA_DL_url E6400_VGA_DL_url_bkup E6400_VGA_offset \
E6400_VGA_romname CONFIG_HAVE_MRC SCH5545EC_DL_url_bkup SCH5545EC_DL_hash \
mecleaner kbc1126_ec_dump MRC_refcode_cbtree new_mac _dl SCH5545EC_DL_url \
@@ -24,29 +24,27 @@ eval "$(setvars "" _b EC_url_bkup EC_hash DL_hash DL_url_bkup MRC_refcode_gbe \
CONFIG_VGA_BIOS_FILE CONFIG_VGA_BIOS_ID CONFIG_KBC1126_FW1 release DL_url \
CONFIG_INCLUDE_SMSC_SCH5545_EC_FW CONFIG_SMSC_SCH5545_EC_FW_FILE nukemode \
CONFIG_IFD_BIN_PATH CONFIG_MRC_FILE CONFIG_HAVE_REFCODE_BLOB cbfstoolref \
CONFIG_REFCODE_BLOB_FILE)"
CONFIG_REFCODE_BLOB_FILE vcfg)"
vendor_download()
{
export PATH="$PATH:/sbin"
[ $# -gt 0 ] || $err "No argument given"
board="$1"
_b="${board%%_*mb}" # shorthand (no duplication per rom size)
boarddir="$cbcfgsdir/$board" && getcfg && scan_config "$_b" \
"config/vendor" && bootstrap && getfiles; return 0
board="$1"; boarddir="$cbcfgsdir/$board"
getcfg && bootstrap && getfiles; return 0
}
getcfg()
{
[ -d "$boarddir" ] || $err "Target '$board' not defined."
eval `setcfg "$boarddir/target.cfg"`
[ -z "$vcfg" ] && printf "%s: vcfg unset\n" "$board" 1>&2 && return 1
check_defconfig "$boarddir" 1>"$tmpdir/vendorcfg.list" && return 1
while read -r cbcfgfile; do
set +u +e
. "$cbcfgfile" 2>/dev/null
set -u -e
set +u +e; . "$cbcfgfile" 2>/dev/null; set -u -e
done < "$tmpdir/vendorcfg.list"
. "$boarddir/target.cfg" 2>/dev/null
[ -z "$tree" ] && $err "getcfg $boarddir: tree undefined"
cbdir="src/coreboot/$tree"
@@ -58,9 +56,10 @@ getcfg()
for c in CONFIG_HAVE_MRC CONFIG_HAVE_ME_BIN CONFIG_KBC1126_FIRMWARE \
CONFIG_VGA_BIOS_FILE CONFIG_INCLUDE_SMSC_SCH5545_EC_FW; do
eval "[ \"\${$c}\" = \"/dev/null\" ] && continue"
eval "[ -z \"\${$c}\" ] || return 0"
eval "[ -z \"\${$c}\" ] && continue"
eval `setcfg "config/vendor/$vcfg/pkg.cfg"`; return 0
done
printf "Vendor files not needed for: %s\n" "$board" 1>&2 && return 1
printf "Vendor files not needed for: %s\n" "$board" 1>&2; return 1
}
bootstrap()
@@ -274,10 +273,7 @@ check_board()
fi
boarddir="$cbcfgsdir/$board"
[ -d "$boarddir" ] || $err "check_board: board $board missing"
[ -f "$boarddir/target.cfg" ] || \
$err "check_board $board: target.cfg missing"
. "$boarddir/target.cfg" 2>/dev/null
eval `setcfg "$boarddir/target.cfg"`
[ -z "$tree" ] && $err "check_board $board: tree undefined"; return 0
}