aboutsummaryrefslogtreecommitdiffstats
path: root/.extras
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-07-13 10:44:56 +0200
committerDanilo M. <danix@danix.xyz>2026-07-13 10:44:56 +0200
commit44f03382065d2742d474fa45b13d07189bae9767 (patch)
tree66bdbdd87703be8bd5b3b1d62d63061b4c642d0c /.extras
parentf4dff4e6d537700314736dc1f28a53e3ab0e1da9 (diff)
downloadsbo-slackbuilds-44f03382065d2742d474fa45b13d07189bae9767.tar.gz
sbo-slackbuilds-44f03382065d2742d474fa45b13d07189bae9767.zip
test-build: container build step (build_one via docker)
Diffstat (limited to '.extras')
-rwxr-xr-x.extras/test-build171
1 files changed, 171 insertions, 0 deletions
diff --git a/.extras/test-build b/.extras/test-build
index 706d5ab..325f5c4 100755
--- a/.extras/test-build
+++ b/.extras/test-build
@@ -389,6 +389,177 @@ depends_on_failed() {
return 1
}
+# lint_pkg <txz> <logf> -> run sbopkglint on a built package. Host-side, target
+# only, fail-soft (skip if absent, never change SUCCESS).
+lint_pkg() {
+ local txz="$1" logf="$2"
+ if ! command -v sbopkglint >/dev/null 2>&1; then
+ echo " sbopkglint not installed on host, skipping lint"
+ return 0
+ fi
+ echo " sbopkglint $(basename "$txz") ..."
+ echo "===== sbopkglint: $(basename "$txz") =====" >> "$logf"
+ local out rc
+ out="$(sbopkglint "$txz" 2>&1)"; rc=$?
+ printf '%s\n' "$out" >> "$logf"
+ if [[ $rc -eq 0 ]]; then
+ echo " lint: ${C_GRN}clean${C_RST}"
+ else
+ echo " lint: ${C_RED}findings${C_RST} (see $(basename "$logf")):"
+ printf '%s\n' "$out" | sed 's/^/ /'
+ fi
+}
+
+# build_one <slackbuild-dir> <is_target 0|1> [container-name]
+# Runs the build in a throwaway container. Sets ST_STATUS/ST_REASON/ST_TIME.
+# Successful builds copy their package to a host workdir; deps are cached and
+# the target is linted. Returns 0 on SUCCESS/CACHED, 1 otherwise.
+build_one() {
+ local dir="$1" is_target="${2:-0}"
+ local prog cat key
+ prog="$(basename "$dir")"; cat="$(category_of "$dir")"; key="$cat/$prog"
+ local logf="$RUN_DIR/${cat}_${prog}.log"
+ local start; start=$(date +%s)
+ local version; version="$(version_of "$dir")"
+
+ [[ "${HAS_README[$dir]:-}" == "1" ]] && ST_README["$key"]=1
+
+ # Dep with a version-matching cached package: installpkg it into the shared
+ # dep-package dir; no build. The target never takes this path.
+ if [[ "$is_target" != "1" ]]; then
+ local cached; cached="$(cache_path "$cat" "$prog" "$version")"
+ if [[ -n "$cached" ]]; then
+ cp -a "$cached" "$DEPS_DIR/"
+ {
+ echo "===== test-build: $prog (from cache) ====="
+ echo "cached package: $(basename "$cached")"
+ } >> "$logf"
+ ST_TIME["$key"]=$(( $(date +%s) - start ))
+ ST_STATUS["$key"]="CACHED"
+ return 0
+ fi
+ fi
+
+ # Build in a container. Mounts:
+ # $dir -> /sbo/pkg (ro, the SlackBuild)
+ # $DEPS_DIR -> /sbo/deps (rw, already-built dep .txz to installpkg first)
+ # $BUILD_OUT -> /sbo/out (rw, where the built package is copied out)
+ # The in-container script installs any deps present, then builds the target,
+ # writes a status token to /sbo/out/$prog.status, and copies the package out.
+ local statf="$BUILD_OUT/$prog.status"
+ rm -f "$statf"
+
+ # fetch deps (removed from -current tree): let the container's sbopkg build
+ # them first. FETCH_DEPS is the set collected during resolution.
+ local fetch_list=""
+ local fp
+ for fp in "${!FETCH_DEPS[@]}"; do fetch_list+="$fp "; done
+
+ docker run --rm \
+ -v "$dir":/sbo/pkg:ro \
+ -v "$DEPS_DIR":/sbo/deps \
+ -v "$BUILD_OUT":/sbo/out \
+ -e PROG="$prog" \
+ -e FETCH_LIST="$fetch_list" \
+ "$ACTIVE_IMAGE" /bin/bash -s >>"$logf" 2>&1 <<'CONTAINER_EOF'
+set -uo pipefail
+prog="$PROG"
+statf="/sbo/out/$prog.status"
+
+# 0. install already-built dependency packages (order guaranteed by the host).
+for d in /sbo/deps/*.t?z; do
+ [[ -e "$d" ]] || continue
+ installpkg --terse "$d" || { echo "INSTALL-FAILED (dep $d)"; echo INSTALL-FAILED > "$statf"; exit 1; }
+done
+
+# 0b. fetch-from-SBo deps via sbopkg (removed from the -current tree).
+for f in $FETCH_LIST; do
+ echo "sbopkg-building fetch dep: $f"
+ sbopkg -B -i "$f" || { echo "BUILD-FAILED (fetch dep $f)"; echo BUILD-FAILED > "$statf"; exit 1; }
+done
+
+# copy the SlackBuild out of the read-only mount so it can write there.
+cp -a /sbo/pkg /sbo/build
+cd /sbo/build || { echo BUILD-FAILED > "$statf"; exit 1; }
+. ./"$prog".info
+
+export OUTPUT=/sbo/out
+mkdir -p "$OUTPUT"
+
+echo "===== test-build: $prog ====="
+echo "PRGNAM=${PRGNAM:-$prog} VERSION=${VERSION:-?} BUILD=${BUILD:-?} TAG=${TAG:-?}"
+echo "uname -m: $(uname -m) OUTPUT=$OUTPUT"
+echo "REQUIRES=${REQUIRES:-}"
+echo "================================="
+
+if [ "$(uname -m)" = "x86_64" ] && [ -n "${DOWNLOAD_x86_64:-}" ] && [ "${DOWNLOAD_x86_64}" != "UNSUPPORTED" ] && [ "${DOWNLOAD_x86_64}" != "UNTESTED" ]; then
+ DL="$DOWNLOAD_x86_64"; MD="$MD5SUM_x86_64"
+else
+ DL="$DOWNLOAD"; MD="$MD5SUM"
+fi
+
+for u in $DL; do
+ wget -c --tries=3 "$u" || { echo DOWNLOAD-FAILED > "$statf"; exit 1; }
+done
+
+set -- $MD
+for u in $DL; do
+ f="$(basename "$u")"
+ want="$1"; shift
+ got="$(md5sum "$f" | cut -d' ' -f1)"
+ if [ "$got" != "$want" ]; then
+ echo "MD5 mismatch on $f: want $want got $got"
+ echo MD5-MISMATCH > "$statf"; exit 1
+ fi
+done
+
+chmod +x ./"$prog".SlackBuild
+if ! ./"$prog".SlackBuild; then
+ echo BUILD-FAILED > "$statf"; exit 1
+fi
+
+pkg="$(ls -t "$OUTPUT"/"$prog"-*.t?z 2>/dev/null | head -n1)"
+if [ -z "$pkg" ]; then
+ echo "No package produced in $OUTPUT"
+ echo BUILD-FAILED > "$statf"; exit 1
+fi
+if ! installpkg --terse "$pkg"; then
+ echo INSTALL-FAILED > "$statf"; exit 1
+fi
+echo "===== installed files: $(basename "$pkg") ====="
+pkgname="$(basename "$pkg")"; pkgname="${pkgname%.t?z}"
+cat "/var/log/packages/$pkgname" 2>/dev/null || echo "(package db entry not found)"
+echo "================================="
+echo SUCCESS > "$statf"
+CONTAINER_EOF
+
+ local status="BUILD-FAILED"
+ [[ -f "$statf" ]] && status="$(cat "$statf")"
+ ST_TIME["$key"]=$(( $(date +%s) - start ))
+ ST_STATUS["$key"]="$status"
+
+ if [[ "$status" == "SUCCESS" ]]; then
+ # locate the built package copied to the host workdir
+ local built newest=""
+ for built in "$BUILD_OUT/${prog}"-*.t?z; do
+ [[ -e "$built" ]] || continue
+ [[ -z "$newest" || "$built" -nt "$newest" ]] && newest="$built"
+ done
+ if [[ -n "$newest" ]]; then
+ if [[ "$is_target" != "1" ]]; then
+ cache_store "$cat" "$prog" "$newest"
+ # make the dep available to later builds in this run
+ cp -a "$newest" "$DEPS_DIR/"
+ else
+ lint_pkg "$newest" "$logf"
+ fi
+ fi
+ return 0
+ fi
+ ST_REASON["$key"]="see $(basename "$logf")"
+ return 1
+}
+
main() {
parse_args "$@"
init_color