diff options
| -rwxr-xr-x | .extras/test-build | 42 | ||||
| -rw-r--r-- | .extras/test-logic.sh | 17 |
2 files changed, 56 insertions, 3 deletions
diff --git a/.extras/test-build b/.extras/test-build index 681ddf7..26bf2a4 100755 --- a/.extras/test-build +++ b/.extras/test-build @@ -158,6 +158,32 @@ find_slackbuild_dir() { category_of() { basename "$(dirname "$1")"; } pkg_key() { echo "$(category_of "$1")/$(basename "$1")"; } +# Resolve the TARGET to test from CWD or a path (repo-agnostic). The target is +# the SlackBuild you are editing, wherever it lives; its deps come from the +# configured SBo tree (see find_slackbuild_dir), NOT the other way around. +# - a path (absolute, or containing '/', or '.'/'./x'): use that dir directly +# - a bare name: ./<name>/ under CWD, else CWD itself if it IS <name>/ +# Prints the resolved absolute dir on success; returns 1 (with a message) if the +# dir has no matching <name>.info. +resolve_target_dir() { + local arg="$1" dir prog + if [[ "$arg" == /* || "$arg" == .* || "$arg" == */* ]]; then + dir="${arg%/}"; prog="$(basename "$dir")" + elif [[ -f "./$arg/$arg.info" ]]; then + dir="./$arg"; prog="$arg" + elif [[ "$(basename "$PWD")" == "$arg" && -f "./$arg.info" ]]; then + dir="."; prog="$arg" + else + echo "Target '$arg' not found: no ./$arg/$arg.info, and CWD is not $arg/." >&2 + return 1 + fi + if [[ ! -f "$dir/$prog.info" ]]; then + echo "Target dir '$dir' has no $prog.info (expected a SlackBuild package dir)." >&2 + return 1 + fi + ( cd "$dir" && pwd ) # emit absolute path +} + read_requires() { local info="$1" # shellcheck disable=SC1090 @@ -534,6 +560,16 @@ for u in $DL; do fi done +# Source /etc/profile.d so dep-provided env is live (google-go-lang sets GOROOT +# + PATH to its go here, rust-opt sets cargo, etc.). This heredoc runs in a +# non-login shell, which does NOT read profile.d, so a bare `go build` would +# otherwise pick the system gccgo instead of the installed google-go-lang. +set +u # profile.d scripts routinely reference unset vars +for pf in /etc/profile.d/*.sh; do + [ -r "$pf" ] && . "$pf" +done +set -u + chmod +x ./"$prog".SlackBuild if ! ./"$prog".SlackBuild; then echo BUILD-FAILED > "$statf"; exit 1 @@ -784,10 +820,10 @@ main() { mkdir -p "$RUN_DIR" : > "$RUN_DIR/build-order.txt" - # Single-package mode: resolve the name in the active tree. + # The target is the local SlackBuild under test (CWD or a path); its deps are + # resolved from the configured SBo tree during _resolve_visit. local tdir - if ! tdir="$(find_slackbuild_dir "$TARGET_ARG")"; then - echo "Program not found in the SBo tree ($ACTIVE_TREE): $TARGET_ARG" >&2 + if ! tdir="$(resolve_target_dir "$TARGET_ARG")"; then exit 1 fi diff --git a/.extras/test-logic.sh b/.extras/test-logic.sh index 0616c99..469ac1d 100644 --- a/.extras/test-logic.sh +++ b/.extras/test-logic.sh @@ -67,6 +67,23 @@ order="${order% }" resolve_target "$T/cat/d" [[ ${#UNMET[@]} -eq 1 ]] && ok "unmet-dep caught" || bad "unmet-dep missed" +# --- resolve_target_dir (target from CWD/path, NOT the SBo tree) ------------- +# Local package dir, separate from the fake SBo tree above. +LOCALREPO=$(mktemp -d); mkdir -p "$LOCALREPO/mypkg" +echo 'REQUIRES=""' > "$LOCALREPO/mypkg/mypkg.info" +# 1. absolute path +got="$(resolve_target_dir "$LOCALREPO/mypkg" 2>/dev/null)" +[[ "$got" == "$LOCALREPO/mypkg" ]] && ok "target: absolute path" || bad "abs path got [$got]" +# 2. bare name resolved under CWD (./mypkg/) +got="$(cd "$LOCALREPO" && resolve_target_dir "mypkg" 2>/dev/null)" +[[ "$got" == "$LOCALREPO/mypkg" ]] && ok "target: bare name in CWD" || bad "bare-in-cwd got [$got]" +# 3. CWD itself is the package +got="$(cd "$LOCALREPO/mypkg" && resolve_target_dir "mypkg" 2>/dev/null)" +[[ "$got" == "$LOCALREPO/mypkg" ]] && ok "target: CWD is the package" || bad "cwd-is-pkg got [$got]" +# 4. missing -> failure +resolve_target_dir "nosuchpkg" >/dev/null 2>&1 && bad "missing target should fail" || ok "target: missing fails" +rm -rf "$LOCALREPO" + resolve_target "$T/cat/e" [[ ${#CYCLES[@]} -ge 1 ]] && ok "cycle caught" || bad "cycle missed" |
