参考所有分组,完成尽量多的内容:锁定OPFS源码映射结论

结论:新增 OPFS source-map 文档和同步守卫,绑定 interp_internal.hh 默认参数文件、rs274ngc_pre.cc restore/save 语义与浏览器 OPFS 边界;未扩展 smoke 功能。
This commit is contained in:
cnc
2026-06-04 14:48:07 +08:00
parent 4eb694164f
commit b3b1117ec9
4 changed files with 98 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
# LinuxCNC source basis: this guard ties browser OPFS parameter persistence to
# interp_internal.hh defaults and rs274ngc_pre.cc restore_parameters() /
# save_parameters() file semantics. It validates bridge policy only; it does not
# add CNC behavior or expand smoke parsing.
linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc}
linuxcnc_root=$(cd "$linuxcnc_root" && pwd)
grep -F '#define RS274NGC_PARAMETER_FILE_NAME_DEFAULT "rs274ngc.var"' \
"$linuxcnc_root/src/emc/rs274ngc/interp_internal.hh" >/dev/null
grep -F '#define RS274NGC_PARAMETER_FILE_BACKUP_SUFFIX ".bak"' \
"$linuxcnc_root/src/emc/rs274ngc/interp_internal.hh" >/dev/null
grep -F 'int Interp::restore_parameters(const char *filename)' \
"$linuxcnc_root/src/emc/rs274ngc/rs274ngc_pre.cc" >/dev/null
grep -F 'int Interp::save_parameters(const char *filename,' \
"$linuxcnc_root/src/emc/rs274ngc/rs274ngc_pre.cc" >/dev/null
grep -F 'std::string tempfile = std::string(filename) + ".new";' \
"$linuxcnc_root/src/emc/rs274ngc/rs274ngc_pre.cc" >/dev/null
grep -F '+ RS274NGC_PARAMETER_FILE_BACKUP_SUFFIX;' \
"$linuxcnc_root/src/emc/rs274ngc/rs274ngc_pre.cc" >/dev/null
grep -F 'RS274NGC_PARAMETER_FILE_NAME_DEFAULT` as `rs274ngc.var`' \
docs/linuxcnc-opfs-source-map.md >/dev/null
grep -F 'RS274NGC_PARAMETER_FILE_BACKUP_SUFFIX` as `.bak`' \
docs/linuxcnc-opfs-source-map.md >/dev/null
grep -F '`Interp::restore_parameters()` for parameter-file reads' \
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 'must not add independent filesystem behavior or expand the temporary smoke parser' \
docs/linuxcnc-opfs-source-map.md >/dev/null
grep -F 'parseFileWithParameterFile()' docs/linuxcnc-opfs-source-map.md >/dev/null
grep -F 'const LINUXCNC_DEFAULT_PARAMETER_FILE = "rs274ngc.var";' web/src/wasm-core.js >/dev/null
grep -F '`${LINUXCNC_DEFAULT_PARAMETER_FILE}.new`' web/src/wasm-core.js >/dev/null
grep -F '`${LINUXCNC_DEFAULT_PARAMETER_FILE}.bak`' web/src/wasm-core.js >/dev/null
grep -F 'LinuxCNC source basis: rs274ngc_pre.cc restore_parameters() reads the' web/src/wasm-core.js >/dev/null
grep -F 'before replacing the main file and managing filename + ".bak".' web/src/wasm-core.js >/dev/null
grep -F 'OPFS cannot be disabled in browser contexts with OPFS support' web/src/wasm-core.js >/dev/null
grep -F 'const events = await simulator.parseFileWithParameterFile(programPath, parameterPath, "linuxcnc", parseOptions);' \
web/src/app.js >/dev/null
grep -F 'OPFS workspace is required for browser program parsing' web/src/app.js >/dev/null
if grep -R -n -E 'localStorage|sessionStorage|indexedDB|showOpenFilePicker|showSaveFilePicker|showDirectoryPicker|webkitRequestFileSystem|FileReader' web/src; then
echo "browser app/wasm code must not add filesystem persistence outside OPFS" >&2
exit 1
fi

View File

@@ -0,0 +1,41 @@
# LinuxCNC OPFS source map
This map records the source basis for browser-side LinuxCNC parameter-file
persistence. It is a policy and bridge map only; it must not add independent filesystem behavior or expand the temporary smoke parser.
## LinuxCNC Source Basis
- `src/emc/rs274ngc/interp_internal.hh` defines
`RS274NGC_PARAMETER_FILE_NAME_DEFAULT` as `rs274ngc.var`.
- `src/emc/rs274ngc/interp_internal.hh` defines
`RS274NGC_PARAMETER_FILE_BACKUP_SUFFIX` as `.bak`.
- `src/emc/rs274ngc/rs274ngc_pre.cc` implements
`Interp::restore_parameters()` for parameter-file reads.
- `src/emc/rs274ngc/rs274ngc_pre.cc` implements
`Interp::save_parameters()` for `filename + ".new"`, backup, and replacement
writes.
## Browser Bridge Boundary
- `web/src/wasm-core.js` must keep LinuxCNC parameter persistence routed
through an OPFS workspace.
- Browser contexts with OPFS support must not disable OPFS.
- Browser app and wasm bridge code must not use Local Storage, IndexedDB,
File Picker, Directory Picker, WebKit filesystem, or FileReader persistence
paths for CNC programs, LinuxCNC parameter files, or mirrored workspace files.
- `web/src/app.js` must parse browser programs through
`parseFileWithParameterFile()` so the program file and LinuxCNC parameter
state both live under OPFS.
## Checks
Run:
```bash
./check-linuxcnc-opfs-source-map.sh
./test-native.sh
./test-linuxcnc-source-link.sh
```
`check-linuxcnc-opfs-source-map.sh` keeps this document, the LinuxCNC source
anchors, and the browser bridge guardrails synchronized.

View File

@@ -145,6 +145,8 @@ grep -F 'LinuxCNC source basis: this guard keeps the local source map aligned' c
grep -F './check-linuxcnc-rs274-source-map.sh' test-native.sh >/dev/null
grep -F 'LinuxCNC source basis: this guard keeps the kinematics source map aligned' check-linuxcnc-kinematics-source-map.sh >/dev/null
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: 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
@@ -210,6 +212,9 @@ grep -F 'including `asset`, `tooldata`, and' docs/linuxcnc-source-policy.md >/de
grep -F 'LinuxCNC kinematics source map' docs/linuxcnc-kinematics-source-map.md >/dev/null
grep -F '| `tooldata` | 10 | LinuxCNC tool table files referenced by covered M428/M429/M430 INI files. |' docs/linuxcnc-kinematics-source-map.md >/dev/null
grep -F 'Browser-side file persistence remains OPFS-only' docs/linuxcnc-kinematics-source-map.md >/dev/null
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 '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

View File

@@ -36,6 +36,7 @@ preflight_cache_dir="$build_dir/preflight-cache"
./check-linuxcnc-inputs-cached.sh --cache-dir "$preflight_cache_dir" linuxcnc-kinematics-source-files.txt --require-kinematics-complete
./check-linuxcnc-rs274-source-map.sh
./check-linuxcnc-kinematics-source-map.sh
./check-linuxcnc-opfs-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