From bc7b947d143f4b879949c6b3311d04bcaf3f3365 Mon Sep 17 00:00:00 2001 From: cnc Date: Wed, 3 Jun 2026 18:46:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E8=80=83=E6=89=80=E6=9C=89=E5=88=86?= =?UTF-8?q?=E7=BB=84=EF=BC=8C=E5=AE=8C=E6=88=90=E5=B0=BD=E9=87=8F=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AE=B9=EF=BC=9A=E6=94=B6=E7=B4=A7=20CMake?= =?UTF-8?q?=20=E6=BA=90=E5=88=97=E8=A1=A8=E5=8F=82=E6=95=B0=E5=AE=88?= =?UTF-8?q?=E5=8D=AB=EF=BC=8C=E7=BB=93=E8=AE=BA=E6=B5=8B=E8=AF=95=E9=80=9A?= =?UTF-8?q?=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list-cmake-set-plus-append-sources.sh | 12 +++++++++ list-cmake-set-sources.sh | 8 ++++++ test-all-native.sh | 38 +++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/list-cmake-set-plus-append-sources.sh b/list-cmake-set-plus-append-sources.sh index 13140b9..ef9111d 100755 --- a/list-cmake-set-plus-append-sources.sh +++ b/list-cmake-set-plus-append-sources.sh @@ -15,6 +15,18 @@ fi set_name=$1 append_name=$2 relative_prefix=${3:-} +if ! [[ "$set_name" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then + echo "CMake source set name must be a CMake variable name: $set_name" >&2 + exit 1 +fi +if ! [[ "$append_name" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then + echo "CMake append source set name must be a CMake variable name: $append_name" >&2 + exit 1 +fi +if [[ "$relative_prefix" = /* || "$relative_prefix" == .. || "$relative_prefix" == ../* || "$relative_prefix" == */.. || "$relative_prefix" == */../* ]]; then + echo "CMake source relative prefix must stay project-relative: $relative_prefix" >&2 + exit 1 +fi awk -v set_name="$set_name" -v append_name="$append_name" -v relative_prefix="$relative_prefix" ' $0 ~ "^[[:space:]]*set\\(" set_name "([[:space:]]|$)" { diff --git a/list-cmake-set-sources.sh b/list-cmake-set-sources.sh index e4ba9f4..2dc535f 100755 --- a/list-cmake-set-sources.sh +++ b/list-cmake-set-sources.sh @@ -14,6 +14,14 @@ fi set_name=$1 relative_prefix=${2:-} +if ! [[ "$set_name" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then + echo "CMake source set name must be a CMake variable name: $set_name" >&2 + exit 1 +fi +if [[ "$relative_prefix" = /* || "$relative_prefix" == .. || "$relative_prefix" == ../* || "$relative_prefix" == */.. || "$relative_prefix" == */../* ]]; then + echo "CMake source relative prefix must stay project-relative: $relative_prefix" >&2 + exit 1 +fi awk -v set_name="$set_name" -v relative_prefix="$relative_prefix" ' $0 ~ "^[[:space:]]*set\\(" set_name "([[:space:]]|$)" { diff --git a/test-all-native.sh b/test-all-native.sh index bdcb81d..a7c7510 100755 --- a/test-all-native.sh +++ b/test-all-native.sh @@ -31,6 +31,8 @@ missing_bridge_source_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_bridge_smoke escaped_project_source_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_escaped_project_source.XXXXXX.log") missing_cmake_set_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_cmake_set.XXXXXX.log") missing_cmake_append_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_cmake_append.XXXXXX.log") +invalid_cmake_set_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_invalid_cmake_set.XXXXXX.log") +escaped_cmake_prefix_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_escaped_cmake_prefix.XXXXXX.log") missing_support_object_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_missing_linuxcnc_support_object.XXXXXX.log") missing_source_manifest=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_native_syntax_missing_source_manifest.XXXXXX.txt") missing_source_log=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_native_syntax_missing_source.XXXXXX.log") @@ -63,6 +65,8 @@ cleanup_native_test_temps() { "$escaped_project_source_log" \ "$missing_cmake_set_log" \ "$missing_cmake_append_log" \ + "$invalid_cmake_set_log" \ + "$escaped_cmake_prefix_log" \ "$missing_support_object_log" \ "$missing_source_manifest" \ "$missing_source_log" \ @@ -180,6 +184,8 @@ for forbidden_manual_cleanup in \ 'rm -f "$escaped_project_source_log"' \ 'rm -f "$missing_cmake_set_log"' \ 'rm -f "$missing_cmake_append_log"' \ + 'rm -f "$invalid_cmake_set_log"' \ + 'rm -f "$escaped_cmake_prefix_log"' \ 'rm -f "$missing_support_object_log"' \ 'rm -f "$missing_source_manifest" "$missing_source_log"' \ 'rm -f "$kinematics_unknown_filter_log"' \ @@ -220,6 +226,9 @@ fi grep -F 'exec 9>"${TMPDIR:-/tmp}/cnc_sim_rs274_source_link.lock"' test-linuxcnc-source-link.sh >/dev/null grep -F "flock 9" test-linuxcnc-source-link.sh >/dev/null grep -F "missing LinuxCNC support object" list-linuxcnc-source-support-objects.sh >/dev/null +grep -F 'CMake source set name must be a CMake variable name: $set_name' list-cmake-set-sources.sh >/dev/null +grep -F 'CMake append source set name must be a CMake variable name: $append_name' list-cmake-set-plus-append-sources.sh >/dev/null +grep -F 'CMake source relative prefix must stay project-relative: $relative_prefix' list-cmake-set-sources.sh >/dev/null grep -F 'missing CMake source set: " set_name' list-cmake-set-sources.sh >/dev/null grep -F 'missing CMake append source set: " append_name' list-cmake-set-plus-append-sources.sh >/dev/null grep -F 'echo "$missing_path_message: $path"' list-filtered-existing-paths.sh >/dev/null @@ -245,6 +254,35 @@ if ! grep -F "missing CMake append source set: does_not_exist_append_set" "$miss sed -n '1,20p' "$missing_cmake_append_log" >&2 exit 1 fi +if ./list-cmake-set-sources.sh 'cnc_sim_core_sources.*' >"$invalid_cmake_set_log" 2>&1; then + echo "CMake source-set lister accepted a regex-like set name" >&2 + exit 1 +fi +if ! grep -F "CMake source set name must be a CMake variable name: cnc_sim_core_sources.*" "$invalid_cmake_set_log" >/dev/null; then + echo "CMake source-set lister did not report invalid set names clearly" >&2 + sed -n '1,20p' "$invalid_cmake_set_log" >&2 + exit 1 +fi +if ./list-cmake-set-plus-append-sources.sh \ + cnc_sim_core_sources \ + 'cnc_sim_core_sources.*' >"$invalid_cmake_set_log" 2>&1; then + echo "combined CMake source-set lister accepted a regex-like append set name" >&2 + exit 1 +fi +if ! grep -F "CMake append source set name must be a CMake variable name: cnc_sim_core_sources.*" "$invalid_cmake_set_log" >/dev/null; then + echo "combined CMake source-set lister did not report invalid append set names clearly" >&2 + sed -n '1,20p' "$invalid_cmake_set_log" >&2 + exit 1 +fi +if ./list-cmake-set-sources.sh cnc_sim_core_sources ../core/ >"$escaped_cmake_prefix_log" 2>&1; then + echo "CMake source-set lister accepted an escaped relative prefix" >&2 + exit 1 +fi +if ! grep -F "CMake source relative prefix must stay project-relative: ../core/" "$escaped_cmake_prefix_log" >/dev/null; then + echo "CMake source-set lister did not report escaped relative prefixes clearly" >&2 + sed -n '1,20p' "$escaped_cmake_prefix_log" >&2 + exit 1 +fi if printf '../core/src/canon_event_sink.cpp\n' | ./list-filtered-existing-paths.sh \ --project-relative \ "" \