From 4185a09428b5bad805ebd9559710182453c865ba Mon Sep 17 00:00:00 2001 From: Alejandro Martin Perez Date: Wed, 14 Oct 2026 00:47:53 +0200 Subject: [PATCH] build(kbd): generate/verify .kbd layouts and check them in CI (#702) kbdcompile was never invoked by the image build, so the committed .kbd could drift (they shipped empty once). Add: - scripts/gen-keyboard-layouts.sh: regenerate data/keyboard/.kbd from data/keyboard/.klc. - scripts/check-keyboard-layouts.sh: fail if a .kbd is missing, maps no scancodes, or differs from a fresh compile. - a CI job running the check. - doc fix: the layout files are generated by hand, not by the image build. --- .github/workflows/ci.yml | 12 +++++++ docs/design/neokbd-design.md | 8 +++-- scripts/check-keyboard-layouts.sh | 60 +++++++++++++++++++++++++++++++ scripts/gen-keyboard-layouts.sh | 26 ++++++++++++++ 4 files changed, 103 insertions(+), 3 deletions(-) create mode 100755 scripts/check-keyboard-layouts.sh create mode 100755 scripts/gen-keyboard-layouts.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6475b9b..3d7728cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,3 +95,15 @@ jobs: run: ./scripts/check-skills.sh - name: scripts/check-irq-locks.sh (INV-3 / Rule 3.5.1) run: ./scripts/check-irq-locks.sh + + keyboard-layouts: + name: Keyboard layouts + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # kbdcompile is a host-side std tool (no target needed). + - uses: dtolnay/rust-toolchain@stable + + - name: scripts/check-keyboard-layouts.sh (#702) + run: ./scripts/check-keyboard-layouts.sh diff --git a/docs/design/neokbd-design.md b/docs/design/neokbd-design.md index 3b074efb..c2aa2fc9 100644 --- a/docs/design/neokbd-design.md +++ b/docs/design/neokbd-design.md @@ -906,10 +906,12 @@ Los layouts se generan desde los mismos archivos `.klc` existentes, pero convert | Archivo | Layout | LangTag | Scancodes | Compose | | --- | --- | --- | --- | --- | -| `US.kbd` | US | en-US | 256 | 0 | -| `Spanish.kbd` | Spanish | es-ES | 256 | 54 | +| `en-US.kbd` | en-US | en-US | 50 | 0 | +| `es-ES.kbd` | es-ES | es-ES | 50 | 54 | -La herramienta `kbdcompile` toma un `.klc` y produce un `.kbd` binario. Se invoca en el build de la imagen, no en runtime. +La herramienta `kbdcompile` toma un `.klc` y produce un `.kbd` binario. Se ejecuta +a mano con `scripts/gen-keyboard-layouts.sh` y `scripts/check-keyboard-layouts.sh` +lo valida en CI (no está enganchado al build de imagen; ver #702). --- diff --git a/scripts/check-keyboard-layouts.sh b/scripts/check-keyboard-layouts.sh new file mode 100755 index 00000000..698c666c --- /dev/null +++ b/scripts/check-keyboard-layouts.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# Verify that data/keyboard/.kbd are non-empty and in sync with their +# .klc sources (issue #702). +# +# Fails if a .kbd is missing, maps zero scancodes, or differs from a fresh +# kbdcompile run. Run from anywhere. +set -euo pipefail + +root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$root" + +(cd tools/kbdcompile && cargo build --quiet) +bin=tools/kbdcompile/target/debug/kbdcompile + +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT + +fail=0 +shopt -s nullglob +found=0 +for klc in data/keyboard/*.klc; do + found=1 + tag="$(basename "$klc" .klc)" + kbd="data/keyboard/$tag.kbd" + + if [ ! -f "$kbd" ]; then + echo "check-keyboard-layouts: missing $kbd" >&2 + fail=1 + continue + fi + + if ! "$bin" "$klc" "$tmp/$tag.kbd" "$tag" "$tag" 2>"$tmp/$tag.err"; then + echo "check-keyboard-layouts: kbdcompile failed for $klc" >&2 + fail=1 + continue + fi + + # Reject an empty layout (every scancode 0xFFFF). + if ! grep -qE '\([1-9][0-9]* scancodes' "$tmp/$tag.err"; then + echo "check-keyboard-layouts: $klc produces an empty layout" >&2 + fail=1 + fi + + # Reject a stale committed artifact. + if ! cmp -s "$tmp/$tag.kbd" "$kbd"; then + echo "check-keyboard-layouts: $kbd is stale (differs from a fresh compile)" >&2 + fail=1 + fi +done + +if [ "$found" -eq 0 ]; then + echo "check-keyboard-layouts: no .klc sources found under data/keyboard/" >&2 + exit 1 +fi + +if [ "$fail" -ne 0 ]; then + echo "check-keyboard-layouts: FAILED — regenerate with scripts/gen-keyboard-layouts.sh" >&2 + exit 1 +fi +echo "check-keyboard-layouts: OK" diff --git a/scripts/gen-keyboard-layouts.sh b/scripts/gen-keyboard-layouts.sh new file mode 100755 index 00000000..ca6c206e --- /dev/null +++ b/scripts/gen-keyboard-layouts.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Regenerate data/keyboard/.kbd from data/keyboard/.klc with kbdcompile. +# +# The layout files are committed artifacts, so this is run by hand when a .klc +# changes (see issue #702). `check-keyboard-layouts.sh` guards against drift. +set -euo pipefail + +root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$root" + +(cd tools/kbdcompile && cargo build --quiet) +bin=tools/kbdcompile/target/debug/kbdcompile + +shopt -s nullglob +found=0 +for klc in data/keyboard/*.klc; do + found=1 + tag="$(basename "$klc" .klc)" + "$bin" "$klc" "data/keyboard/$tag.kbd" "$tag" "$tag" +done + +if [ "$found" -eq 0 ]; then + echo "gen-keyboard-layouts: no .klc sources found under data/keyboard/" >&2 + exit 1 +fi +echo "gen-keyboard-layouts: done"