diff --git a/check-linuxcnc-switchkins-remap-table.sh b/check-linuxcnc-switchkins-remap-table.sh index aa62d1c..bfafacb 100755 --- a/check-linuxcnc-switchkins-remap-table.sh +++ b/check-linuxcnc-switchkins-remap-table.sh @@ -355,28 +355,36 @@ validate_generator_cli_contract() { local cli_dir local cli_manifest local cli_manifest_with_config_ngc + local cli_manifest_with_config_tbl local cli_manifest_with_duplicate_ini local cli_manifest_with_duplicate_remap + local cli_manifest_with_duplicate_tooldata local cli_manifest_with_unused_hal local cli_manifest_with_unused_postgui local cli_manifest_with_unused_remap + local cli_manifest_with_unused_tooldata local cli_manifest_without_ini local cli_manifest_without_hal local cli_manifest_without_postgui local cli_manifest_without_remap + local cli_manifest_without_tooldata cli_dir=$(mktemp -d "${TMPDIR:-/tmp}/linuxcnc_switchkins_remap_cli.XXXXXX") trap 'rm -rf "$cli_dir"' EXIT cli_manifest="$cli_dir/bridgemill-manifest.txt" cli_manifest_with_config_ngc="$cli_dir/bridgemill-manifest-with-config-ngc.txt" + cli_manifest_with_config_tbl="$cli_dir/bridgemill-manifest-with-config-tbl.txt" cli_manifest_with_duplicate_ini="$cli_dir/bridgemill-manifest-with-duplicate-ini.txt" cli_manifest_with_duplicate_remap="$cli_dir/bridgemill-manifest-with-duplicate-remap.txt" + cli_manifest_with_duplicate_tooldata="$cli_dir/bridgemill-manifest-with-duplicate-tooldata.txt" cli_manifest_with_unused_hal="$cli_dir/bridgemill-manifest-with-unused-hal.txt" cli_manifest_with_unused_postgui="$cli_dir/bridgemill-manifest-with-unused-postgui.txt" cli_manifest_with_unused_remap="$cli_dir/bridgemill-manifest-with-unused-remap.txt" + cli_manifest_with_unused_tooldata="$cli_dir/bridgemill-manifest-with-unused-tooldata.txt" cli_manifest_without_ini="$cli_dir/bridgemill-manifest-without-ini.txt" cli_manifest_without_hal="$cli_dir/bridgemill-manifest-without-hal.txt" cli_manifest_without_postgui="$cli_dir/bridgemill-manifest-without-postgui.txt" cli_manifest_without_remap="$cli_dir/bridgemill-manifest-without-remap.txt" + cli_manifest_without_tooldata="$cli_dir/bridgemill-manifest-without-tooldata.txt" if ! awk -F: -v manifest="$manifest_file" ' function require(key) { @@ -390,6 +398,7 @@ validate_generator_cli_contract() { require("remap:configs/sim/axis/vismach/5axis/bridgemill/remap_subs/428remap.ngc") require("remap:configs/sim/axis/vismach/5axis/bridgemill/remap_subs/429remap.ngc") require("remap:configs/sim/axis/vismach/5axis/bridgemill/remap_subs/430remap.ngc") + require("tooldata:configs/sim/axis/vismach/5axis/bridgemill/5axis.tbl") } { key = $1 ":" $2 @@ -427,6 +436,15 @@ validate_generator_cli_contract() { echo "switchkins remap generator accepted LinuxCNC remap source listed as config" >&2 exit 1 fi + cp "$cli_manifest" "$cli_manifest_with_config_tbl" + grep -F \ + 'tooldata:configs/sim/axis/vismach/5axis/bridgemill/5axis.tbl:' \ + "$cli_manifest" | sed 's/^tooldata:/config:/' >>"$cli_manifest_with_config_tbl" + if LINUXCNC_ROOT="$linuxcnc_root" ./generate-linuxcnc-switchkins-remap-table.sh \ + "$cli_manifest_with_config_tbl" >/dev/null 2>&1; then + echo "switchkins remap generator accepted LinuxCNC TOOL_TABLE source listed as config" >&2 + exit 1 + fi cp "$cli_manifest" "$cli_manifest_with_duplicate_ini" grep -F \ 'config:configs/sim/axis/vismach/5axis/bridgemill/5axis.ini:' \ @@ -445,6 +463,15 @@ validate_generator_cli_contract() { echo "switchkins remap generator accepted duplicate LinuxCNC M428 remap source" >&2 exit 1 fi + cp "$cli_manifest" "$cli_manifest_with_duplicate_tooldata" + grep -F \ + 'tooldata:configs/sim/axis/vismach/5axis/bridgemill/5axis.tbl:' \ + "$cli_manifest" >>"$cli_manifest_with_duplicate_tooldata" + if LINUXCNC_ROOT="$linuxcnc_root" ./generate-linuxcnc-switchkins-remap-table.sh \ + "$cli_manifest_with_duplicate_tooldata" >/dev/null 2>&1; then + echo "switchkins remap generator accepted duplicate LinuxCNC TOOL_TABLE source" >&2 + exit 1 + fi grep -Fv \ 'config:configs/sim/axis/vismach/5axis/bridgemill/5axis.ini:' \ "$cli_manifest" >"$cli_manifest_without_ini" @@ -477,6 +504,14 @@ validate_generator_cli_contract() { echo "switchkins remap generator accepted manifest missing LinuxCNC M430 remap source" >&2 exit 1 fi + grep -Fv \ + 'tooldata:configs/sim/axis/vismach/5axis/bridgemill/5axis.tbl:' \ + "$cli_manifest" >"$cli_manifest_without_tooldata" + if LINUXCNC_ROOT="$linuxcnc_root" ./generate-linuxcnc-switchkins-remap-table.sh \ + "$cli_manifest_without_tooldata" >/dev/null 2>&1; then + echo "switchkins remap generator accepted manifest missing LinuxCNC TOOL_TABLE source" >&2 + exit 1 + fi cp "$cli_manifest" "$cli_manifest_with_unused_hal" grep -F \ 'config:configs/sim/axis/vismach/melfa-sim/melfa_dh.hal:' \ @@ -504,6 +539,15 @@ validate_generator_cli_contract() { echo "switchkins remap generator accepted unused LinuxCNC M428 remap source" >&2 exit 1 fi + cp "$cli_manifest" "$cli_manifest_with_unused_tooldata" + grep -F \ + 'tooldata:configs/sim/axis/vismach/melfa-sim/melfa.tbl:' \ + "$manifest_file" >>"$cli_manifest_with_unused_tooldata" + if LINUXCNC_ROOT="$linuxcnc_root" ./generate-linuxcnc-switchkins-remap-table.sh \ + "$cli_manifest_with_unused_tooldata" >/dev/null 2>&1; then + echo "switchkins remap generator accepted unused LinuxCNC TOOL_TABLE source" >&2 + exit 1 + fi LINUXCNC_ROOT="$linuxcnc_root" ./generate-linuxcnc-switchkins-remap-table.sh --all-output-dir "$cli_dir/out" "$cli_manifest" LINUXCNC_ROOT="$linuxcnc_root" ./generate-linuxcnc-switchkins-remap-table.sh "$cli_manifest" \ diff --git a/generate-linuxcnc-switchkins-remap-table.sh b/generate-linuxcnc-switchkins-remap-table.sh index c36e6a7..4c5984d 100755 --- a/generate-linuxcnc-switchkins-remap-table.sh +++ b/generate-linuxcnc-switchkins-remap-table.sh @@ -100,6 +100,8 @@ read_ini_switchkins_config() { print "halfile\t" value } else if (section == "hal" && key == "postgui_halfile") { print "postgui_halfile\t" value + } else if (section == "emcio" && key == "tool_table") { + print "tool_table\t" value } else if (section == "rs274ngc" && key == "subroutine_path") { print "subroutine_path\t" value } else if (section == "rs274ngc" && key == "remap") { @@ -152,8 +154,11 @@ declare -A manifest_config_sources=() declare -A used_config_sources=() declare -A manifest_remap_sources=() declare -A used_remap_sources=() +declare -A manifest_tooldata_sources=() +declare -A used_tooldata_sources=() manifest_config_count=0 manifest_remap_count=0 +manifest_tooldata_count=0 validate_manifest_source_path() { local group=$1 @@ -208,6 +213,19 @@ while IFS=: read -r manifest_group manifest_path _manifest_note; do manifest_remap_sources[$manifest_path]=1 manifest_remap_count=$((manifest_remap_count + 1)) ;; + tooldata) + validate_manifest_source_path "$manifest_group" "$manifest_path" + if [[ "$manifest_path" != *.tbl ]]; then + echo "LinuxCNC switchkins tooldata source must be a tbl file in $manifest: $manifest_path" >&2 + exit 1 + fi + if [[ -n "${manifest_tooldata_sources[$manifest_path]:-}" ]]; then + echo "duplicate LinuxCNC switchkins tooldata source in $manifest: $manifest_path" >&2 + exit 1 + fi + manifest_tooldata_sources[$manifest_path]=1 + manifest_tooldata_count=$((manifest_tooldata_count + 1)) + ;; esac done <"$manifest" @@ -283,6 +301,27 @@ config_source_for_halfile() { resolved_config_source=$resolved_linuxcnc_path } +resolved_tooldata_source= +tooldata_source_for_tool_table() { + local config=$1 + local tool_table=$2 + resolved_tooldata_source= + [[ -n "$tool_table" ]] || return 1 + + local tool_path=${tool_table%%[[:space:]]*} + [[ -n "$tool_path" ]] || return 1 + + local config_dir + config_dir_for "$config" + config_dir=$resolved_config_dir + local resolved + resolve_config_path "$config_dir" "$tool_path" + resolved=$resolved_config_path + [[ -f "$resolved" ]] || return 1 + relative_linuxcnc_path "$resolved" + resolved_tooldata_source=$resolved_linuxcnc_path +} + resolved_kinstype= declare -A kinstype_cache=() kinstype_for_remap_source() { @@ -353,6 +392,16 @@ record_config_source() { used_config_sources[$source]=1 } +record_tooldata_source() { + local config_path=$1 + local source=$2 + if [[ -z "${manifest_tooldata_sources[$source]:-}" ]]; then + echo "LinuxCNC TOOL_TABLE source is not listed as tooldata in $manifest: $source ($config_path)" >&2 + exit 1 + fi + used_tooldata_sources[$source]=1 +} + declare -A seen_aliases=() declare -A seen_cases=() declare -A seen_case_values=() @@ -363,6 +412,7 @@ processed_config_count=0 resolved_remap_count=0 unique_config_source_count=0 unique_resolved_remap_count=0 +unique_tooldata_source_count=0 add_alias() { local alias=$1 @@ -612,6 +662,7 @@ while IFS=: read -r group path _note; do kinematics= halfiles= postgui_halfiles= + tool_tables= subroutine_paths= remap_ngc_428= remap_ngc_429= @@ -630,6 +681,9 @@ while IFS=: read -r group path _note; do postgui_halfile) postgui_halfiles+="${postgui_halfiles:+$'\n'}$ini_value" ;; + tool_table) + tool_tables+="${tool_tables:+$'\n'}$ini_value" + ;; subroutine_path) subroutine_paths+="${subroutine_paths:+$'\n'}$ini_value" ;; @@ -740,6 +794,11 @@ while IFS=: read -r group path _note; do add_postgui_halfile_cases "$halfile" "$m428" "$m429" "$m430" add_halfile_aliases "$halfile" "$m428" "$m429" "$m430" done <<<"$postgui_halfiles" + while IFS= read -r tool_table; do + if tooldata_source_for_tool_table "$config" "$tool_table"; then + record_tooldata_source "$path" "$resolved_tooldata_source" + fi + done <<<"$tool_tables" for remap_source in "$remap_source_428" "$remap_source_429" "$remap_source_430"; do if [[ -n "$remap_source" ]]; then @@ -761,6 +820,7 @@ done <"$manifest" unique_config_source_count=${#used_config_sources[@]} unique_resolved_remap_count=${#used_remap_sources[@]} +unique_tooldata_source_count=${#used_tooldata_sources[@]} validate_generated_content() { if ((manifest_config_count == 0)); then @@ -787,6 +847,10 @@ validate_generated_content() { echo "no unique LinuxCNC config sources used from manifest: $manifest" >&2 exit 1 fi + if ((manifest_tooldata_count > 0 && unique_tooldata_source_count == 0)); then + echo "no unique LinuxCNC TOOL_TABLE sources used from manifest: $manifest" >&2 + exit 1 + fi if ((unique_config_source_count != manifest_config_count)); then echo "LinuxCNC config manifest coverage mismatch: used $unique_config_source_count of $manifest_config_count config sources" >&2 local config_source @@ -797,6 +861,16 @@ validate_generated_content() { done exit 1 fi + if ((unique_tooldata_source_count != manifest_tooldata_count)); then + echo "LinuxCNC tooldata manifest coverage mismatch: used $unique_tooldata_source_count of $manifest_tooldata_count tooldata sources" >&2 + local tooldata_source + for tooldata_source in "${!manifest_tooldata_sources[@]}"; do + if [[ -z "${used_tooldata_sources[$tooldata_source]:-}" ]]; then + echo "unused LinuxCNC tooldata manifest source: $tooldata_source" >&2 + fi + done + exit 1 + fi if ((unique_resolved_remap_count != manifest_remap_count)); then echo "LinuxCNC remap manifest coverage mismatch: resolved $unique_resolved_remap_count of $manifest_remap_count remap sources" >&2 local remap_source