diff options
| author | Danilo M. <danix@danix.xyz> | 2026-07-13 10:18:39 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-07-13 10:18:39 +0200 |
| commit | b8281632a92d3b85db0beab8f43022180000720d (patch) | |
| tree | fabdd13149f9a7cae1338517911ccfe6d5c947d2 /.extras/test-build | |
| parent | 1a39e22ddfd989591620995284187fbfbbf93f91 (diff) | |
| download | sbo-slackbuilds-b8281632a92d3b85db0beab8f43022180000720d.tar.gz sbo-slackbuilds-b8281632a92d3b85db0beab8f43022180000720d.zip | |
test-build: port SBo lookup + dependency resolver
Diffstat (limited to '.extras/test-build')
| -rwxr-xr-x | .extras/test-build | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/.extras/test-build b/.extras/test-build index 4d3f158..fa24fa6 100755 --- a/.extras/test-build +++ b/.extras/test-build @@ -132,10 +132,106 @@ EOF fi } +# ============================================================================= +# SBo tree lookup +# ============================================================================= +# In this tool there is one active tree per run, but the resolver reads an array +# named SBO_TREE_ROOTS so the ported logic and its self-check match sbo-batch-test. +# main() sets SBO_TREE_ROOTS=("$ACTIVE_TREE") after require_config. +declare -a SBO_TREE_ROOTS=() + +find_slackbuild_dir() { + local prog="$1" root d + for root in "${SBO_TREE_ROOTS[@]}"; do + [[ -d "$root" ]] || continue + for d in "$root"/*/"$prog"; do + if [[ -d "$d" && -f "$d/$prog.info" ]]; then + echo "$d"; return 0 + fi + done + done + return 1 +} + +category_of() { basename "$(dirname "$1")"; } +pkg_key() { echo "$(category_of "$1")/$(basename "$1")"; } + +read_requires() { + local info="$1" + # shellcheck disable=SC1090 + ( set +u; source "$info"; echo "${REQUIRES:-}" ) +} + +version_of() { + local dir="$1" + local info="$dir/$(basename "$dir").info" + [[ -f "$info" ]] || return + local v; v="$(grep -m1 '^VERSION=' "$info" | cut -d'"' -f2)" + echo "$v" +} + +# ============================================================================= +# DEPENDENCY RESOLUTION (topo sort + cycle detection, LOCAL tree only) +# ============================================================================= +declare -a RESOLVED_ORDER=() +declare -A UNMET=() +declare -a CYCLES=() +declare -A HAS_README=() +declare -A _vstate=() + +# Is a prog already present in the container base? Overridden at build time to +# consult the image; in resolution we treat "in base" as a callback so the pure +# topo logic stays testable. Default: not in base (self-check has no base db). +installed_in_base() { return 1; } + +_resolve_visit() { + local dir="$1" parent="$2" + local key; key="$(basename "$dir")" + + if [[ "${_vstate[$dir]:-}" == "1" ]]; then return 0; fi + if [[ "${_vstate[$dir]:-}" == "0" ]]; then + CYCLES+=("cycle involving $key (pulled in via $parent)") + return 1 + fi + _vstate["$dir"]=0 + + local info="$dir/$(basename "$dir").info" + local req tok depdir rc=0 + req="$(read_requires "$info")" + for tok in $req; do + if [[ "$tok" == "%README%" ]]; then + HAS_README["$dir"]=1 + continue + fi + if depdir="$(find_slackbuild_dir "$tok")"; then + _resolve_visit "$depdir" "$key" || rc=1 + elif installed_in_base "$tok"; then + : + else + UNMET["$tok"]="needed by $key" + rc=1 + fi + done + + _vstate["$dir"]=1 + RESOLVED_ORDER+=("$dir") + return $rc +} + +resolve_target() { + local dir="$1" + RESOLVED_ORDER=() + CYCLES=() + UNMET=() + _vstate=() + _resolve_visit "$dir" "(top)" +} + main() { parse_args "$@" init_color require_config + SBO_TREE_ROOTS=("$ACTIVE_TREE") } main "$@" |
