1
0
Fork 0

Rearchitect generator around binding-plan layer with function generation

This commit is contained in:
Brendan Szymanski 2026-07-17 14:43:54 -04:00
parent 3b42593c72
commit 56de5bc976
43 changed files with 6222 additions and 7059 deletions

98
scripts/compile-gate.sh Executable file
View file

@ -0,0 +1,98 @@
#!/usr/bin/env bash
# compile-gate.sh — the generator's primary acceptance gate.
#
# Generates the tier's monorepo from configs/tierN.toml, then requires the
# generated package to `swift build` with ZERO errors. Pass/fail only: error
# counts are not a metric. Also diffs each module's skip report against the
# committed baseline in docs/skip-baseline/tierN/ (if present) so that new
# skips in supported categories fail loudly.
#
# Usage:
# scripts/compile-gate.sh <tier|all> [--fresh]
#
# <tier> 1..6 (tier1 = GLib+GObject ... tier6 = full stack), or 'all'
# --fresh remove the tier's output directory before generating (use when
# the generated file set shrinks and stale files would linger)
#
# Output goes to ${TMPDIR:-/tmp}/swift-gtk-gen-gate/tier-N; a stable path so
# incremental swift builds stay fast between runs.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
GATE_ROOT="${TMPDIR:-/tmp}/swift-gtk-gen-gate"
TIER_ARG="${1:-}"
FRESH=0
[[ "${2:-}" == "--fresh" ]] && FRESH=1
if [[ -z "$TIER_ARG" ]]; then
echo "usage: $0 <tier|all> [--fresh]" >&2
exit 2
fi
if [[ "$TIER_ARG" == "all" ]]; then
TIERS=(1 2 3 4 5 6)
else
TIERS=("$TIER_ARG")
fi
echo "==> Building generator"
swift build --package-path "$ROOT"
BIN="$(swift build --package-path "$ROOT" --show-bin-path)/swift-gtk-gen"
FAILED=0
run_tier() {
local tier="$1"
local config="$ROOT/configs/tier${tier}.toml"
local out="$GATE_ROOT/tier-${tier}"
if [[ ! -f "$config" ]]; then
echo "!! tier $tier: missing $config" >&2
return 1
fi
if [[ "$FRESH" == 1 ]]; then
rm -rf "$out"
fi
mkdir -p "$out"
echo "==> Tier $tier: generating into $out"
if ! "$BIN" --monorepo-config "$config" --output "$out" --skip-report >"$out/generate.log" 2>&1; then
echo "!! tier $tier: GENERATION FAILED (see $out/generate.log)" >&2
tail -n 20 "$out/generate.log" >&2
return 1
fi
echo "==> Tier $tier: swift build"
if ! swift build --package-path "$out" >"$out/build.log" 2>&1; then
echo "!! tier $tier: BUILD FAILED (see $out/build.log)" >&2
grep -m 10 'error:' "$out/build.log" >&2 || tail -n 20 "$out/build.log" >&2
return 1
fi
local baseline="$ROOT/docs/skip-baseline/tier${tier}"
if [[ -d "$baseline" ]]; then
echo "==> Tier $tier: diffing skip reports against $baseline"
if ! diff -ru "$baseline" "$out/skip-reports" >"$out/skip-diff.log" 2>&1; then
echo "!! tier $tier: SKIP REPORT CHANGED (see $out/skip-diff.log)" >&2
head -n 40 "$out/skip-diff.log" >&2
echo " If the change is intentional (coverage grew), refresh the baseline:" >&2
echo " cp -r $out/skip-reports/. $baseline/" >&2
return 1
fi
else
echo "==> Tier $tier: no skip baseline at $baseline (skipping diff)"
fi
echo "==> Tier $tier: PASS"
}
for tier in "${TIERS[@]}"; do
if ! run_tier "$tier"; then
FAILED=1
fi
done
exit "$FAILED"

View file

@ -1,82 +0,0 @@
#!/usr/bin/env bash
# Regression test for swift-gtk-gen output.
# Run this after any change to CodeGen.swift to catch regressions.
#
# Steps:
# 1. Build the generator
# 2. Generate Gtk-4.0 wrapper from the system .gir file
# 3. Run unit tests
# 4. Try to build the generated wrapper; report dependency-ignored errors
# 5. Lint the generated wrapper
set -euo pipefail
cd "$(dirname "$0")/.."
TEST_DIR="/tmp/regression-test-$$"
BIN_PATH=".build/debug/swift-gtk-gen"
echo "=== swift-gtk-gen regression test ==="
echo "Test output directory: $TEST_DIR"
# Cleanup trap (runs on exit, even on failure)
trap 'rm -rf "$TEST_DIR" /tmp/build-output.log' EXIT
# Ensure binary is built
if [ ! -x "$BIN_PATH" ]; then
echo "Binary not found at $BIN_PATH — running 'swift build' first..."
swift build
fi
# Generate
rm -rf "$TEST_DIR"
mkdir -p "$TEST_DIR"
"$BIN_PATH" \
--gir-file /usr/share/gir-1.0/Gtk-4.0.gir \
--output "$TEST_DIR" \
--generate-all 2>/dev/null
# Run unit tests
echo ""
echo "=== Unit tests ==="
swift test 2>&1 | tail -5
# Count errors
echo ""
echo "=== Generated output metrics ==="
file_count=$(find "$TEST_DIR" -name "*.swift" | wc -l)
echo "Generated Swift files: $file_count"
# Try to build the generated code
echo ""
echo "=== Build generated code ==="
if swift build --package-path "$TEST_DIR" 2>&1 > /tmp/build-output.log; then
echo "Generated code BUILD: PASS"
else
total=$(grep -c "error:" /tmp/build-output.log || echo 0)
cannot_find=$(grep "error:" /tmp/build-output.log | grep -c "cannot find" || echo 0)
fixable=$((total - cannot_find))
echo "Generated code BUILD: FAIL"
echo " Total errors: $total"
echo " Cannot find (deps): $cannot_find"
echo " Fixable errors: $fixable"
if [ "$fixable" -gt 0 ]; then
echo ""
echo "First 20 fixable errors:"
grep "error:" /tmp/build-output.log | grep -v "cannot find" | head -20
fi
fi
# Lint
echo ""
echo "=== Lint ==="
cd "$(dirname "$0")/.."
lint_errors=$(swift format lint --configuration .swift-format --recursive "$TEST_DIR" 2>&1 | grep -c "error:" || echo 0)
echo "Lint errors: $lint_errors"
if [ "$lint_errors" -gt 0 ]; then
echo "First 10 lint errors:"
swift format lint --configuration .swift-format --recursive "$TEST_DIR" 2>&1 | grep "error:" | head -10
fi
echo ""
echo "=== Done ==="