#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")" # LinuxCNC source basis: this guard ties generated switchkins/remap aliases and # config cases to LinuxCNC configs/sim INI REMAP entries, remap_subs # # assignments, and halcmd loadusr parsing sources. It validates # generator/table policy only; it does not add CNC behavior or expand smoke. linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc} linuxcnc_root=$(cd "$linuxcnc_root" && pwd) grep -F 'LinuxCNC source basis: generated switchkins/remap tables are extracted from' \ generate-linuxcnc-switchkins-remap-table.sh >/dev/null grep -F 'src/hal/utils/halcmd_commands.cc do_loadusr_cmd()' \ generate-linuxcnc-switchkins-remap-table.sh >/dev/null grep -F 'getopt("+wWin:")' generate-linuxcnc-switchkins-remap-table.sh >/dev/null grep -F 'src/hal/utils/halcmd_completion.c lists the common -W/-Wn/-w/-iw forms' \ generate-linuxcnc-switchkins-remap-table.sh >/dev/null grep -F 'LinuxCNC TOOL_TABLE source is not listed as tooldata' \ generate-linuxcnc-switchkins-remap-table.sh >/dev/null grep -F 'LinuxCNC source basis: switchkins/remap table validation derives M428/M429/M430' \ check-linuxcnc-switchkins-remap-table.sh >/dev/null grep -F 'validate_tool_table_source_coverage_only' \ check-linuxcnc-switchkins-remap-table.sh >/dev/null grep -F 'exposes TOOL_TABLE through switchkins API/web bridge' \ check-linuxcnc-switchkins-remap-table.sh >/dev/null grep -F 'int do_loadusr_cmd(const char *args[])' "$linuxcnc_root/src/hal/utils/halcmd_commands.cc" >/dev/null grep -F 'getopt(argc,' "$linuxcnc_root/src/hal/utils/halcmd_commands.cc" >/dev/null grep -F '"+wWin:"' "$linuxcnc_root/src/hal/utils/halcmd_commands.cc" >/dev/null grep -F -- '-Wn' "$linuxcnc_root/src/hal/utils/halcmd_completion.c" >/dev/null python3 - "$linuxcnc_root" <<'PY' from pathlib import Path import json import re import sys linuxcnc_root = Path(sys.argv[1]) source_map = Path("docs/linuxcnc-switchkins-remap-source-map.md").read_text(encoding="utf-8") table = Path("core/src/linuxcnc_switchkins_remap_table.inc").read_text(encoding="utf-8") cpp_cases = Path("core/tests/linuxcnc_switchkins_remap_config_cases.inc").read_text(encoding="utf-8") json_cases = json.loads(Path("web/public/linuxcnc_switchkins_remap_config_cases.json").read_text(encoding="utf-8")) counts = { "core/src/linuxcnc_switchkins_remap_table.inc": len(re.findall(r'^\s*\{"', table, re.M)), "core/tests/linuxcnc_switchkins_remap_config_cases.inc": len(re.findall(r'^\s*\{"', cpp_cases, re.M)), "web/public/linuxcnc_switchkins_remap_config_cases.json": len(json_cases), } for path, count in counts.items(): if f"| `{path}` | {count} |" not in source_map: raise SystemExit(f"docs/linuxcnc-switchkins-remap-source-map.md count mismatch for {path}") remap_sources = [ path for path in (linuxcnc_root / "configs/sim").rglob("*remap.ngc") if path.name in {"428remap.ngc", "429remap.ngc", "430remap.ngc"} ] remap_ini_re = re.compile(r"REMAP\s*=\s*M(428|429|430)(?:\D|$)", re.I) remap_inis = [ path for path in (linuxcnc_root / "configs/sim").rglob("*.ini") if remap_ini_re.search(path.read_text(encoding="utf-8", errors="ignore")) ] if f"| LinuxCNC M428/M429/M430 remap sources | {len(remap_sources)} |" not in source_map: raise SystemExit("docs/linuxcnc-switchkins-remap-source-map.md remap source count mismatch") if f"| LinuxCNC switchkins REMAP INI sources | {len(remap_inis)} |" not in source_map: raise SystemExit("docs/linuxcnc-switchkins-remap-source-map.md REMAP INI source count mismatch") required_phrases = [ "must not add new smoke parser behavior", "`#` assignments", "[EMCIO] TOOL_TABLE` entries are source coverage only", "must not become generated switchkins aliases", "./check-linuxcnc-switchkins-remap-table.sh linuxcnc-kinematics-source-files.txt", ] for phrase in required_phrases: if phrase not in source_map: raise SystemExit( f"docs/linuxcnc-switchkins-remap-source-map.md is missing boundary phrase: {phrase}" ) case_fields = {case["field"] for case in json_cases} bad_fields = [field for field in case_fields if "tool" in field.lower()] if bad_fields: raise SystemExit(f"generated switchkins config cases expose TOOL_TABLE fields: {bad_fields}") if re.search(r'\btoolTable\b|\btooltable\b|\btool_table\b|\bTOOL_TABLE\b', Path("web/src/wasm-core.js").read_text(encoding="utf-8")): raise SystemExit("web/src/wasm-core.js exposes TOOL_TABLE through switchkins API") if re.search(r'\btoolTable\b|\btooltable\b|\btool_table\b|\bTOOL_TABLE\b', Path("web/src/index.ts").read_text(encoding="utf-8")): raise SystemExit("web/src/index.ts exposes TOOL_TABLE through switchkins API") PY