|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Checks that manually-maintained file lists across build/project files stay |
| 4 | +# in sync with the actual source files on disk. |
| 5 | +# |
| 6 | +# Checked lists: |
| 7 | +# Java files : scripts/infer.sh |
| 8 | +# Native .c : IDE/WIN/wolfssljni.vcxproj |
| 9 | +# IDE/WIN/wolfssljni.vcxproj.filters |
| 10 | +# IDE/Android/app/src/main/cpp/CMakeLists.txt |
| 11 | +# platform/android_aosp/wolfssljni/Android.mk |
| 12 | +# Native .h : IDE/WIN/wolfssljni.vcxproj |
| 13 | +# IDE/WIN/wolfssljni.vcxproj.filters |
| 14 | +# |
| 15 | +# Run from wolfssljni root: |
| 16 | +# ./scripts/check-file-lists.sh |
| 17 | +# |
| 18 | +# Returns 0 if all lists match, 1 if any mismatch is found. |
| 19 | + |
| 20 | +set -euo pipefail |
| 21 | + |
| 22 | +# cd to repo root (parent of scripts/) |
| 23 | +cd "$(dirname "$0")/.." || exit 1 |
| 24 | + |
| 25 | +FAIL=0 |
| 26 | + |
| 27 | +# ---------------------- helper functions ---------------------- |
| 28 | + |
| 29 | +# Print a sorted, newline-delimited list to stdout. Arguments are the items. |
| 30 | +sort_list() { |
| 31 | + printf '%s\n' "$@" | sort |
| 32 | +} |
| 33 | + |
| 34 | +# Compare two sorted lists (passed as strings with newline separators). |
| 35 | +# $1 = label for first list |
| 36 | +# $2 = first list (newline-separated) |
| 37 | +# $3 = label for second list |
| 38 | +# $4 = second list (newline-separated) |
| 39 | +compare_lists() { |
| 40 | + local label_a="$1" list_a="$2" label_b="$3" list_b="$4" |
| 41 | + local only_a only_b |
| 42 | + |
| 43 | + only_a=$(comm -23 <(echo "$list_a") <(echo "$list_b")) |
| 44 | + only_b=$(comm -13 <(echo "$list_a") <(echo "$list_b")) |
| 45 | + |
| 46 | + if [ -n "$only_a" ] || [ -n "$only_b" ]; then |
| 47 | + echo "MISMATCH between $label_a and $label_b" |
| 48 | + if [ -n "$only_a" ]; then |
| 49 | + echo " In $label_a but not $label_b:" |
| 50 | + echo "$only_a" | sed 's/^/ /' |
| 51 | + fi |
| 52 | + if [ -n "$only_b" ]; then |
| 53 | + echo " In $label_b but not $label_a:" |
| 54 | + echo "$only_b" | sed 's/^/ /' |
| 55 | + fi |
| 56 | + echo |
| 57 | + FAIL=1 |
| 58 | + fi |
| 59 | +} |
| 60 | + |
| 61 | +# ---------------------- collect actual files on disk ---------------------- |
| 62 | + |
| 63 | +# Java source files (non-test), paths relative to repo root |
| 64 | +DISK_JAVA=$(find src/java -name '*.java' -not -path '*/test/*' | sort) |
| 65 | + |
| 66 | +# Native .c files – basenames only (each manifest uses different path prefixes) |
| 67 | +DISK_C=$(find native -maxdepth 1 -name '*.c' -exec basename {} \; | sort) |
| 68 | + |
| 69 | +# Native .h files – basenames only |
| 70 | +DISK_H=$(find native -maxdepth 1 -name '*.h' -exec basename {} \; | sort) |
| 71 | + |
| 72 | +# ======================== Java source checks ======================== |
| 73 | + |
| 74 | +echo "Checking Java source files in scripts/infer.sh..." |
| 75 | + |
| 76 | +# --- scripts/infer.sh --- |
| 77 | +INFER_JAVA=$(grep '\.java' scripts/infer.sh \ |
| 78 | + | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*\\$//' \ |
| 79 | + | sort) |
| 80 | + |
| 81 | +compare_lists "disk (src/java)" "$DISK_JAVA" \ |
| 82 | + "scripts/infer.sh" "$INFER_JAVA" |
| 83 | + |
| 84 | +# ======================== Native .c checks ======================== |
| 85 | + |
| 86 | +# --- IDE/WIN/wolfssljni.vcxproj --- |
| 87 | +echo "Checking native .c files in IDE/WIN/wolfssljni.vcxproj..." |
| 88 | +VCXPROJ_C=$(grep '<ClCompile Include=' IDE/WIN/wolfssljni.vcxproj \ |
| 89 | + | sed 's/.*Include="[^"]*\\\([^"\\]*\)".*/\1/' \ |
| 90 | + | sort) |
| 91 | + |
| 92 | +compare_lists "disk (native/*.c)" "$DISK_C" \ |
| 93 | + "IDE/WIN/wolfssljni.vcxproj <ClCompile>" "$VCXPROJ_C" |
| 94 | + |
| 95 | +# --- IDE/WIN/wolfssljni.vcxproj.filters --- |
| 96 | +echo "Checking native .c files in IDE/WIN/wolfssljni.vcxproj.filters..." |
| 97 | +FILTERS_C=$(grep '<ClCompile Include=' IDE/WIN/wolfssljni.vcxproj.filters \ |
| 98 | + | sed 's/.*Include="[^"]*\\\([^"\\]*\)".*/\1/' \ |
| 99 | + | sort) |
| 100 | + |
| 101 | +compare_lists "IDE/WIN/wolfssljni.vcxproj <ClCompile>" "$VCXPROJ_C" \ |
| 102 | + "IDE/WIN/wolfssljni.vcxproj.filters <ClCompile>" "$FILTERS_C" |
| 103 | + |
| 104 | +# --- IDE/Android/app/src/main/cpp/CMakeLists.txt --- |
| 105 | +# Extract files from the add_library(wolfssljni SHARED ...) block |
| 106 | +CMAKE=IDE/Android/app/src/main/cpp/CMakeLists.txt |
| 107 | +echo "Checking native .c files in $CMAKE..." |
| 108 | +CMAKE_C=$(sed -n '/^add_library(wolfssljni SHARED/,/^)/p' "$CMAKE" \ |
| 109 | + | grep '\.c' \ |
| 110 | + | sed 's|.*native/||; s/)//; s/^[[:space:]]*//' \ |
| 111 | + | sort) |
| 112 | + |
| 113 | +compare_lists "disk (native/*.c)" "$DISK_C" \ |
| 114 | + "CMakeLists.txt add_library(wolfssljni)" "$CMAKE_C" |
| 115 | + |
| 116 | +# --- platform/android_aosp/wolfssljni/Android.mk --- |
| 117 | +# Extract LOCAL_SRC_FILES from the native library section (after second |
| 118 | +# "include $(CLEAR_VARS)") |
| 119 | +AOSP_MK=platform/android_aosp/wolfssljni/Android.mk |
| 120 | +echo "Checking native .c files in $AOSP_MK..." |
| 121 | +AOSP_C=$(sed -n '/^# Create wolfSSL JNI native/,/^include \$(BUILD_SHARED_LIBRARY)/p' "$AOSP_MK" \ |
| 122 | + | grep '\.c' \ |
| 123 | + | sed 's|.*native/||; s/[[:space:]]*\\$//' \ |
| 124 | + | sed 's/^[[:space:]]*//' \ |
| 125 | + | sort) |
| 126 | + |
| 127 | +compare_lists "disk (native/*.c)" "$DISK_C" \ |
| 128 | + "platform/android_aosp/wolfssljni/Android.mk native" "$AOSP_C" |
| 129 | + |
| 130 | +# ======================== Native .h checks ======================== |
| 131 | + |
| 132 | +# --- IDE/WIN/wolfssljni.vcxproj --- |
| 133 | +echo "Checking native .h files in IDE/WIN/wolfssljni.vcxproj..." |
| 134 | +VCXPROJ_H=$(grep '<ClInclude Include=' IDE/WIN/wolfssljni.vcxproj \ |
| 135 | + | sed 's/.*Include="[^"]*\\\([^"\\]*\)".*/\1/' \ |
| 136 | + | sort) |
| 137 | + |
| 138 | +compare_lists "disk (native/*.h)" "$DISK_H" \ |
| 139 | + "IDE/WIN/wolfssljni.vcxproj <ClInclude>" "$VCXPROJ_H" |
| 140 | + |
| 141 | +# --- IDE/WIN/wolfssljni.vcxproj.filters --- |
| 142 | +echo "Checking native .h files in IDE/WIN/wolfssljni.vcxproj.filters..." |
| 143 | +FILTERS_H=$(grep '<ClInclude Include=' IDE/WIN/wolfssljni.vcxproj.filters \ |
| 144 | + | sed 's/.*Include="[^"]*\\\([^"\\]*\)".*/\1/' \ |
| 145 | + | sort) |
| 146 | + |
| 147 | +compare_lists "IDE/WIN/wolfssljni.vcxproj <ClInclude>" "$VCXPROJ_H" \ |
| 148 | + "IDE/WIN/wolfssljni.vcxproj.filters <ClInclude>" "$FILTERS_H" |
| 149 | + |
| 150 | +# ======================== Summary ======================== |
| 151 | + |
| 152 | +if [ "$FAIL" -eq 0 ]; then |
| 153 | + echo "All file lists are in sync." |
| 154 | + exit 0 |
| 155 | +else |
| 156 | + echo "File list mismatches detected (see above)." |
| 157 | + exit 1 |
| 158 | +fi |
0 commit comments