Files
wasm-simulator/list-linuxcnc-manifest-sources.sh
cnc aa6e79ac64 参考所有分组,完成尽量多的内容。禁止顺手扩功能 smoke
结论:收敛第 2/6 组 manifest/source-link 约束,公共 manifest source lister 只接受单个 manifest group 名称或 all,拒绝 core,header 这类复合 filter,避免 source coverage 查询静默误用;未扩展 smoke 功能。验证:CNC_SIM_ALL_NATIVE_GUARDRAILS_ONLY=1 ./test-all-native.sh、./test-native.sh、./test-linuxcnc-source-link.sh 均通过。
2026-06-03 19:11:22 +08:00

96 lines
2.9 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" && ! "$filter_group" =~ ^[A-Za-z0-9_-]+$ ]]; then
echo "manifest source filter must be a manifest group name: $filter_group" >&2
exit 1
fi
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"