Files
wasm-simulator/list-linuxcnc-manifest-sources.sh
cnc dcf246c0a0 参考所有分组,完成尽量多的内容:收紧 manifest 坏行校验
结论:通用 LinuxCNC manifest lister 现在与输入校验一致拒绝缺少 note 或字段数量异常的坏行,并在 all-native guardrail 中覆盖通用 lister 与 native/source-link 调用链;未扩展 smoke 功能。
2026-06-03 17:37:58 +08:00

91 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
# LinuxCNC source basis: manifest listers expose LinuxCNC-root relative source
# entries from RS274, kinematics, remap, config, tooldata, and metadata
# manifests after check-linuxcnc-inputs.sh validates their source coverage.
manifest=${1:?manifest required}
filter_group=${2:?filter group required}
output_mode=${3:?output mode required}
allowed_groups=${4:?allowed groups required}
duplicate_groups=${5:?duplicate groups required}
missing_source_message=${6:?missing source message required}
linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc}
contains_group() {
local groups=$1
local group=$2
[[ ",$groups," == *",$group,"* ]]
}
checks_duplicate_group() {
local groups=$1
local group=$2
[[ "$groups" == "all" ]] || contains_group "$groups" "$group"
}
LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs-cached.sh "$manifest"
linuxcnc_root=$(cd "$linuxcnc_root" && pwd)
if [[ "$filter_group" != "all" ]] && ! contains_group "$allowed_groups" "$filter_group"; then
echo "unknown manifest source filter: $filter_group" >&2
exit 1
fi
case "$output_mode" in
relative|full)
;;
*)
echo "unknown manifest source output mode: $output_mode" >&2
exit 1
;;
esac
seen_sources=()
manifest_line_number=0
while IFS= read -r manifest_line || [[ -n "$manifest_line" ]]; do
manifest_line_number=$((manifest_line_number + 1))
case "$manifest_line" in
""|\#*)
continue
;;
esac
IFS=: read -r group path note extra <<<"$manifest_line"
if [[ -z "$group" || -z "$path" || -z "$note" || -n "${extra:-}" ]]; then
echo "bad manifest line $manifest_line_number: $manifest_line" >&2
exit 1
fi
if ! contains_group "$allowed_groups" "$group"; then
echo "unknown manifest group: $group" >&2
exit 1
fi
if [[ "$path" = /* || "$path" == .. || "$path" == ../* || "$path" == */.. || "$path" == */../* ]]; then
echo "manifest source must be LinuxCNC-root relative: $path" >&2
exit 1
fi
full_path="$linuxcnc_root/$path"
if [[ ! -f "$full_path" ]]; then
echo "$missing_source_message: $path" >&2
exit 1
fi
if checks_duplicate_group "$duplicate_groups" "$group"; then
if printf '%s\n' "${seen_sources[@]}" | grep -Fx -- "$path" >/dev/null; then
echo "duplicate manifest source: $path" >&2
exit 1
fi
seen_sources+=("$path")
fi
if [[ "$filter_group" == "all" || "$filter_group" == "$group" ]]; then
if [[ "$output_mode" == "full" ]]; then
printf '%s\n' "$full_path"
else
printf '%s\n' "$path"
fi
fi
done < "$manifest"