Files
wasm-simulator/list-linuxcnc-manifest-sources.sh
2026-06-02 14:06:59 +08:00

84 lines
2.4 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=()
while IFS=: read -r group path note; do
case "$group" in
""|\#*)
continue
;;
esac
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"