unified list command for all scripts

e.g. ./build boot roms list
./update blobs inject listboards
./build boot list
./build clean list

also this is now possible:
./build list
or maybe
./update list
^ would list directories in resources/scripts/build
and resources/scripts/update respectively

this script is added:
resources/scripts/build/command/options

call it like so, e.g.
./build command options resources/coreboot

this script is now used, for list functions in
other scripts.

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-08-27 14:14:49 +01:00
parent 93d2dcad2d
commit 9457d6be52
6 changed files with 52 additions and 72 deletions

View File

@ -51,17 +51,11 @@ main()
[ -d "${cfgsdir}" ] || err "unsupported project name" [ -d "${cfgsdir}" ] || err "unsupported project name"
shift 1 shift 1
targets="" targets=$(./build command options "${cfgsdir}")
if [ $# -gt 0 ]; then [ $# -gt 0 ] && targets=$@
targets=$@
else
for x in "${cfgsdir}/"*; do
[ -d "${x}" ] || continue
targets="${targets} ${x##*/}"
done
fi
[ -z "${targets}" ] && \ [ -z "${targets}" ] && \
err "No targets available for project: ${project}" err "No targets available for project: ${project}"
for x in ${targets}; do for x in ${targets}; do
rm -f "${cfgsdir}"/*/seen || err_rm_seen "main 2" rm -f "${cfgsdir}"/*/seen || err_rm_seen "main 2"
download_for_target "${x}" || \ download_for_target "${x}" || \

35
lbmk
View File

@ -48,6 +48,8 @@ main()
./.gitcheck || err "/.gitcheck call from main, in /lbmk" ./.gitcheck || err "/.gitcheck call from main, in /lbmk"
[ "${mode}" = "help" ] && usage ${0} && exit 0 [ "${mode}" = "help" ] && usage ${0} && exit 0
[ "${mode}" = "list" ] && ./build command options "${buildpath}" && \
exit 0
[ $# -lt 2 ] && usage ${0} && exit 1 [ $# -lt 2 ] && usage ${0} && exit 1
if [ "${mode}" = "dependencies" ]; then if [ "${mode}" = "dependencies" ]; then
@ -63,10 +65,10 @@ main()
case "${option}" in case "${option}" in
list) list)
printf "Options for mode '%s':\n\n" ${mode} ./build command options "${buildpath}/${mode}" ;;
listoptions "${mode}" ;;
all) all)
for option in $(listoptions "${mode}"); do for option in $(./build command options "${buildpath}/${mode}")
do
"${buildpath}/${mode}/${option}" $@ || \ "${buildpath}/${mode}/${option}" $@ || \
err "script fail: ${buildpath}/${mode}/${option} $@" err "script fail: ${buildpath}/${mode}/${option} $@"
done done
@ -99,19 +101,6 @@ install_dependencies()
printf "You must install AUR packages: %s\n" "${aur_notice}" 1>&2 printf "You must install AUR packages: %s\n" "${aur_notice}" 1>&2
} }
# Takes exactly one mode as parameter
listoptions()
{
options="n"
for option in "${buildpath}/${1}/"*; do
[ -f "${option}" ] || continue
printf '%s\n' ${option##*/}
options="y"
done
[ "${options}" = "y" ] || \
err "listoptions: No scripts present in directory ${buildpath}/${1}"
}
usage() usage()
{ {
progname=${0} progname=${0}
@ -119,7 +108,7 @@ usage()
USAGE: ${progname} <MODE> <OPTION> USAGE: ${progname} <MODE> <OPTION>
possible values for 'mode': possible values for 'mode':
$(listmodes) $(./build command options "${buildpath}/${mode}")
Example: ${progname} module all Example: ${progname} module all
Example: ${progname} module flashrom [static] Example: ${progname} module flashrom [static]
@ -130,16 +119,4 @@ usage()
EOF EOF
} }
listmodes()
{
modes="n"
for mode in "${buildpath}"/*; do
[ -d "${mode}" ] || continue
printf '%s\n' ${mode##*/}
modes="y"
done
[ "${modes}" = "y" ] || \
err "listmodes: No directories present in directory ${buildpath}"
}
main $@ main $@

View File

@ -42,7 +42,8 @@ main()
firstoption="${1}" firstoption="${1}"
[ "${firstoption}" = "help" ] && usage && exit 0 [ "${firstoption}" = "help" ] && usage && exit 0
[ "${firstoption}" = "list" ] && listboards && exit 0 [ "${firstoption}" = "list" ] && \
./build command options resources/coreboot && exit 0
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case ${1} in case ${1} in
@ -65,8 +66,8 @@ main()
printf "Building %s ROM images\n" "${projectname}" printf "Building %s ROM images\n" "${projectname}"
if [ "${firstoption}" = "all" ]; then if [ "${firstoption}" = "all" ]; then
for boardname in $(listboards); do for target in $(./build command options resources/coreboot); do
buildrom "${boardname}" || err "build/roms (1): error" buildrom "${target}" || err "build/roms (1): error"
done done
else else
for board in ${boards}; do for board in ${boards}; do
@ -80,7 +81,7 @@ main()
usage() usage()
{ {
cat <<- EOF cat <<- EOF
USAGE: ./build boot roms boardname USAGE: ./build boot roms target
To build *all* boards, do this: ./build boot roms all To build *all* boards, do this: ./build boot roms all
To list *all* boards, do this: ./build boot roms list To list *all* boards, do this: ./build boot roms list
@ -94,23 +95,13 @@ usage()
./build boot roms x200_8mb x60 ./build boot roms x200_8mb x60
./build boot roms x60 -p grub -d corebootfb -k usqwerty ./build boot roms x60 -p grub -d corebootfb -k usqwerty
possible values for 'boardname': possible values for 'target':
$(listboards) $(./build command options "resources/coreboot")
Refer to the ${projectname} documentation for more information. Refer to the ${projectname} documentation for more information.
EOF EOF
} }
listboards()
{
for boarddir in resources/coreboot/*; do
[ -d "${boarddir}" ] || continue
board="${boarddir##resources/coreboot/}"
board="${board%/}"
printf '%s\n' "${board##*/}"
done
}
# Build ROM images for supported boards # Build ROM images for supported boards
buildrom() { buildrom() {
[ -d "resources/coreboot/${1}/" ] || \ [ -d "resources/coreboot/${1}/" ] || \

View File

@ -0,0 +1,31 @@
#!/usr/bin/env sh
# Copyright (c) 2023 Leah Rowe <info@minifree.org>
# SPDX-License-Identifier: MIT
. "include/err.sh"
items=1
main()
{
[ $# -gt 0 ] || \
err "No argument given"
listitems "${1}" || err "No items present under: ${1}"
}
listitems()
{
[ -d "${1}" ] || \
err "Directory not does exist: ${1}"
for x in "${1}/"*; do
# -e used because this is for files *or* directories
[ -e "${x}" ] || continue
[ "${x##*/}" = "build.list" ] && continue
printf "%s\n" "${x##*/}"
items=0
done
return ${items}
}
main $@

View File

@ -76,17 +76,13 @@ main()
[ -f "${listfile}" ] || fail "list file, ${listfile}, does not exist" [ -f "${listfile}" ] || fail "list file, ${listfile}, does not exist"
# Build for all targets if no argument is given # Build for all targets if no argument is given
if [ "$#" -eq 0 ]; then targets=$(./build command options "${cfgsdir}")
for target_dir in "${cfgsdir}"/*; do [ $# -gt 0 ] && targets=$@
[ -d "${target_dir}/config/" ] || continue
set -- "$@" "${target_dir#${cfgsdir}/}"
done
fi
[ -d "${elfdir}" ] || [ "${mode}" != "all" ] || \ [ -d "${elfdir}" ] || [ "${mode}" != "all" ] || \
mkdir -p "${elfdir}/" || fail "can't create directory ${elfdir}" mkdir -p "${elfdir}/" || fail "can't create directory ${elfdir}"
for x in "$@"; do for x in ${targets}; do
target="${x}" target="${x}"
printf "Running 'make %s' for project '%s, target '%s''\n" \ printf "Running 'make %s' for project '%s, target '%s''\n" \
"${mode}" "${project}" "${target}" "${mode}" "${project}" "${target}"

View File

@ -44,7 +44,8 @@ main()
sname="${0}" sname="${0}"
[ $# -lt 1 ] && err "No options specified." [ $# -lt 1 ] && err "No options specified."
[ "${1}" = "listboards" ] && listboards && exit 0 [ "${1}" = "listboards" ] && \
./build command options resources/coreboot && exit 0
archive="${1}" archive="${1}"
@ -345,16 +346,6 @@ modify_gbe()
rm -f "${_gbe_tmp}" rm -f "${_gbe_tmp}"
} }
listboards()
{
for boarddir in "${cbcfgsdir}"/*; do
[ -d "${boarddir}" ] || continue
board="${boarddir##${cbcfgsdir}/}"
board="${board%/}"
printf "%s\n" "${board##*/}"
done
}
usage() usage()
{ {
cat <<- EOF cat <<- EOF