From b3b1117ec9712f84169b5204a14df170fd94f0c0 Mon Sep 17 00:00:00 2001 From: cnc Date: Thu, 4 Jun 2026 14:48:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E8=80=83=E6=89=80=E6=9C=89=E5=88=86?= =?UTF-8?q?=E7=BB=84=EF=BC=8C=E5=AE=8C=E6=88=90=E5=B0=BD=E9=87=8F=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AE=B9=EF=BC=9A=E9=94=81=E5=AE=9AOPFS?= =?UTF-8?q?=E6=BA=90=E7=A0=81=E6=98=A0=E5=B0=84=E7=BB=93=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 结论:新增 OPFS source-map 文档和同步守卫,绑定 interp_internal.hh 默认参数文件、rs274ngc_pre.cc restore/save 语义与浏览器 OPFS 边界;未扩展 smoke 功能。 --- check-linuxcnc-opfs-source-map.sh | 51 +++++++++++++++++++++++++++++++ docs/linuxcnc-opfs-source-map.md | 41 +++++++++++++++++++++++++ test-all-native.sh | 5 +++ test-native.sh | 1 + 4 files changed, 98 insertions(+) create mode 100755 check-linuxcnc-opfs-source-map.sh create mode 100644 docs/linuxcnc-opfs-source-map.md diff --git a/check-linuxcnc-opfs-source-map.sh b/check-linuxcnc-opfs-source-map.sh new file mode 100755 index 0000000..cbe5301 --- /dev/null +++ b/check-linuxcnc-opfs-source-map.sh @@ -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 diff --git a/docs/linuxcnc-opfs-source-map.md b/docs/linuxcnc-opfs-source-map.md new file mode 100644 index 0000000..a5c3ebb --- /dev/null +++ b/docs/linuxcnc-opfs-source-map.md @@ -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. diff --git a/test-all-native.sh b/test-all-native.sh index 699246c..2d61bab 100755 --- a/test-all-native.sh +++ b/test-all-native.sh @@ -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 diff --git a/test-native.sh b/test-native.sh index 8bb7275..585430c 100755 --- a/test-native.sh +++ b/test-native.sh @@ -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