unos-repository

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

build-all.sh (2484B)


      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 # shellcheck disable=SC1091
     21 . "${ROOT}/mk/channels.inc"
     22 
     23 ARCH="x86_64"
     24 PKGS=""
     25 CHANNEL="${UNOS_CHANNEL:-lts}"
     26 for a in "$@"; do
     27 	case "$a" in
     28 		--dry-run)    DRY=1 ;;
     29 		--skip-built) SKIP=1 ;;
     30 		--arch)       ARCH="$2"; shift 2; continue ;;
     31 		--arch=*)     ARCH="${a#--arch=}"; continue ;;
     32 		--channel)    CHANNEL="$2"; shift 2; continue ;;
     33 		--channel=*)  CHANNEL="${a#--channel=}"; continue ;;
     34 		-h|--help)    sed -n '2,10p' "$0"; exit 0 ;;
     35 		-*)           echo "build-all.sh: unknown option: $a" >&2; exit 1 ;;
     36 		*)            PKGS="${PKGS} $a" ;;
     37 	esac
     38 done
     39 ARCH=$(chan_arch "${ARCH}")
     40 case "${ARCH}" in x86_64|aarch64) ;; *) die "unsupported ARCH: ${ARCH}" >&2; exit 1 ;; esac
     41 export ARCH
     42 export UNOS_CHANNEL="${CHANNEL}"
     43 REPODIR=$(chan_repodir "${CHANNEL}" "${ARCH}")
     44 
     45 msg() { printf '==> %s\n' "$*"; }
     46 die() { printf 'build-all.sh: error: %s\n' "$*" >&2; exit 1; }
     47 
     48 # Host tools are the root of the dependency graph: without them nothing builds.
     49 "${ROOT}/mk/bootstrap-host.sh" --check >/dev/null 2>&1 \
     50 	|| die "host tools missing or stale; run ./mk/bootstrap-host.sh"
     51 
     52 # shellcheck disable=SC2086
     53 ORDER=$("${ROOT}/mk/deps.sh" order ${PKGS}) || die "could not resolve build order"
     54 
     55 if [ "${DRY}" = "1" ]; then
     56 	printf '%s\n' "${ORDER}"
     57 	exit 0
     58 fi
     59 
     60 total=$(printf '%s\n' "${ORDER}" | wc -l | tr -d ' ')
     61 n=0
     62 built=0
     63 skipped=0
     64 
     65 for p in ${ORDER}; do
     66 	n=$((n + 1))
     67 	if [ "${SKIP}" = "1" ] && ls "${REPODIR}/${p}"-*.apk >/dev/null 2>&1; then
     68 		msg "[${n}/${total}] ${p}: already built, skipping"
     69 		skipped=$((skipped + 1))
     70 		continue
     71 	fi
     72 	msg "[${n}/${total}] ${p} (${ARCH})"
     73 	"${ROOT}/mk/build.sh" "${p}" "${ARCH}" || die "${p} failed"
     74 	built=$((built + 1))
     75 done
     76 
     77 msg "built ${built}, skipped ${skipped}, of ${total} (ARCH=${ARCH})"
     78 msg "now run ./mk/repo-index.sh ${ARCH} to refresh APKINDEX"