build-data-lines.sh (2385B)
1 #!/usr/bin/env bash 2 # Example composition of the shared build/configure/file commands. 3 # 4 # Goal: prepare a file processor that drops empty and #-prefixed lines without 5 # compiling source, constructing workers, or resolving aliases on deployment. 6 # COMPILER_DIGEST is a caller-declared identity; see docs/consumers.md for its 7 # recipe. Each phase gets its own PHASE_SECONDS deadline. STORE holds the CAS. 8 # 9 # < bash demos/consumers/data-lines/build-data-lines.sh /tmp/scp-lines "$COMPILER_DIGEST" 240 10 # > code/build/configuration pins, followed by file-manifest=<hash> 11 set -euo pipefail 12 if [[ $# != 3 ]]; then 13 printf 'Usage: %s STORE COMPILER_DIGEST PHASE_SECONDS\n' "$0" >&2 14 exit 2 15 fi 16 store="$1"; compiler="$2"; seconds="$3" 17 repo="$(cd "$(dirname "$0")/../../.." && pwd)" 18 bootstrap="${SCP_BOOTSTRAP:-$repo/.bootstrap-run/scp-bootstrap}" 19 tricu="${TRICU:-$repo/result/bin/tricu}" 20 # 1. Build reusable entries and invoke ONLY configureData. That SCP export 21 # supplies splitter/predicate/filter/application state; this shell does not 22 # duplicate the wiring. The returned invocations manifest contains dataLines, 23 # a callable bytes -> Result [line], rather than a file reader. 24 built="$(bash "$repo/demos/consumers/configurations/build-configurations.sh" "$store" "$compiler" "$seconds" configureData)" 25 printf '%s\n' "$built" 26 invocations="$(printf '%s\n' "$built" | sed -n 's/^invocations=//p')" 27 # 2. Bind that callable to the shared file IO/presentation adapter. The label 28 # affects displayed output, not the filtering rule. file-manifest identifies 29 # the complete processFile callable, including its already configured program. 30 "$tricu" scp file --bootstrap "$bootstrap" --store "$store" --seconds "$seconds" \ 31 --invocations "$invocations" --entry dataLines --label data-lines 32 # 3. Deployment is a separate command. Use the printed file-manifest hash: 33 # < result/bin/tricu scp run-file --store /tmp/scp-lines --seconds 60 --manifest FILE_MANIFEST_HASH --input-file demos/consumers/data-lines/data-lines-input.txt 34 # > data-lines=2 35 # > first=alpha 36 # > [t t, ["alpha", "beta"]] 37 # Try an empty file: success has zero lines and first=<none>. Try a missing 38 # path: failure-stage=read explains the failure, and the Result stays an error 39 # rather than silently becoming an empty list. Application errors are data, 40 # not automatic shell exit failures. This processes whole files, not streams.