unos-repository

APK repository for unos
git clone git://git.finwo.net/misc/unos-repository
Log | Files | Refs | README

build-all.sh (2244B)


      1 #!/bin/sh
      2 # mk/build-all.sh - build packages in dependency order.
      3 #
      4 #   ./mk/build-all.sh                 every package, correctly ordered
      5 #   ./mk/build-all.sh gptfdisk        that package and everything it needs
      6 #   ./mk/build-all.sh --skip-built    don't rebuild packages already in the repo
      7 #   ./mk/build-all.sh --dry-run       print the order, build nothing
      8 #
      9 # Order comes from mk/deps.sh, which derives it from each template's
     10 # `makedepends`. Before this existed, build order lived only in the head of
     11 # whoever was driving the build, which is precisely what a CI runner does not
     12 # have.
     13 set -eu
     14 
     15 HERE=$(cd "$(dirname "$0")" && pwd)
     16 ROOT=$(cd "${HERE}/.." && pwd)
     17 
     18 DRY=0
     19 SKIP=0
     20 ARCH="x86_64"
     21 PKGS=""
     22 for a in "$@"; do
     23 	case "$a" in
     24 		--dry-run)    DRY=1 ;;
     25 		--skip-built) SKIP=1 ;;
     26 		--arch)       ARCH="$2"; shift 2; continue ;;
     27 		--arch=*)     ARCH="${a#--arch=}"; continue ;;
     28 		-h|--help)    sed -n '2,10p' "$0"; exit 0 ;;
     29 		-*)           echo "build-all.sh: unknown option: $a" >&2; exit 1 ;;
     30 		*)            PKGS="${PKGS} $a" ;;
     31 	esac
     32 done
     33 case "${ARCH}" in arm64) ARCH=aarch64 ;; esac
     34 case "${ARCH}" in x86_64|aarch64) ;; *) die "unsupported ARCH: ${ARCH}" >&2; exit 1 ;; esac
     35 export ARCH
     36 
     37 msg() { printf '==> %s\n' "$*"; }
     38 die() { printf 'build-all.sh: error: %s\n' "$*" >&2; exit 1; }
     39 
     40 # Host tools are the root of the dependency graph: without them nothing builds.
     41 "${ROOT}/mk/bootstrap-host.sh" --check >/dev/null 2>&1 \
     42 	|| die "host tools missing or stale; run ./mk/bootstrap-host.sh"
     43 
     44 # shellcheck disable=SC2086
     45 ORDER=$("${ROOT}/mk/deps.sh" order ${PKGS}) || die "could not resolve build order"
     46 
     47 if [ "${DRY}" = "1" ]; then
     48 	printf '%s\n' "${ORDER}"
     49 	exit 0
     50 fi
     51 
     52 total=$(printf '%s\n' "${ORDER}" | wc -l | tr -d ' ')
     53 n=0
     54 built=0
     55 skipped=0
     56 
     57 for p in ${ORDER}; do
     58 	n=$((n + 1))
     59 	if [ "${SKIP}" = "1" ] && ls "${ROOT}/build/repo/${ARCH}/${p}"-*.apk >/dev/null 2>&1; then
     60 		msg "[${n}/${total}] ${p}: already built, skipping"
     61 		skipped=$((skipped + 1))
     62 		continue
     63 	fi
     64 	msg "[${n}/${total}] ${p} (${ARCH})"
     65 	"${ROOT}/mk/build.sh" "${p}" "${ARCH}" || die "${p} failed"
     66 	built=$((built + 1))
     67 done
     68 
     69 msg "built ${built}, skipped ${skipped}, of ${total} (ARCH=${ARCH})"
     70 msg "now run ./mk/repo-index.sh ${ARCH} to refresh APKINDEX"