Files
wasm-simulator/test-linuxcnc-wasm-cmake-safe-probe.sh
cnc 40a63c76f7 高效率推进 LinuxCNC 源码对齐流程
说明:集中 LinuxCNC 源码清单与 wasm/native probe 的路径解析,补强 manifest、shim、source-link 检查,并保持 LinuxCNC 源码后端对齐验证流程可复用。

验证:./test-native.sh;./test-linuxcnc-source-link.sh;./test-all-native.sh;wasm source/probe 相关脚本。
2026-05-27 11:14:06 +08:00

570 lines
29 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc}
build_dir=$(mktemp -d "${TMPDIR:-/tmp}/cnc_sim_linuxcnc_wasm_cmake_safe_probe.XXXXXX")
manifest=${1:-linuxcnc-rs274-wasm-source-files.txt}
if [[ ! -f "$manifest" ]]; then
echo "missing manifest: $manifest" >&2
exit 1
fi
if [[ ! -d "$linuxcnc_root" ]]; then
echo "missing LinuxCNC root: $linuxcnc_root" >&2
exit 1
fi
trap 'rm -rf "$build_dir"' EXIT
missing_manifest=${TMPDIR:-/tmp}/cnc_sim_missing_build_wasm_manifest.txt
missing_manifest_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_build_wasm_manifest.XXXXXX.log")
rm -f "$missing_manifest"
if ./build-wasm.sh "$missing_manifest" >"$missing_manifest_log" 2>&1; then
echo "build-wasm accepted missing manifest: $missing_manifest" >&2
exit 1
fi
if ! grep -F "missing manifest: $missing_manifest" "$missing_manifest_log" >/dev/null; then
echo "build-wasm did not report missing manifest clearly" >&2
sed -n '1,20p' "$missing_manifest_log" >&2
exit 1
fi
rm -f "$missing_manifest_log"
missing_root=/tmp/does-not-exist-linuxcnc
missing_root_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_build_wasm_missing_root.XXXXXX.log")
if LINUXCNC_ROOT="$missing_root" ./build-wasm.sh >"$missing_root_log" 2>&1; then
echo "build-wasm accepted missing LinuxCNC root: $missing_root" >&2
exit 1
fi
if ! grep -F "missing LinuxCNC root: $missing_root" "$missing_root_log" >/dev/null; then
echo "build-wasm did not report missing LinuxCNC root clearly" >&2
sed -n '1,20p' "$missing_root_log" >&2
exit 1
fi
grep -F 'exec 9>"${TMPDIR:-/tmp}/cnc_sim_build_wasm.lock"' build-wasm.sh >/dev/null
grep -F "flock 9" build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-blockers.sh "$manifest"' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-source-syntax.sh "$manifest"' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-source-objects.sh "$manifest"' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-cmake-safe-probe.sh "$manifest"' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-tooldata-link.sh' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-tooldata-common-link.sh' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-tooldata-mmap-symbols.sh' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-tooldata-runtime-symbols.sh' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-interp-base-link.sh' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-interp-find-link.sh' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-python-plugin-link.sh' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-rs274ngc-pre-object.sh' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh "$manifest"' build-wasm.sh >/dev/null
grep -F -- './test-linuxcnc-wasm-rs274ngc-pre-link.sh "$manifest"' build-wasm.sh >/dev/null
grep -F -- '-DCNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST="$manifest"' build-wasm.sh >/dev/null
grep -F -- 'if ! command -v emcmake >/dev/null 2>&1; then' build-wasm.sh >/dev/null
grep -F "Emscripten is required. Install/activate emsdk so emcmake and emcc are in PATH." build-wasm.sh >/dev/null
grep -F -- 'emcmake cmake -S core -B build/wasm \' build-wasm.sh >/dev/null
grep -F -- 'default_manifest="$PWD/linuxcnc-rs274-wasm-source-files.txt"' build-wasm.sh >/dev/null
grep -F -- 'LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-wasm-manifest-sources.sh "$manifest" core > "$manifest_core_sources"' build-wasm.sh >/dev/null
grep -F -- 'LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-wasm-manifest-sources.sh "$manifest" blocked > "$manifest_blocked_sources"' build-wasm.sh >/dev/null
grep -F -- 'if [[ "$manifest" == "$default_manifest" ]] && [[ "$manifest_core_count" -ne 25 || "$manifest_blocked_count" -ne 1 ]]; then' build-wasm.sh >/dev/null
./list-linuxcnc-wasm-safe-shims.sh >/dev/null
./list-linuxcnc-wasm-safe-project-sources.sh >/dev/null
./list-linuxcnc-wasm-manifest-sources.sh "$manifest" core >/dev/null
grep -Fx "src/emc/rs274ngc/interp_arc.cc" \
< <(./list-linuxcnc-wasm-manifest-sources.sh "$manifest" core) >/dev/null
grep -Fx "src/emc/tooldata/tooldata_mmap.cc" \
< <(./list-linuxcnc-wasm-manifest-sources.sh "$manifest" blocked) >/dev/null
unknown_manifest_filter_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_unknown_wasm_manifest_filter.XXXXXX.log")
if ./list-linuxcnc-wasm-manifest-sources.sh "$manifest" bogus >"$unknown_manifest_filter_log" 2>&1; then
echo "wasm manifest source lister accepted unknown filter" >&2
exit 1
fi
if ! grep -F "unknown manifest source filter: bogus" "$unknown_manifest_filter_log" >/dev/null; then
echo "wasm manifest source lister did not report unknown filter clearly" >&2
sed -n '1,20p' "$unknown_manifest_filter_log" >&2
exit 1
fi
rm -f "$unknown_manifest_filter_log"
unknown_manifest_output_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_unknown_wasm_manifest_output.XXXXXX.log")
if ./list-linuxcnc-wasm-manifest-sources.sh "$manifest" core bogus >"$unknown_manifest_output_log" 2>&1; then
echo "wasm manifest source lister accepted unknown output mode" >&2
exit 1
fi
if ! grep -F "unknown manifest source output mode: bogus" "$unknown_manifest_output_log" >/dev/null; then
echo "wasm manifest source lister did not report unknown output mode clearly" >&2
sed -n '1,20p' "$unknown_manifest_output_log" >&2
exit 1
fi
rm -f "$unknown_manifest_output_log"
grep -Fx "$linuxcnc_root/src/emc/rs274ngc/interp_arc.cc" \
< <(LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-wasm-manifest-sources.sh "$manifest" core full) >/dev/null
grep -Fx "core/wasm_shims/dlfcn.cc" < <(./list-linuxcnc-wasm-safe-shims.sh dlfcn.cc) >/dev/null
grep -Fx "core/wasm_shims/pythonplugin/python_plugin.cc" \
< <(./list-linuxcnc-wasm-safe-shims.sh python_plugin.cc) >/dev/null
grep -Fx "core/wasm_shims/rtapi_compat.cc" \
< <(./list-linuxcnc-wasm-safe-shims.sh rtapi_compat.cc) >/dev/null
grep -Fx "core/wasm_shims/tooldata/tooldata_mmap_backend.cc" \
< <(./list-linuxcnc-wasm-safe-shims.sh tooldata_mmap_backend.cc) >/dev/null
grep -Fx "core/wasm_shims/tooldata/tooldata_runtime_stubs.cc" \
< <(./list-linuxcnc-wasm-safe-shims.sh tooldata_runtime_stubs.cc) >/dev/null
grep -Fx "core/src/linuxcnc_canon_bridge.cpp" \
< <(./list-linuxcnc-wasm-safe-project-sources.sh linuxcnc_canon_bridge.cpp) >/dev/null
missing_shim_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_wasm_safe_shim.XXXXXX.log")
if ./list-linuxcnc-wasm-safe-shims.sh does_not_exist.cc >"$missing_shim_log" 2>&1; then
echo "wasm-safe shim lister accepted missing shim filter" >&2
exit 1
fi
if ! grep -F "missing wasm-safe shim in CMake list: does_not_exist.cc" "$missing_shim_log" >/dev/null; then
echo "wasm-safe shim lister did not report missing shim filter clearly" >&2
sed -n '1,20p' "$missing_shim_log" >&2
exit 1
fi
rm -f "$missing_shim_log"
missing_project_source_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_wasm_safe_project_source.XXXXXX.log")
if ./list-linuxcnc-wasm-safe-project-sources.sh does_not_exist.cc >"$missing_project_source_log" 2>&1; then
echo "wasm-safe project source lister accepted missing source filter" >&2
exit 1
fi
if ! grep -F "missing wasm-safe project source in CMake list: does_not_exist.cc" "$missing_project_source_log" >/dev/null; then
echo "wasm-safe project source lister did not report missing source filter clearly" >&2
sed -n '1,20p' "$missing_project_source_log" >&2
exit 1
fi
rm -f "$missing_project_source_log"
rm -f "$missing_root_log"
missing_wasm_script_manifest=${TMPDIR:-/tmp}/cnc_sim_missing_wasm_script_manifest.txt
missing_wasm_script_manifest_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_wasm_script_manifest.XXXXXX.log")
rm -f "$missing_wasm_script_manifest"
for script in \
list-linuxcnc-wasm-manifest-sources.sh \
test-linuxcnc-wasm-source-syntax.sh \
test-linuxcnc-wasm-source-objects.sh \
test-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh \
test-linuxcnc-wasm-rs274ngc-pre-link.sh; do
if "./$script" "$missing_wasm_script_manifest" >"$missing_wasm_script_manifest_log" 2>&1; then
echo "$script accepted missing manifest: $missing_wasm_script_manifest" >&2
exit 1
fi
if ! grep -F "missing manifest: $missing_wasm_script_manifest" "$missing_wasm_script_manifest_log" >/dev/null; then
echo "$script did not report missing manifest clearly" >&2
sed -n '1,20p' "$missing_wasm_script_manifest_log" >&2
exit 1
fi
done
rm -f "$missing_wasm_script_manifest_log"
missing_root_scripts=(
test-linuxcnc-wasm-interp-base-link.sh
test-linuxcnc-wasm-interp-find-link.sh
test-linuxcnc-wasm-python-plugin-link.sh
test-linuxcnc-wasm-rs274ngc-pre-object.sh
test-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh
test-linuxcnc-wasm-rs274ngc-pre-link.sh
test-linuxcnc-wasm-source-objects.sh
test-linuxcnc-wasm-source-syntax.sh
test-linuxcnc-wasm-tooldata-common-link.sh
test-linuxcnc-wasm-tooldata-link.sh
test-linuxcnc-wasm-tooldata-mmap-symbols.sh
test-linuxcnc-wasm-tooldata-runtime-symbols.sh
)
for script in "${missing_root_scripts[@]}"; do
if LINUXCNC_ROOT="$missing_root" "./$script" >"$missing_root_log" 2>&1; then
echo "$script accepted missing LinuxCNC root: $missing_root" >&2
exit 1
fi
if ! grep -F "missing LinuxCNC root: $missing_root" "$missing_root_log" >/dev/null; then
echo "$script did not report missing LinuxCNC root clearly" >&2
sed -n '1,20p' "$missing_root_log" >&2
exit 1
fi
done
rm -f "$missing_root_log"
missing_source_root=$(mktemp -d "${TMPDIR:-/tmp}/cnc_sim_missing_linuxcnc_source_root.XXXXXX")
missing_source_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_linuxcnc_source.XXXXXX.log")
mkdir -p "$missing_source_root/src" "$missing_source_root/include"
fixed_source_scripts=(
"test-linuxcnc-wasm-interp-base-link.sh:src/emc/rs274ngc/interp_base.cc"
"test-linuxcnc-wasm-interp-find-link.sh:src/emc/tooldata/tooldata_common.cc"
"test-linuxcnc-wasm-rs274ngc-pre-object.sh:src/emc/rs274ngc/rs274ngc_pre.cc"
"test-linuxcnc-wasm-tooldata-common-link.sh:src/emc/tooldata/tooldata_common.cc"
"test-linuxcnc-wasm-tooldata-link.sh:src/emc/tooldata/tooldata_common.cc"
"test-linuxcnc-wasm-tooldata-mmap-symbols.sh:src/emc/tooldata/tooldata_mmap.cc"
"test-linuxcnc-wasm-tooldata-runtime-symbols.sh:src/emc/tooldata/tooldata_db.cc"
)
for script_and_path in "${fixed_source_scripts[@]}"; do
script=${script_and_path%%:*}
source_path=${script_and_path#*:}
if LINUXCNC_ROOT="$missing_source_root" "./$script" >"$missing_source_log" 2>&1; then
echo "$script accepted missing LinuxCNC source: $source_path" >&2
exit 1
fi
if ! grep -F "missing LinuxCNC source: $source_path" "$missing_source_log" >/dev/null; then
echo "$script did not report missing LinuxCNC source clearly" >&2
sed -n '1,20p' "$missing_source_log" >&2
exit 1
fi
done
rm -rf "$missing_source_root"
rm -f "$missing_source_log"
missing_interp_find_root=$(mktemp -d "${TMPDIR:-/tmp}/cnc_sim_missing_interp_find_source_root.XXXXXX")
missing_interp_find_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_interp_find_source.XXXXXX.log")
mkdir -p "$missing_interp_find_root/src/emc/tooldata" "$missing_interp_find_root/src/emc/rs274ngc" "$missing_interp_find_root/include"
touch "$missing_interp_find_root/src/emc/tooldata/tooldata_common.cc"
if LINUXCNC_ROOT="$missing_interp_find_root" ./test-linuxcnc-wasm-interp-find-link.sh >"$missing_interp_find_log" 2>&1; then
echo "test-linuxcnc-wasm-interp-find-link.sh accepted missing LinuxCNC source: src/emc/rs274ngc/interp_find.cc" >&2
exit 1
fi
if ! grep -F "missing LinuxCNC source: src/emc/rs274ngc/interp_find.cc" "$missing_interp_find_log" >/dev/null; then
echo "test-linuxcnc-wasm-interp-find-link.sh did not report missing interp_find source clearly" >&2
sed -n '1,20p' "$missing_interp_find_log" >&2
exit 1
fi
rm -rf "$missing_interp_find_root"
rm -f "$missing_interp_find_log"
missing_tooldata_runtime_root=$(mktemp -d "${TMPDIR:-/tmp}/cnc_sim_missing_tooldata_runtime_source_root.XXXXXX")
missing_tooldata_runtime_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_tooldata_runtime_source.XXXXXX.log")
mkdir -p "$missing_tooldata_runtime_root/src/emc/tooldata" "$missing_tooldata_runtime_root/include"
touch "$missing_tooldata_runtime_root/src/emc/tooldata/tooldata_db.cc"
if LINUXCNC_ROOT="$missing_tooldata_runtime_root" ./test-linuxcnc-wasm-tooldata-runtime-symbols.sh >"$missing_tooldata_runtime_log" 2>&1; then
echo "test-linuxcnc-wasm-tooldata-runtime-symbols.sh accepted missing LinuxCNC source: src/emc/tooldata/tooldata_nml.cc" >&2
exit 1
fi
if ! grep -F "missing LinuxCNC source: src/emc/tooldata/tooldata_nml.cc" "$missing_tooldata_runtime_log" >/dev/null; then
echo "test-linuxcnc-wasm-tooldata-runtime-symbols.sh did not report missing tooldata_nml source clearly" >&2
sed -n '1,20p' "$missing_tooldata_runtime_log" >&2
exit 1
fi
rm -rf "$missing_tooldata_runtime_root"
rm -f "$missing_tooldata_runtime_log"
unknown_group_manifest=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_unknown_wasm_manifest_group.XXXXXX.txt")
unknown_group_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_unknown_wasm_manifest_group.XXXXXX.log")
printf 'bogus:src/emc/rs274ngc/interp_arc.cc:test unknown group\n' >"$unknown_group_manifest"
if ./build-wasm.sh "$unknown_group_manifest" >"$unknown_group_log" 2>&1; then
echo "build-wasm accepted unknown manifest group" >&2
exit 1
fi
if ! grep -F "unknown manifest group: bogus" "$unknown_group_log" >/dev/null; then
echo "build-wasm did not report unknown manifest group clearly" >&2
sed -n '1,20p' "$unknown_group_log" >&2
exit 1
fi
for script in \
analyze-linuxcnc-wasm-blockers.sh \
test-linuxcnc-wasm-source-syntax.sh \
test-linuxcnc-wasm-source-objects.sh \
test-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh \
test-linuxcnc-wasm-rs274ngc-pre-link.sh; do
if "./$script" "$unknown_group_manifest" >"$unknown_group_log" 2>&1; then
echo "$script accepted unknown manifest group" >&2
exit 1
fi
if ! grep -F "unknown manifest group: bogus" "$unknown_group_log" >/dev/null; then
echo "$script did not report unknown manifest group clearly" >&2
sed -n '1,20p' "$unknown_group_log" >&2
exit 1
fi
done
rm -f "$unknown_group_manifest" "$unknown_group_log"
blocker_scan_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_wasm_blocker_scan.XXXXXX.log")
./test-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh >"$blocker_scan_log" 2>&1
blocker_report_file=$(awk '/^wrote / { print $2 }' "$blocker_scan_log")
if [[ -z "$blocker_report_file" || ! -f "$blocker_report_file" ]]; then
echo "wasm rs274ngc_pre blocker scan did not preserve its report file" >&2
sed -n '1,20p' "$blocker_scan_log" >&2
exit 1
fi
rm -f "$blocker_report_file" "$blocker_scan_log"
missing_source_manifest=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_wasm_manifest_source.XXXXXX.txt")
missing_source_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_wasm_manifest_source.XXXXXX.log")
printf 'core:src/emc/rs274ngc/does_not_exist.cc:test missing source\n' >"$missing_source_manifest"
if ./build-wasm.sh "$missing_source_manifest" >"$missing_source_log" 2>&1; then
echo "build-wasm accepted missing manifest source" >&2
exit 1
fi
if ! grep -F "missing manifest source: src/emc/rs274ngc/does_not_exist.cc" "$missing_source_log" >/dev/null; then
echo "build-wasm did not report missing manifest source clearly" >&2
sed -n '1,20p' "$missing_source_log" >&2
exit 1
fi
if ./test-linuxcnc-wasm-source-syntax.sh "$missing_source_manifest" >"$missing_source_log" 2>&1; then
echo "wasm source syntax probe accepted missing manifest source" >&2
exit 1
fi
if ! grep -F "missing manifest source: src/emc/rs274ngc/does_not_exist.cc" "$missing_source_log" >/dev/null; then
echo "wasm source syntax probe did not report missing manifest source clearly" >&2
sed -n '1,20p' "$missing_source_log" >&2
exit 1
fi
if ./test-linuxcnc-wasm-source-objects.sh "$missing_source_manifest" >"$missing_source_log" 2>&1; then
echo "wasm source object probe accepted missing manifest source" >&2
exit 1
fi
if ! grep -F "missing manifest source: src/emc/rs274ngc/does_not_exist.cc" "$missing_source_log" >/dev/null; then
echo "wasm source object probe did not report missing manifest source clearly" >&2
sed -n '1,20p' "$missing_source_log" >&2
exit 1
fi
if ./test-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh "$missing_source_manifest" >"$missing_source_log" 2>&1; then
echo "wasm rs274ngc_pre blocker scan accepted missing manifest source" >&2
exit 1
fi
if ! grep -F "missing manifest source: src/emc/rs274ngc/does_not_exist.cc" "$missing_source_log" >/dev/null; then
echo "wasm rs274ngc_pre blocker scan did not report missing manifest source clearly" >&2
sed -n '1,20p' "$missing_source_log" >&2
exit 1
fi
if ./test-linuxcnc-wasm-rs274ngc-pre-link.sh "$missing_source_manifest" >"$missing_source_log" 2>&1; then
echo "wasm rs274ngc_pre link probe accepted missing manifest source" >&2
exit 1
fi
if ! grep -F "missing manifest source: src/emc/rs274ngc/does_not_exist.cc" "$missing_source_log" >/dev/null; then
echo "wasm rs274ngc_pre link probe did not report missing manifest source clearly" >&2
sed -n '1,20p' "$missing_source_log" >&2
exit 1
fi
rm -f "$missing_source_manifest" "$missing_source_log"
empty_partition_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_empty_wasm_manifest_partition.XXXXXX.log")
empty_core_manifest=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_empty_wasm_manifest_core.XXXXXX.txt")
empty_blocked_manifest=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_empty_wasm_manifest_blocked.XXXXXX.txt")
printf 'blocked:src/emc/tooldata/tooldata_mmap.cc:test empty core partition\n' >"$empty_core_manifest"
if ./build-wasm.sh "$empty_core_manifest" >"$empty_partition_log" 2>&1; then
echo "build-wasm accepted empty core manifest partition" >&2
exit 1
fi
if ! grep -F "unexpected wasm manifest partition: core=0 blocked=1" "$empty_partition_log" >/dev/null; then
echo "build-wasm did not report empty core manifest partition clearly" >&2
sed -n '1,20p' "$empty_partition_log" >&2
exit 1
fi
printf 'core:src/emc/rs274ngc/interp_arc.cc:test empty blocked partition\n' >"$empty_blocked_manifest"
if ./build-wasm.sh "$empty_blocked_manifest" >"$empty_partition_log" 2>&1; then
echo "build-wasm accepted empty blocked manifest partition" >&2
exit 1
fi
if ! grep -F "unexpected wasm manifest partition: core=1 blocked=0" "$empty_partition_log" >/dev/null; then
echo "build-wasm did not report empty blocked manifest partition clearly" >&2
sed -n '1,20p' "$empty_partition_log" >&2
exit 1
fi
rm -f "$empty_core_manifest" "$empty_blocked_manifest" "$empty_partition_log"
bad_default_manifest_dir=$(mktemp -d "${TMPDIR:-/tmp}/cnc_sim_bad_default_wasm_manifest.XXXXXX")
bad_default_manifest_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_bad_default_wasm_manifest.XXXXXX.log")
linuxcnc_root_abs=$(cd "$linuxcnc_root" && pwd)
cp build-wasm.sh "$bad_default_manifest_dir/build-wasm.sh"
cp list-linuxcnc-wasm-manifest-sources.sh "$bad_default_manifest_dir/list-linuxcnc-wasm-manifest-sources.sh"
printf 'core:src/emc/rs274ngc/interp_arc.cc:test bad default core count\nblocked:src/emc/tooldata/tooldata_mmap.cc:test bad default blocked count\n' \
>"$bad_default_manifest_dir/linuxcnc-rs274-wasm-source-files.txt"
if LINUXCNC_ROOT="$linuxcnc_root_abs" "$bad_default_manifest_dir/build-wasm.sh" >"$bad_default_manifest_log" 2>&1; then
echo "build-wasm accepted bad default wasm manifest partition" >&2
exit 1
fi
if ! grep -F "unexpected wasm manifest partition: core=1 blocked=1" "$bad_default_manifest_log" >/dev/null; then
echo "build-wasm did not enforce default wasm manifest partition for no-arg entry" >&2
sed -n '1,20p' "$bad_default_manifest_log" >&2
exit 1
fi
rm -rf "$bad_default_manifest_dir"
rm -f "$bad_default_manifest_log"
duplicate_manifest=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_duplicate_wasm_manifest.XXXXXX.txt")
duplicate_manifest_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_duplicate_wasm_manifest.XXXXXX.log")
cat >"$duplicate_manifest" <<'EOF'
core:src/emc/rs274ngc/interp_arc.cc:duplicate core entry
core:src/emc/rs274ngc/interp_arc.cc:duplicate core entry
blocked:src/emc/tooldata/tooldata_mmap.cc:blocked entry
EOF
if ./build-wasm.sh "$duplicate_manifest" >"$duplicate_manifest_log" 2>&1; then
echo "build-wasm accepted duplicate manifest source" >&2
exit 1
fi
if ! grep -F "duplicate manifest source: src/emc/rs274ngc/interp_arc.cc" "$duplicate_manifest_log" >/dev/null; then
echo "build-wasm did not report duplicate manifest source clearly" >&2
sed -n '1,20p' "$duplicate_manifest_log" >&2
exit 1
fi
rm -f "$duplicate_manifest" "$duplicate_manifest_log"
comment_manifest=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_comment_wasm_manifest.XXXXXX.txt")
comment_manifest_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_comment_wasm_manifest.XXXXXX.log")
cat >"$comment_manifest" <<'EOF'
# LinuxCNC rs274 source subset for browser-safe source-link probing.
# Format: group:path:note
core:src/emc/rs274ngc/interp_arc.cc:commented core entry
blocked:src/emc/tooldata/tooldata_mmap.cc:commented blocked entry
EOF
if ./build-wasm.sh "$comment_manifest" >"$comment_manifest_log" 2>&1; then
:
fi
if grep -F "duplicate manifest source" "$comment_manifest_log" >/dev/null; then
echo "build-wasm rejected commented manifest lines as duplicates" >&2
sed -n '1,20p' "$comment_manifest_log" >&2
exit 1
fi
rm -f "$comment_manifest" "$comment_manifest_log"
duplicate_source_manifest=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_duplicate_wasm_source_manifest.XXXXXX.txt")
duplicate_source_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_duplicate_wasm_source_manifest.XXXXXX.log")
cat >"$duplicate_source_manifest" <<'EOF'
core:src/emc/rs274ngc/interp_arc.cc:duplicate core entry
core:src/emc/rs274ngc/interp_arc.cc:duplicate core entry
blocked:src/emc/tooldata/tooldata_mmap.cc:blocked entry
EOF
if ./test-linuxcnc-wasm-source-objects.sh "$duplicate_source_manifest" >"$duplicate_source_log" 2>&1; then
echo "source object probe accepted duplicate manifest source" >&2
exit 1
fi
if ! grep -F "duplicate manifest source: src/emc/rs274ngc/interp_arc.cc" "$duplicate_source_log" >/dev/null; then
echo "source object probe did not report duplicate manifest source clearly" >&2
sed -n '1,20p' "$duplicate_source_log" >&2
exit 1
fi
rm -f "$duplicate_source_manifest" "$duplicate_source_log"
duplicate_syntax_manifest=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_duplicate_wasm_syntax_manifest.XXXXXX.txt")
duplicate_syntax_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_duplicate_wasm_syntax_manifest.XXXXXX.log")
cat >"$duplicate_syntax_manifest" <<'EOF'
core:src/emc/rs274ngc/interp_arc.cc:duplicate core entry
core:src/emc/rs274ngc/interp_arc.cc:duplicate core entry
blocked:src/emc/tooldata/tooldata_mmap.cc:blocked entry
EOF
if ./test-linuxcnc-wasm-source-syntax.sh "$duplicate_syntax_manifest" >"$duplicate_syntax_log" 2>&1; then
echo "syntax probe accepted duplicate manifest source" >&2
exit 1
fi
if ! grep -F "duplicate manifest source: src/emc/rs274ngc/interp_arc.cc" "$duplicate_syntax_log" >/dev/null; then
echo "syntax probe did not report duplicate manifest source clearly" >&2
sed -n '1,20p' "$duplicate_syntax_log" >&2
exit 1
fi
rm -f "$duplicate_syntax_manifest" "$duplicate_syntax_log"
duplicate_pre_blocker_manifest=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_duplicate_wasm_pre_blocker_manifest.XXXXXX.txt")
duplicate_pre_blocker_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_duplicate_wasm_pre_blocker_manifest.XXXXXX.log")
cat >"$duplicate_pre_blocker_manifest" <<'EOF'
core:src/emc/rs274ngc/interp_arc.cc:duplicate core entry
core:src/emc/rs274ngc/interp_arc.cc:duplicate core entry
blocked:src/emc/tooldata/tooldata_mmap.cc:blocked entry
EOF
if ./test-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh "$duplicate_pre_blocker_manifest" >"$duplicate_pre_blocker_log" 2>&1; then
echo "rs274ngc_pre blocker scan accepted duplicate manifest source" >&2
exit 1
fi
if ! grep -F "duplicate manifest source: src/emc/rs274ngc/interp_arc.cc" "$duplicate_pre_blocker_log" >/dev/null; then
echo "rs274ngc_pre blocker scan did not report duplicate manifest source clearly" >&2
sed -n '1,20p' "$duplicate_pre_blocker_log" >&2
exit 1
fi
rm -f "$duplicate_pre_blocker_manifest" "$duplicate_pre_blocker_log"
duplicate_pre_link_manifest=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_duplicate_wasm_pre_link_manifest.XXXXXX.txt")
duplicate_pre_link_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_duplicate_wasm_pre_link_manifest.XXXXXX.log")
cat >"$duplicate_pre_link_manifest" <<'EOF'
core:src/emc/rs274ngc/interp_arc.cc:duplicate core entry
core:src/emc/rs274ngc/interp_arc.cc:duplicate core entry
blocked:src/emc/tooldata/tooldata_mmap.cc:blocked entry
EOF
if ./test-linuxcnc-wasm-rs274ngc-pre-link.sh "$duplicate_pre_link_manifest" >"$duplicate_pre_link_log" 2>&1; then
echo "rs274ngc_pre link probe accepted duplicate manifest source" >&2
exit 1
fi
if ! grep -F "duplicate manifest source: src/emc/rs274ngc/interp_arc.cc" "$duplicate_pre_link_log" >/dev/null; then
echo "rs274ngc_pre link probe did not report duplicate manifest source clearly" >&2
sed -n '1,20p' "$duplicate_pre_link_log" >&2
exit 1
fi
rm -f "$duplicate_pre_link_manifest" "$duplicate_pre_link_log"
linuxcnc_root=$(cd "$linuxcnc_root" && pwd)
default_manifest="$PWD/linuxcnc-rs274-wasm-source-files.txt"
manifest_core_count=0
manifest_blocked_count=0
manifest_core_sources="$build_dir/wasm_core_sources.txt"
manifest_blocked_sources="$build_dir/wasm_blocked_sources.txt"
./list-linuxcnc-wasm-manifest-sources.sh "$manifest" core > "$manifest_core_sources"
./list-linuxcnc-wasm-manifest-sources.sh "$manifest" blocked > "$manifest_blocked_sources"
manifest_core_count=$(wc -l < "$manifest_core_sources")
manifest_blocked_count=$(wc -l < "$manifest_blocked_sources")
required_shim_sources="$build_dir/wasm_safe_shim_sources.txt"
./list-linuxcnc-wasm-safe-shims.sh > "$required_shim_sources"
required_project_sources="$build_dir/wasm_safe_project_sources.txt"
./list-linuxcnc-wasm-safe-project-sources.sh > "$required_project_sources"
if [[ "$manifest" == "$default_manifest" ]] && [[ "$manifest_core_count" -ne 25 || "$manifest_blocked_count" -ne 1 ]]; then
echo "unexpected wasm manifest partition: core=$manifest_core_count blocked=$manifest_blocked_count" >&2
exit 1
fi
if [[ "$manifest_core_count" -eq 0 || "$manifest_blocked_count" -eq 0 ]]; then
echo "unexpected wasm manifest partition: core=$manifest_core_count blocked=$manifest_blocked_count" >&2
exit 1
fi
while IFS= read -r shim; do
[[ -z "$shim" ]] && continue
cmake_shim=${shim#core/}
if ! grep -F "$cmake_shim" core/CMakeLists.txt >/dev/null; then
echo "missing CMake wasm-safe shim: $cmake_shim" >&2
exit 1
fi
done < "$required_shim_sources"
while IFS= read -r source; do
[[ -z "$source" ]] && continue
cmake_source=${source#core/}
if ! grep -F "$cmake_source" core/CMakeLists.txt >/dev/null; then
echo "missing CMake wasm-safe project source: $cmake_source" >&2
exit 1
fi
done < "$required_project_sources"
grep -F "add_executable(linuxcnc_rs274_wasm_safe_probe EXCLUDE_FROM_ALL" core/CMakeLists.txt >/dev/null
grep -F "wasm_shims/rs274ngc_pre_probe_main.cc" core/CMakeLists.txt >/dev/null
grep -F "target_link_libraries(linuxcnc_rs274_wasm_safe_probe PRIVATE fmt)" core/CMakeLists.txt >/dev/null
grep -F "add_custom_target(linuxcnc_rs274_wasm_blocked_sources" core/CMakeLists.txt >/dev/null
grep -F "LinuxCNC source root does not exist" core/CMakeLists.txt >/dev/null
grep -F 'if(NOT IS_DIRECTORY "${CNC_SIM_LINUXCNC_ROOT_ABS}")' core/CMakeLists.txt >/dev/null
grep -F "Missing LinuxCNC wasm source manifest" core/CMakeLists.txt >/dev/null
grep -F 'if(NOT EXISTS "${CNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST}")' core/CMakeLists.txt >/dev/null
grep -F "LinuxCNC wasm source manifest is not a file" core/CMakeLists.txt >/dev/null
grep -F 'if(IS_DIRECTORY "${CNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST}")' core/CMakeLists.txt >/dev/null
grep -F "Bad LinuxCNC wasm source manifest line" core/CMakeLists.txt >/dev/null
grep -F "LinuxCNC wasm manifest source does not exist" core/CMakeLists.txt >/dev/null
grep -F 'if(NOT EXISTS "${manifest_source}")' core/CMakeLists.txt >/dev/null
grep -F "LinuxCNC wasm manifest source is not a file" core/CMakeLists.txt >/dev/null
grep -F 'if(IS_DIRECTORY "${manifest_source}")' core/CMakeLists.txt >/dev/null
awk '
/set\(manifest_source/ { manifest_source = NR }
/Unknown LinuxCNC wasm source manifest group/ { unknown_group = NR }
END { exit !(unknown_group && manifest_source && unknown_group < manifest_source) }
' core/CMakeLists.txt
grep -F "LinuxCNC wasm source manifest has no core entries" core/CMakeLists.txt >/dev/null
grep -F "LinuxCNC wasm source manifest has no blocked entries" core/CMakeLists.txt >/dev/null
if ! command -v cmake >/dev/null 2>&1; then
echo "cmake not found; skipping linuxcnc wasm-safe CMake probe target"
exit 0
fi
cmake -S core -B "$build_dir" \
-DCMAKE_BUILD_TYPE=Release \
-DCNC_SIM_LINUXCNC_ROOT="$linuxcnc_root" \
-DCNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST="$manifest" \
-DCNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE=ON
cmake --build "$build_dir" --target linuxcnc_rs274_wasm_safe_probe_objects
cmake --build "$build_dir" --target linuxcnc_rs274_wasm_safe_probe
"$build_dir/linuxcnc_rs274_wasm_safe_probe"
echo "linuxcnc wasm-safe CMake probe target passed"