Files
alkane-os/third-party/flare-ui/scripts/vendor.sh
T
x ad31cfbafa Vendor flare-ui v0.2.9 and prove the schema-driven UI in an image
Spike, not the final UI: it answers whether flare-ui can drive Alkane OS's
on-box pages, and what it costs.

What works:

- schema/alkane-bb.json authors the sidebar as data (3 sections, 14 tabs);
- src/bin/ui-spike.rs renders it through flare_ui::nav + flare_ui::shell, so
  the unified sidebar, ordering and surface filtering come from the schema
  rather than from hand-written HTML;
- the render uses the shared bf- design tokens, the same ones the rest of the
  suite uses.

Size, measured rather than assumed (armv7, release, stripped):

  ui-baseline   323 KiB   (maud + serde_json, no flare-ui)
  ui-spike      771 KiB   (flare-ui + wschema + sha2)
  marginal      448 KiB

Vendoring: third-party/flare-ui is the full v0.2.9 tree pinned in
flare-ui/flare-ui.lock (a partial archive does not compile, since the crate
include_str!s assets from dash-editor/). vendor/ is re-generated as a cargo
directory source with the new registry dependencies (maud, sha2, typenum,
digest, generic-array, block-buffer, crypto-common, cfg-if, etc.) so the build
still works offline. third-party/README.md records how to re-pin.
2026-11-04 14:06:25 -06:00

185 lines
7.6 KiB
Bash

#!/usr/bin/env bash
# Keep a consumer's vendored copy of flare-ui pinned to one release tag.
# Run inside the consumer repository (flare, flare-edge). The consumer
# vendors this script too, as its own locked file.
#
# vendor.sh check every vendored file matches the lock
# vendor.sh check --upstream DIR ...and the lock matches that tag in a
# checkout of flare-ui
# vendor.sh sync DIR TAG copy the locked trees from TAG in DIR
# and rewrite the lock
#
# The lock is flare-ui.lock at the consumer's repository root:
#
# tag <vN.N.N>
# commit <40-hex commit the tag points at>
# tree <path in flare-ui> <path in this repository>
# <git blob id> <path in flare-ui> <path in this repository>
#
# `tree` lines are written by hand. `sync` expands each into one blob line
# per file. A tree whose source is a directory owns its destination
# directory: a file there that the lock does not name fails `check`. A tree
# whose source is a single file locks only that file.
#
# A consumer pins a release tag, never an untagged commit: `sync` refuses
# anything that is not a `v<N>.<N>.<N>` tag. The lock names no host; where
# flare-ui lives is the caller's business.
set -euo pipefail
die() { echo "vendor: $*" >&2; exit 1; }
root=$(git rev-parse --show-toplevel 2>/dev/null) || die "run inside the consumer repository"
lock="$root/flare-ui.lock"
tag_re='^v[0-9]+\.[0-9]+\.[0-9]+$'
trees() {
[ -f "$lock" ] || die "no flare-ui.lock at $root"
awk '$1 == "tree" { print $2, $3 }' "$lock"
}
entries() {
grep -Ev '^(#|tag |commit |tree |[[:space:]]*$)' "$lock" || true
}
locked_field() {
awk -v k="$1" '$1 == k { print $2 }' "$lock"
}
# Files under a vendored directory that the lock does not name.
unlisted() {
local seen=$1 src dest file rel
while read -r src dest; do
[ -d "$root/$dest" ] || continue
# A single-file tree has a file destination, skipped above.
while IFS= read -r -d '' file; do
rel=${file#"$root/"}
case " $seen " in *" $rel "*) ;; *) echo "$rel";; esac
done < <(find "$root/$dest" -type f -print0 -o -type l -print0)
done < <(trees)
}
check() {
local upstream="" bad=0 seen="" blob src dest have want tag commit
if [ "${1:-}" = "--upstream" ]; then
upstream=${2:?--upstream needs a flare-ui checkout}
fi
tag=$(locked_field tag)
[[ "$tag" =~ $tag_re ]] || die "flare-ui.lock has no vN.N.N tag line"
commit=$(locked_field commit)
[[ "$commit" =~ ^[0-9a-f]{40}$ ]] || die "flare-ui.lock has no 40-hex commit line"
if [ -n "$upstream" ]; then
want=$(git -C "$upstream" rev-parse --verify --quiet "refs/tags/$tag^{commit}" 2>/dev/null) \
|| die "upstream has no tag $tag"
if [ "$want" != "$commit" ]; then
echo "upstream: tag $tag is $want, the lock says $commit"; bad=1
fi
fi
while read -r blob src dest extra; do
[ -z "${extra:-}" ] || die "lock line has more than three fields: $blob $src $dest $extra"
[[ "$blob" =~ ^[0-9a-f]{40}$ ]] || die "lock line for $dest has no blob id"
case " $seen " in *" $dest "*) die "$dest is locked twice";; esac
seen="$seen $dest"
if [ ! -f "$root/$dest" ]; then
echo "missing: $dest (locked from $src)"; bad=1; continue
fi
have=$(git hash-object "$root/$dest")
if [ "$have" != "$blob" ]; then
echo "drift: $dest is $have, the lock says $blob ($src at $tag)"; bad=1
fi
if [ -n "$upstream" ] && [ "$want" = "$commit" ]; then
have=$(git -C "$upstream" rev-parse --verify --quiet "$commit:$src" 2>/dev/null) \
|| { echo "upstream: $src does not exist at $tag"; bad=1; continue; }
if [ "$have" != "$blob" ]; then
echo "upstream: $src at $tag is $have, the lock says $blob"; bad=1
fi
fi
done < <(entries)
[ -n "$seen" ] || die "flare-ui.lock lists no files"
# A tree line nobody synced has no blob line, so nothing above looked at
# the files it stands for (flare-ui#43).
local tsrc tdest covered item
while read -r tsrc tdest; do
covered=0
for item in $seen; do
case "$item" in "$tdest"|"$tdest"/*) covered=1; break;; esac
done
if [ "$covered" -eq 0 ]; then
echo "unsynced: tree $tsrc $tdest has no locked file; run sync"; bad=1
fi
done < <(trees)
local extra_file
while IFS= read -r extra_file; do
[ -n "$extra_file" ] || continue
echo "unlisted: $extra_file is in a vendored directory but not in the lock"; bad=1
done < <(unlisted "$seen")
if [ "$bad" -ne 0 ]; then
echo "vendor: vendored flare-ui files do not match flare-ui.lock." >&2
echo "Change them in flare-ui, tag a release, then re-sync; never edit them here." >&2
exit 1
fi
echo "vendor: $(echo "$seen" | wc -w) files match flare-ui $tag"
}
sync() {
local dir=${1:?sync needs a flare-ui checkout} tag=${2:?sync needs a tag}
[[ "$tag" =~ $tag_re ]] || die "$tag is not a release tag (vN.N.N); pin tags, never commits"
local commit
commit=$(git -C "$dir" rev-parse --verify --quiet "refs/tags/$tag^{commit}") \
|| die "$tag is not a tag in $dir"
local tree_list
tree_list=$(trees)
[ -n "$tree_list" ] || die "flare-ui.lock has no tree lines"
local tmp src dest mode blob path rel stage
tmp=$(mktemp "$root/.flare-ui.lock.XXXXXX")
stage=$(mktemp -d "$root/.flare-ui-stage.XXXXXX")
trap 'rm -rf "$tmp" "$stage"' EXIT
{
echo "# flare-ui files vendored here. Generated by vendor.sh sync;"
echo "# check with vendor.sh check. Never edit a vendored file in place."
echo "tag $tag"
echo "commit $commit"
while read -r src dest; do
echo "tree $src $dest"
done <<< "$tree_list"
while read -r src dest; do
git -C "$dir" cat-file -e "$commit:$src" 2>/dev/null || die "$src does not exist at $tag"
while read -r mode _ blob path; do
case "$mode" in 100644|100755) ;; *) die "$path is not a regular file (mode $mode)";; esac
case "$path" in *[[:space:]]*) die "$path has whitespace in its name";; esac
if [ "$path" = "$src" ]; then rel=$dest; else rel="$dest/${path#"$src"/}"; fi
mkdir -p "$(dirname "$stage/$rel")"
git -C "$dir" cat-file blob "$blob" > "$stage/$rel"
[ "$mode" = 100755 ] && chmod +x "$stage/$rel"
echo "$blob $path $rel"
done < <(git -C "$dir" ls-tree -r "$commit" -- "$src")
done <<< "$tree_list"
} > "$tmp"
# Replace each vendored directory wholesale, then the lock.
while read -r src dest; do
if [ -d "$stage/$dest" ]; then
rm -rf "${root:?}/$dest"
mkdir -p "$(dirname "$root/$dest")"
cp -a "$stage/$dest" "$root/$dest"
else
mkdir -p "$(dirname "$root/$dest")"
cp -a "$stage/$dest" "$root/$dest"
fi
done <<< "$tree_list"
mv "$tmp" "$lock"
rm -rf "$stage"
trap - EXIT
check --upstream "$dir"
}
# One brace group that ends in exit: bash parses all of it before running
# any of it, so when sync copies a new vendor.sh over this running file, bash
# never reads on into the new file's bytes (flare-ui#45).
{
case "${1:-}" in
check) shift; check "$@";;
sync) shift; sync "$@";;
*) echo "usage: vendor.sh check [--upstream DIR] | sync DIR TAG" >&2; exit 2;;
esac
exit
}