#!/usr/bin/env bash # brintsysroot-check — is the sysroot present, and is it current? # # The one question this toolchain answers about its own libc state, from # outside. Before it existed the consuming repository asked by running # sysroot/libc-stamp.sh directly, and that script is internal machinery: it # takes MUSL_BUILD and GLIBC_BUILD from its environment because the sysroot # makefiles are what export them, so a caller who had neither got # "MUSL_BUILD is not set" and a distro build that stopped before it started. # Every part of that was toolchain detail leaking across a repository boundary # — a script name, an environment contract, a directory layout — and each part # is free to change here without the consumer being able to know. # # So the consumer asks this instead. It resolves the sysroot the same way every # other front door does (libexec/config.sh), refuses by name when it cannot, # and hands the question to the makefile that already knows the build-tree # variables the answer needs. # # It BUILDS NOTHING. Ask as often as you like. # # Usage: # brintsysroot-check both libc arms # brintsysroot-check musl the musl arm alone (sysroot tree, both pools) # brintsysroot-check glibc the glibc arm alone # # Each product is reported as current, STALE, NEVER BUILT or REFUSED, with the # target that produces it. Never built and stale are kept apart on purpose: # they are different problems with different repairs, and a caller told only # "not current" picks between a two-minute pool refresh and an hours-long full # build with nothing to go on. Exit status is 0 when everything asked about is # current and non-zero when it is not; WHICH problem it is, is the report's # job, not the exit code's — a tree with one arm never built and the other # stale has no single worst class to encode. set -euo pipefail # readlink -f, not dirname alone: these front doors are meant to be symlinked # into a prefix on PATH, and a symlink's dirname is the prefix, not this repo. source "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/../libexec/config.sh" target=check case "${1:-}" in '') ;; musl) target=check-musl ;; glibc) target=check-glibc ;; -h|--help) echo "usage: brintsysroot-check [musl|glibc]" echo " Reports whether each durable libc product in \$BRINTIUM_SYSROOT is current," echo " stale, never built, or refused because its source checkout is dirty, and" echo " names the target that produces each one. Builds nothing. No argument" echo " reports both arms." exit 0 ;; *) brintium_fatal "brintsysroot-check: '$1' is not a libc arm. It takes musl, glibc, or no argument at all (both). Refusing rather than checking both anyway: a caller that meant one arm and typed it wrong would read a green about the other one as an answer about theirs." ;; esac [ $# -le 1 ] || brintium_fatal \ "brintsysroot-check takes at most one argument, the libc arm; got $#. There is nothing else to pass — the sysroot it reports on is the one BRINTIUM_SYSROOT resolves to." brintium_require sysroot # -C the CHECKOUT's sysroot directory, which is where the makefile is, while # BRINTIUM_SYSROOT — exported above — is where the artifacts are. The two are # the same directory by default and need not be: a staged tree elsewhere is # still reported on by the makefile that produced it, and never by a makefile # that happens to sit beside the artifacts. mk="$BRINTIUM/sysroot/Makefile" [ -f "$mk" ] || brintium_fatal \ "'$mk' does not exist, so there is no sysroot build to ask. BRINTIUM='$BRINTIUM' resolved to a checkout with libexec/config.sh but no sysroot/Makefile under it — that is a partial or truncated clone, not a configuration problem." exec make --no-print-directory -C "$BRINTIUM/sysroot" "$target"