按提示词结论补 switchkins 完整覆盖锁

This commit is contained in:
cnc
2026-06-02 14:40:52 +08:00
parent 31e1e4499e
commit 0abf801856
7 changed files with 164 additions and 3 deletions

View File

@@ -36,6 +36,148 @@ if [[ ! -f "$manifest" ]]; then
exit 1
fi
validate_manifest_switchkins_complete() {
local manifest_file=$1
if command -v python3 >/dev/null 2>&1; then
if ! python3 - "$linuxcnc_root" "$manifest_file" <<'PY'
import os
import re
import sys
linuxcnc_root, manifest_file = sys.argv[1:]
sim_root = os.path.join(linuxcnc_root, "configs", "sim")
remap_ini_re = re.compile(r"REMAP\s*=\s*M(428|429|430)(?:\D|$)", re.I)
switchkins_remap_names = {"428remap.ngc", "429remap.ngc", "430remap.ngc"}
manifest_config_paths = set()
manifest_remap_paths = set()
with open(manifest_file, encoding="utf-8") as manifest:
for line in manifest:
parts = line.rstrip("\n").split(":", 2)
if len(parts) < 2:
continue
group, source_path = parts[:2]
if group == "config" and source_path.endswith(".ini"):
with open(os.path.join(linuxcnc_root, source_path), encoding="utf-8") as handle:
if remap_ini_re.search(handle.read()):
manifest_config_paths.add(source_path)
elif group == "remap":
manifest_remap_paths.add(source_path)
linuxcnc_config_paths = set()
linuxcnc_remap_paths = set()
for current_root, _dirs, files in os.walk(sim_root):
for filename in files:
source = os.path.join(current_root, filename)
source_path = os.path.relpath(source, linuxcnc_root)
if filename.endswith(".ini"):
with open(source, encoding="utf-8", errors="ignore") as handle:
if remap_ini_re.search(handle.read()):
linuxcnc_config_paths.add(source_path)
elif filename in switchkins_remap_names:
linuxcnc_remap_paths.add(source_path)
missing_configs = sorted(linuxcnc_config_paths - manifest_config_paths)
extra_configs = sorted(manifest_config_paths - linuxcnc_config_paths)
missing_remaps = sorted(linuxcnc_remap_paths - manifest_remap_paths)
extra_remaps = sorted(manifest_remap_paths - linuxcnc_remap_paths)
for source_path in missing_configs:
print(f"missing LinuxCNC switchkins REMAP INI in manifest: {source_path}", file=sys.stderr)
for source_path in extra_configs:
print(f"unexpected LinuxCNC switchkins REMAP INI in manifest: {source_path}", file=sys.stderr)
for source_path in missing_remaps:
print(f"missing LinuxCNC switchkins remap source in manifest: {source_path}", file=sys.stderr)
for source_path in extra_remaps:
print(f"unexpected LinuxCNC switchkins remap source in manifest: {source_path}", file=sys.stderr)
if missing_configs or extra_configs or missing_remaps or extra_remaps:
raise SystemExit(1)
PY
then
exit 1
fi
elif command -v node >/dev/null 2>&1; then
if ! node - "$linuxcnc_root" "$manifest_file" <<'JS'
const fs = require("fs");
const path = require("path");
const [linuxcncRoot, manifestFile] = process.argv.slice(2);
const simRoot = path.join(linuxcncRoot, "configs", "sim");
const remapIniRe = /REMAP\s*=\s*M(428|429|430)(?:\D|$)/i;
const switchkinsRemapNames = new Set(["428remap.ngc", "429remap.ngc", "430remap.ngc"]);
const manifestConfigPaths = new Set();
const manifestRemapPaths = new Set();
for (const line of fs.readFileSync(manifestFile, "utf8").split(/\r?\n/)) {
const parts = line.split(":", 3);
if (parts.length < 2) {
continue;
}
const [group, sourcePath] = parts;
if (group === "config" && sourcePath.endsWith(".ini")) {
const text = fs.readFileSync(path.join(linuxcncRoot, sourcePath), "utf8");
if (remapIniRe.test(text)) {
manifestConfigPaths.add(sourcePath);
}
} else if (group === "remap") {
manifestRemapPaths.add(sourcePath);
}
}
function walkFiles(root) {
const files = [];
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
const fullPath = path.join(root, entry.name);
if (entry.isDirectory()) {
files.push(...walkFiles(fullPath));
} else if (entry.isFile()) {
files.push(fullPath);
}
}
return files;
}
const linuxcncConfigPaths = new Set();
const linuxcncRemapPaths = new Set();
for (const source of walkFiles(simRoot)) {
const sourcePath = path.relative(linuxcncRoot, source);
const basename = path.basename(source);
if (basename.endsWith(".ini")) {
const text = fs.readFileSync(source, "utf8");
if (remapIniRe.test(text)) {
linuxcncConfigPaths.add(sourcePath);
}
} else if (switchkinsRemapNames.has(basename)) {
linuxcncRemapPaths.add(sourcePath);
}
}
const missingConfigs = [...linuxcncConfigPaths].filter((sourcePath) => !manifestConfigPaths.has(sourcePath)).sort();
const extraConfigs = [...manifestConfigPaths].filter((sourcePath) => !linuxcncConfigPaths.has(sourcePath)).sort();
const missingRemaps = [...linuxcncRemapPaths].filter((sourcePath) => !manifestRemapPaths.has(sourcePath)).sort();
const extraRemaps = [...manifestRemapPaths].filter((sourcePath) => !linuxcncRemapPaths.has(sourcePath)).sort();
for (const sourcePath of missingConfigs) {
console.error(`missing LinuxCNC switchkins REMAP INI in manifest: ${sourcePath}`);
}
for (const sourcePath of extraConfigs) {
console.error(`unexpected LinuxCNC switchkins REMAP INI in manifest: ${sourcePath}`);
}
for (const sourcePath of missingRemaps) {
console.error(`missing LinuxCNC switchkins remap source in manifest: ${sourcePath}`);
}
for (const sourcePath of extraRemaps) {
console.error(`unexpected LinuxCNC switchkins remap source in manifest: ${sourcePath}`);
}
if (missingConfigs.length || extraConfigs.length || missingRemaps.length || extraRemaps.length) {
process.exit(1);
}
JS
then
exit 1
fi
else
echo "missing python3 or node for switchkins remap manifest completeness validation" >&2
exit 1
fi
}
validate_manifest_switchkins_complete "$manifest"
validate_manifest_remap_kinstypes() {
local manifest_file=$1
if command -v python3 >/dev/null 2>&1; then