|
| 1 | +#!/bin/sh |
| 2 | +# This file is part of KASLD - https://github.com/bcoles/kasld |
| 3 | +# |
| 4 | +# check-components-built — every component source produced a build artefact. |
| 5 | +# |
| 6 | +# The component recipe exits 0 whatever the compiler said, on purpose: with 118 |
| 7 | +# independent leaf targets, one that will not compile must not stop the other |
| 8 | +# 117 from being built and tested. What it does instead is REMOVE the target, so |
| 9 | +# a broken component becomes absent rather than stale and is not silently |
| 10 | +# exercised as the last binary that happened to compile. |
| 11 | +# |
| 12 | +# That leaves the failure to be noticed by something. Nothing noticed it. The |
| 13 | +# orchestrator finds components by scanning the directory, so an absent one is |
| 14 | +# simply a smaller set -- 117 components, reported as success -- and no guard |
| 15 | +# compared what was built against what exists in source. A component could stop |
| 16 | +# compiling and `make`, `make test` and `make cross` would all stay green. |
| 17 | +# |
| 18 | +# The recipe already writes the distinction to disk, so this reads it rather |
| 19 | +# than tracking anything of its own: |
| 20 | +# |
| 21 | +# non-empty file compiled |
| 22 | +# empty file arch-gated, skipped by the `#error "Architecture is not |
| 23 | +# supported"` path, which writes an empty target deliberately |
| 24 | +# absent the compiler failed |
| 25 | +# |
| 26 | +# A count is not used and must not be: a fixed expected number rots the moment a |
| 27 | +# component is added, which is the failure mode this file exists to prevent, one |
| 28 | +# level up. The source directory is the inventory and the build answers to it. |
| 29 | +# |
| 30 | +# Usage: tests/check-components-built (also run by `make test`) |
| 31 | +# --- |
| 32 | +# <bcoles@gmail.com> |
| 33 | + |
| 34 | +set -u |
| 35 | +ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd) |
| 36 | +# shellcheck source=tests/lib/guard-scope.sh |
| 37 | +. "$ROOT/tests/lib/guard-scope.sh" |
| 38 | + |
| 39 | +if [ -t 2 ] || [ -n "${KASLD_COLOR:-}" ]; then |
| 40 | + RED=$(printf '\033[31m'); GREEN=$(printf '\033[32m') |
| 41 | + YELLOW=$(printf '\033[33m'); RESET=$(printf '\033[0m') |
| 42 | +else |
| 43 | + RED=; GREEN=; YELLOW=; RESET= |
| 44 | +fi |
| 45 | + |
| 46 | +# The native triple, resolved the same way the build resolves it. Probing |
| 47 | +# build/*/ and taking the first that exists would pick a cross directory -- |
| 48 | +# i686 sorts before x86_64 -- and check a set this host never built. |
| 49 | +COMP= |
| 50 | +for t in "$(cc -dumpmachine 2>/dev/null)" "$(${CC:-cc} -dumpmachine 2>/dev/null)"; do |
| 51 | + [ -n "$t" ] || continue |
| 52 | + if [ -d "$ROOT/build/$t/components" ]; then |
| 53 | + COMP=$ROOT/build/$t/components |
| 54 | + break |
| 55 | + fi |
| 56 | +done |
| 57 | +[ -n "$COMP" ] || { |
| 58 | + printf '%scheck-components-built: SKIP%s (no native component build; run make first)\n' \ |
| 59 | + "$YELLOW" "$RESET" |
| 60 | + exit 0 |
| 61 | +} |
| 62 | + |
| 63 | +missing=; nsrc=0; nbuilt=0; nskipped=0 |
| 64 | +for src in "$ROOT"/src/components/*.c; do |
| 65 | + [ -f "$src" ] || continue |
| 66 | + nsrc=$((nsrc + 1)) |
| 67 | + name=$(basename "$src" .c) |
| 68 | + if [ ! -e "$COMP/$name" ]; then |
| 69 | + missing="$missing $name" |
| 70 | + elif [ -s "$COMP/$name" ]; then |
| 71 | + nbuilt=$((nbuilt + 1)) |
| 72 | + else |
| 73 | + nskipped=$((nskipped + 1)) |
| 74 | + fi |
| 75 | +done |
| 76 | + |
| 77 | +if [ -n "$missing" ]; then |
| 78 | + printf '%scheck-components-built: FAIL%s (component source with no build artefact)\n' \ |
| 79 | + "$RED" "$RESET" >&2 |
| 80 | + for m in $missing; do printf ' %s\n' "$m" >&2; done |
| 81 | + printf 'The compile failed and the recipe removed the target. Re-run make and\n' >&2 |
| 82 | + printf 'read the CC line for that component; the diagnostic is printed there even\n' >&2 |
| 83 | + printf 'though the build reports success.\n' >&2 |
| 84 | + exit 1 |
| 85 | +fi |
| 86 | + |
| 87 | +guard_scope "check-components-built" "$nsrc" 50 |
| 88 | + |
| 89 | +printf '%scheck-components-built: OK%s (%s built, %s architecture-gated, %s sources)\n' \ |
| 90 | + "$GREEN" "$RESET" "$nbuilt" "$nskipped" "$nsrc" |
0 commit comments