diff --git a/check-linuxcnc-switchkins-remap-source-map.sh b/check-linuxcnc-switchkins-remap-source-map.sh new file mode 100755 index 0000000..624fddb --- /dev/null +++ b/check-linuxcnc-switchkins-remap-source-map.sh @@ -0,0 +1,93 @@ +#!/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 diff --git a/docs/linuxcnc-switchkins-remap-source-map.md b/docs/linuxcnc-switchkins-remap-source-map.md new file mode 100644 index 0000000..81000fd --- /dev/null +++ b/docs/linuxcnc-switchkins-remap-source-map.md @@ -0,0 +1,48 @@ +# LinuxCNC switchkins/remap source map + +This map records the source basis for generated M428/M429/M430 switchkins +aliases and config cases. It is a generator/table map only; it must not add new smoke parser behavior or expose LinuxCNC source-only assets as browser API fields. + +## LinuxCNC Source Basis + +- `configs/sim/**.ini` files with `REMAP = M428`, `REMAP = M429`, or + `REMAP = M430` provide the switchkins configuration roots. +- `remap_subs/{428,429,430}remap.ngc` files provide the adjacent + `#` assignments. +- `src/hal/utils/halcmd_commands.cc` `do_loadusr_cmd()` and + `getopt("+wWin:")` define the `loadusr` option model used by the generator. +- `src/hal/utils/halcmd_completion.c` documents common `loadusr` + `-W/-Wn/-w/-iw` forms preserved by the generator. + +## Generated Coverage + +| Output | Count | Source coverage role | +| --- | ---: | --- | +| `core/src/linuxcnc_switchkins_remap_table.inc` | 177 | Generated switchkins aliases from LinuxCNC INI/HAL/remap sources. | +| `core/tests/linuxcnc_switchkins_remap_config_cases.inc` | 616 | Generated C++ config cases for accepted switchkins config fields. | +| `web/public/linuxcnc_switchkins_remap_config_cases.json` | 616 | Generated browser-readable config cases mirroring the C++ cases. | +| LinuxCNC M428/M429/M430 remap sources | 31 | LinuxCNC `#` source assignments. | +| LinuxCNC switchkins REMAP INI sources | 16 | LinuxCNC configs that declare M428/M429/M430 remaps. | + +## Boundaries + +- `[EMCIO] TOOL_TABLE` entries are source coverage only. They must stay in the kinematics manifest as `tooldata` entries and must not become generated switchkins aliases, config fields, or browser option keys. +- `asset`, `metadata`, and `tooldata` inputs referenced by switchkins configs + are source coverage, not browser API surface. +- Generated tables must continue to derive M428/M429/M430 kinstypes from + LinuxCNC remap `#` assignments, not from hand-authored behavior. + +## Checks + +Run: + +```bash +./check-linuxcnc-switchkins-remap-source-map.sh +./check-linuxcnc-switchkins-remap-table.sh linuxcnc-kinematics-source-files.txt +./test-native.sh +./test-linuxcnc-source-link.sh +``` + +`check-linuxcnc-switchkins-remap-source-map.sh` keeps this document, generator +source anchors, generated output counts, and source-only `TOOL_TABLE` boundary +synchronized. diff --git a/test-all-native.sh b/test-all-native.sh index 2d61bab..14b3413 100755 --- a/test-all-native.sh +++ b/test-all-native.sh @@ -147,6 +147,9 @@ grep -F 'LinuxCNC source basis: this guard keeps the kinematics source map align grep -F './check-linuxcnc-kinematics-source-map.sh' test-native.sh >/dev/null grep -F 'LinuxCNC source basis: this guard ties browser OPFS parameter persistence' check-linuxcnc-opfs-source-map.sh >/dev/null grep -F './check-linuxcnc-opfs-source-map.sh' test-native.sh >/dev/null +grep -F 'LinuxCNC source basis: this guard ties generated switchkins/remap aliases' check-linuxcnc-switchkins-remap-source-map.sh >/dev/null +grep -F './check-linuxcnc-switchkins-remap-source-map.sh' test-native.sh >/dev/null +grep -F './check-linuxcnc-switchkins-remap-source-map.sh' test-linuxcnc-source-link.sh >/dev/null grep -F 'LinuxCNC source basis: the cached input checker keys check-linuxcnc-inputs.sh' check-linuxcnc-inputs-cached.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 'LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs-cached.sh "$manifest" --require-kinematics-complete' check-linuxcnc-switchkins-remap-table.sh >/dev/null @@ -215,6 +218,10 @@ grep -F 'Browser-side file persistence remains OPFS-only' docs/linuxcnc-kinemati grep -F 'LinuxCNC OPFS source map' docs/linuxcnc-opfs-source-map.md >/dev/null grep -F '`Interp::save_parameters()` for `filename + ".new"`' docs/linuxcnc-opfs-source-map.md >/dev/null grep -F 'Browser contexts with OPFS support must not disable OPFS.' docs/linuxcnc-opfs-source-map.md >/dev/null +grep -F 'LinuxCNC switchkins/remap source map' docs/linuxcnc-switchkins-remap-source-map.md >/dev/null +grep -F '| `core/src/linuxcnc_switchkins_remap_table.inc` | 177 | Generated switchkins aliases from LinuxCNC INI/HAL/remap sources. |' docs/linuxcnc-switchkins-remap-source-map.md >/dev/null +grep -F '[EMCIO] TOOL_TABLE` entries are source coverage only' docs/linuxcnc-switchkins-remap-source-map.md >/dev/null +grep -F './check-linuxcnc-switchkins-remap-source-map.sh' test-linuxcnc-source-link.sh >/dev/null grep -F 'check-linuxcnc-switchkins-remap-table-cached.sh --cache-dir "$preflight_cache_dir" linuxcnc-kinematics-source-files.txt' test-native.sh >/dev/null grep -F 'check-linuxcnc-switchkins-remap-table-cached.sh --cache-dir "$preflight_cache_dir" linuxcnc-kinematics-source-files.txt' test-linuxcnc-source-link.sh >/dev/null grep -F 'check-linuxcnc-switchkins-remap-table-cached.sh --cache-dir "$preflight_cache_dir" linuxcnc-kinematics-source-files.txt' build-wasm.sh >/dev/null diff --git a/test-linuxcnc-source-link.sh b/test-linuxcnc-source-link.sh index 7cf55a0..108c54e 100755 --- a/test-linuxcnc-source-link.sh +++ b/test-linuxcnc-source-link.sh @@ -36,6 +36,7 @@ fi preflight_cache_dir="$build_dir/preflight-cache" LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs-cached.sh --cache-dir "$preflight_cache_dir" "$manifest" +./check-linuxcnc-switchkins-remap-source-map.sh LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-switchkins-remap-table-cached.sh --cache-dir "$preflight_cache_dir" linuxcnc-kinematics-source-files.txt # The LinuxCNC source-linked dump path is not concurrency-safe under parallel execution. exec 9>"${TMPDIR:-/tmp}/cnc_sim_rs274_source_link.lock" diff --git a/test-native.sh b/test-native.sh index 585430c..fa97c20 100755 --- a/test-native.sh +++ b/test-native.sh @@ -37,6 +37,7 @@ preflight_cache_dir="$build_dir/preflight-cache" ./check-linuxcnc-rs274-source-map.sh ./check-linuxcnc-kinematics-source-map.sh ./check-linuxcnc-opfs-source-map.sh +./check-linuxcnc-switchkins-remap-source-map.sh ./check-linuxcnc-switchkins-remap-table-cached.sh --cache-dir "$preflight_cache_dir" linuxcnc-kinematics-source-files.txt grep -F 'tooldata:src/emc/tooldata/tooldata_nml.cc:NML tool table backend selected by LinuxCNC TOOL_NML_FLAG' linuxcnc-rs274-source-files.txt >/dev/null grep -F 'tooldata:src/emc/tooldata/tool_mmap_read.cc:LinuxCNC tooldata mmap reader utility source from tooldata Submakefile' linuxcnc-rs274-source-files.txt >/dev/null