mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-20 05:36:23 +02:00
lbmk: unified execution on find commands
We have a lot of places in lbmk where the output of find is used, and then some function is executed on the result. This is messy, and bloats several of these functions. Now this is unified, into a new function: fx_ What fx_ does is execute a given function, for each result found, with the arguments for a find command appended. For example: find -name ".git" If you wanted to do: foo "$arg" Where "arg" is a search result from find, and you wanted to execute "foo" on each one, you would do: fx_ foo -name ".git" The find utility does have an -exec feature, but I've found that it only works for executables, not functions. fx_ does not return errors, so "foo" in this example would have to do its own error handling. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+18
-25
@@ -282,19 +282,18 @@ extract_tbfw()
|
|||||||
{
|
{
|
||||||
chkvars TBFW_size # size in bytes, matching TBFW's flash IC
|
chkvars TBFW_size # size in bytes, matching TBFW's flash IC
|
||||||
x_ mkdir -p tmp
|
x_ mkdir -p tmp
|
||||||
x_ rm -f tmp/tb.bin
|
|
||||||
find "$appdir" -type f -name "TBT.bin" > "tmp/tb.txt" || \
|
x_ rm -f tmp/tb.bin && fx_ copy_tbfw "$appdir" -type f -name "TBT.bin"
|
||||||
$err "extract_tbfw $_dest: Can't extract TBT.bin - $dontflash"
|
|
||||||
while read -r f; do
|
|
||||||
[ -f "$f" ] || continue
|
|
||||||
[ -L "$f" ] && continue
|
|
||||||
x_ cp "$f" "tmp/tb.bin"
|
|
||||||
break
|
|
||||||
done < "tmp/tb.txt"
|
|
||||||
x_ dd if=/dev/null of=tmp/tb.bin bs=1 seek=$TBFW_size
|
x_ dd if=/dev/null of=tmp/tb.bin bs=1 seek=$TBFW_size
|
||||||
x_ cp "tmp/tb.bin" "$_dest"
|
x_ cp "tmp/tb.bin" "$_dest"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copy_tbfw()
|
||||||
|
{
|
||||||
|
[ -f "$1" ] && [ ! -L "$1" ] && x_ cp "$1" "tmp/tb.bin" && return 1; :
|
||||||
|
}
|
||||||
|
|
||||||
extract_fspm()
|
extract_fspm()
|
||||||
{
|
{
|
||||||
copy_fsp M; :
|
copy_fsp M; :
|
||||||
@@ -419,16 +418,10 @@ patch_release_roms()
|
|||||||
hashfile="$_hashes" && break; :
|
hashfile="$_hashes" && break; :
|
||||||
done
|
done
|
||||||
|
|
||||||
x_ mkdir -p "tmp" && [ -L "tmp/rom.list" ] && \
|
x_ mkdir -p "tmp"
|
||||||
$err "'$archive' -> tmp/rom.list is a symlink - $dontflash"
|
|
||||||
|
|
||||||
find "$tmpromdir" -maxdepth 1 -type f -name "*.rom" > "tmp/rom.list" \
|
|
||||||
|| $err "'$archive' -> Can't make tmp/rom.list - $dontflash"
|
|
||||||
|
|
||||||
if readkconfig; then
|
if readkconfig; then
|
||||||
while read -r _xrom ; do
|
fx_ prep_rom "$tmpromdir" -maxdepth 1 -type f -name "*.rom"
|
||||||
process_release_rom "$_xrom" || break
|
|
||||||
done < "tmp/rom.list"
|
|
||||||
[ "$nukemode" != "nuke" ] || \
|
[ "$nukemode" != "nuke" ] || \
|
||||||
printf "Make sure you inserted vendor files: %s\n" \
|
printf "Make sure you inserted vendor files: %s\n" \
|
||||||
"$vguide" > "$tmpromdir/README.md" || :
|
"$vguide" > "$tmpromdir/README.md" || :
|
||||||
@@ -462,7 +455,7 @@ patch_release_roms()
|
|||||||
"$archive" || $err "'$archive' -> Can't overwrite - $dontflash"; :
|
"$archive" || $err "'$archive' -> Can't overwrite - $dontflash"; :
|
||||||
}
|
}
|
||||||
|
|
||||||
process_release_rom()
|
prep_rom()
|
||||||
{
|
{
|
||||||
_xrom="$1"
|
_xrom="$1"
|
||||||
_xromname="${1##*/}"
|
_xromname="${1##*/}"
|
||||||
@@ -578,13 +571,7 @@ modify_mac()
|
|||||||
[ "$new_mac" != "restore" ] && x_ make -C util/nvmutil && \
|
[ "$new_mac" != "restore" ] && x_ make -C util/nvmutil && \
|
||||||
x_ "$nvm" tmp/gbe setmac "$new_mac"
|
x_ "$nvm" tmp/gbe setmac "$new_mac"
|
||||||
|
|
||||||
find "$tmpromdir" -maxdepth 1 -type f -name "*.rom" > "tmp/rom.list" \
|
fx_ newmac "$tmpromdir" -maxdepth 1 -type f -name "*.rom"
|
||||||
|| $err "'$archive' -> Can't make tmp/rom.list - $dontflash"
|
|
||||||
|
|
||||||
while read -r _xrom; do
|
|
||||||
e "$_xrom" f && xchanged="y" && x_ \
|
|
||||||
"$ifdtool" $ifdprefix -i GbE:tmp/gbe "$_xrom" -O "$_xrom"
|
|
||||||
done < "tmp/rom.list"
|
|
||||||
|
|
||||||
printf "\nGbE NVM written to '%s':\n" "$archive"
|
printf "\nGbE NVM written to '%s':\n" "$archive"
|
||||||
x_ "$nvm" tmp/gbe dump | grep -v "bytes read from file" || :
|
x_ "$nvm" tmp/gbe dump | grep -v "bytes read from file" || :
|
||||||
@@ -593,3 +580,9 @@ modify_mac()
|
|||||||
printf "\nDefault GbE file '%s' written, unmodified.\n" \
|
printf "\nDefault GbE file '%s' written, unmodified.\n" \
|
||||||
"${CONFIG_GBE_BIN_PATH##*../}"; :
|
"${CONFIG_GBE_BIN_PATH##*../}"; :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newmac()
|
||||||
|
{
|
||||||
|
e "$1" f && xchanged="y" && x_ \
|
||||||
|
"$ifdtool" $ifdprefix -i GbE:tmp/gbe "$1" -O "$1"; :
|
||||||
|
}
|
||||||
|
|||||||
@@ -128,6 +128,17 @@ setvars()
|
|||||||
printf "%s\n" "${_setvars% }"
|
printf "%s\n" "${_setvars% }"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fx_()
|
||||||
|
{
|
||||||
|
fd="`mktemp`"
|
||||||
|
xx="$1" && shift 1
|
||||||
|
find "$@" | sort > "$fd" || $err "!find $(echo "$@") > \"$fd\""
|
||||||
|
while read -r fx; do
|
||||||
|
"$xx" "$fx" || break; :
|
||||||
|
done < "$fd"
|
||||||
|
x_ rm -f "$fd"
|
||||||
|
}
|
||||||
|
|
||||||
x_()
|
x_()
|
||||||
{
|
{
|
||||||
[ $# -lt 1 ] || "$@" || $err "Unhandled error for: $(echo "$@")"; :
|
[ $# -lt 1 ] || "$@" || $err "Unhandled error for: $(echo "$@")"; :
|
||||||
|
|||||||
@@ -278,20 +278,9 @@ check_project_hashes()
|
|||||||
[ ! -f "$XBMK_CACHE/hash/$project$tree" ] || \
|
[ ! -f "$XBMK_CACHE/hash/$project$tree" ] || \
|
||||||
read -r old_pjhash < "$XBMK_CACHE/hash/$project$tree"
|
read -r old_pjhash < "$XBMK_CACHE/hash/$project$tree"
|
||||||
|
|
||||||
x_ rm -f "$xbmktmp/project.list" "$xbmktmp/project.hash" \
|
x_ rm -f "$xbmktmp/project.hash"
|
||||||
"$xbmktmp/project.tmp"
|
fx_ create_project_hash "$datadir" "$configdir/$tree" "$mdir" \
|
||||||
x_ touch "$xbmktmp/project.tmp" "$xbmktmp/project.hash"
|
-type f -not -path "*/.git*/*"
|
||||||
|
|
||||||
for rmchk in "$datadir" "$configdir/$tree" "$mdir"; do
|
|
||||||
[ ! -d "$rmchk" ] || find "$rmchk" -type f -not -path \
|
|
||||||
"*/.git*/*" >> "$xbmktmp/project.tmp" || $err "!fh $rmchk"
|
|
||||||
done
|
|
||||||
sort "$xbmktmp/project.tmp" > "$xbmktmp/project.list" || $err "!pj srt"
|
|
||||||
|
|
||||||
while read -r rmchk; do
|
|
||||||
[ ! -f "$rmchk" ] || x_ sha512sum "$rmchk" | awk \
|
|
||||||
'{print $1}' >> "$xbmktmp/project.hash" || $err "!h $rmchk"
|
|
||||||
done < "$xbmktmp/project.list"
|
|
||||||
|
|
||||||
pjhash="$(sha512sum "$xbmktmp/project.hash" | awk '{print $1}')" || :
|
pjhash="$(sha512sum "$xbmktmp/project.hash" | awk '{print $1}')" || :
|
||||||
[ "$pjhash" != "$old_pjhash" ] && badhash="y"
|
[ "$pjhash" != "$old_pjhash" ] && badhash="y"
|
||||||
@@ -304,6 +293,12 @@ check_project_hashes()
|
|||||||
"elf/$project/$tree" "elf/$project/$target"; :
|
"elf/$project/$tree" "elf/$project/$target"; :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_project_hash()
|
||||||
|
{
|
||||||
|
[ ! -f "$1" ] || x_ sha512sum "$1" | awk \
|
||||||
|
'{print $1}' >> "$xbmktmp/project.hash" || $err "!h $1"; :
|
||||||
|
}
|
||||||
|
|
||||||
check_cross_compiler()
|
check_cross_compiler()
|
||||||
{
|
{
|
||||||
xgccargs="UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS"
|
xgccargs="UPDATED_SUBMODULES=1 CPUS=$XBMK_THREADS"
|
||||||
|
|||||||
Reference in New Issue
Block a user