Skip to content

Commit 4d68718

Browse files
authored
Merge pull request #331 from padelsbach/padelsbach/check-file-lists
Add script to check source file lists, move comment style check to a script
2 parents 69550dc + 2eac03b commit 4d68718

5 files changed

Lines changed: 271 additions & 77 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Check File Lists
2+
3+
on:
4+
pull_request:
5+
branches: [ '*' ]
6+
7+
jobs:
8+
check-file-lists:
9+
runs-on: ubuntu-latest
10+
name: Check build file lists in sync
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Check file lists
17+
run: ./scripts/check-file-lists.sh

.github/workflows/comment-style-check.yml

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -19,81 +19,5 @@ jobs:
1919
with:
2020
fetch-depth: 0
2121

22-
- name: Get changed files
23-
id: changed-files
24-
run: |
25-
# Get list of changed .java and .c/.h files in this PR
26-
git diff --name-only --diff-filter=AM origin/${{ github.base_ref }}...HEAD | \
27-
grep -E '\.(java|c|h)$' > changed_files.txt || echo "No matching files found"
28-
29-
if [ -s changed_files.txt ]; then
30-
echo "Found changed files:"
31-
cat changed_files.txt
32-
echo "has_files=true" >> $GITHUB_OUTPUT
33-
else
34-
echo "No .java, .c, or .h files changed in this PR"
35-
echo "has_files=false" >> $GITHUB_OUTPUT
36-
fi
37-
3822
- name: Check for single-line comments in changed files
39-
if: steps.changed-files.outputs.has_files == 'true'
40-
run: |
41-
violations_found=false
42-
43-
while IFS= read -r file; do
44-
if [ -f "$file" ]; then
45-
echo "Checking $file for comment style violations..."
46-
47-
# Find potential single-line comments (//)
48-
# This is a simple check that may have some false positives
49-
# but catches the most common violations
50-
violations=$(grep -n '//' "$file" | \
51-
grep -v 'http://' | \
52-
grep -v 'https://' | \
53-
grep -v -E '/\*.*//.*\*/' | \
54-
grep -v -E '"[^"]*//[^"]*"' | \
55-
grep -E ':[[:space:]]*//' || true)
56-
57-
if [ -n "$violations" ]; then
58-
echo "❌ Single-line comments found in $file:"
59-
echo "$violations"
60-
echo ""
61-
violations_found=true
62-
else
63-
echo "✅ $file: No single-line comment violations found"
64-
fi
65-
fi
66-
done < changed_files.txt
67-
68-
if [ "$violations_found" = true ]; then
69-
echo ""
70-
echo "=================================="
71-
echo "❌ COMMENT STYLE CHECK FAILED"
72-
echo "=================================="
73-
echo ""
74-
echo "Single-line comments (//) were found in the changed files."
75-
echo "According to the coding standard in CLAUDE.md:"
76-
echo "- MUST only use multi-line comments, no \"//\" style ones"
77-
echo ""
78-
echo "Please replace all single-line comments (//) with multi-line comments (/* */)."
79-
echo ""
80-
echo "Examples:"
81-
echo " ❌ Bad: // This is a comment"
82-
echo " ✅ Good: /* This is a comment */"
83-
echo ""
84-
echo " ❌ Bad: // TODO: implement this"
85-
echo " ✅ Good: /* TODO: implement this */"
86-
echo ""
87-
exit 1
88-
else
89-
echo ""
90-
echo "=================================="
91-
echo "✅ COMMENT STYLE CHECK PASSED"
92-
echo "=================================="
93-
echo "All changed files follow the multi-line comment style standard."
94-
fi
95-
96-
- name: Comment style check skipped
97-
if: steps.changed-files.outputs.has_files == 'false'
98-
run: |
99-
echo "✅ Comment style check skipped - no .java, .c, or .h files were changed in this PR"
23+
run: ./scripts/comment-style-check.sh "${{ github.base_ref }}"

platform/android_aosp/wolfssljni/Android.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ LOCAL_SRC_FILES := \
3838
native/com_wolfssl_WolfSSL.c \
3939
native/com_wolfssl_WolfSSLCertificate.c \
4040
native/com_wolfssl_WolfSSLCertManager.c \
41+
native/com_wolfssl_WolfSSLCertRequest.c \
4142
native/com_wolfssl_WolfSSLContext.c \
43+
native/com_wolfssl_WolfSSLNameConstraints.c \
4244
native/com_wolfssl_WolfSSLSession.c \
45+
native/com_wolfssl_WolfSSLX509Name.c \
4346
native/com_wolfssl_WolfSSLX509StoreCtx.c
4447
LOCAL_C_INCLUDES := \
4548
$(LOCAL_PATH)/native \

scripts/check-file-lists.sh

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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

scripts/comment-style-check.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
3+
# Comment Style Check Script
4+
# Checks that .java, .c, and .h files use multi-line comments (/* */)
5+
# instead of single-line comments (//).
6+
#
7+
# Usage:
8+
# comment-style-check.sh <base_ref>
9+
#
10+
# Arguments:
11+
# base_ref - The base branch to diff against (e.g., "main")
12+
13+
set -euo pipefail
14+
15+
if [ $# -lt 1 ]; then
16+
echo "Usage: $0 <base_ref>"
17+
exit 1
18+
fi
19+
20+
BASE_REF="$1"
21+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
22+
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
23+
CHANGED_FILES="$(mktemp -t changed_files.XXXXXX)"
24+
trap 'rm -f "$CHANGED_FILES"' EXIT
25+
26+
cd "$REPO_ROOT"
27+
28+
# Get list of changed .java and .c/.h files
29+
DIFF_OUTPUT="$(git diff --name-only --diff-filter=AM "origin/${BASE_REF}...HEAD")"
30+
printf '%s\n' "$DIFF_OUTPUT" | grep -E '\.(java|c|h)$' > "$CHANGED_FILES" || true
31+
32+
if [ ! -s "$CHANGED_FILES" ]; then
33+
echo "✅ Comment style check skipped - no .java, .c, or .h files were changed in this PR"
34+
exit 0
35+
fi
36+
37+
echo "Found changed files:"
38+
cat "$CHANGED_FILES"
39+
40+
violations_found=false
41+
42+
while IFS= read -r file; do
43+
if [ -f "$file" ]; then
44+
echo "Checking $file for comment style violations..."
45+
46+
# Find potential single-line comments (//)
47+
# This is a simple check that may have some false positives
48+
# but catches the most common violations
49+
violations=$(grep -n '//' "$file" | \
50+
grep -v 'http://' | \
51+
grep -v 'https://' | \
52+
grep -v -E '/\*.*//.*\*/' | \
53+
grep -v -E '"[^"]*//[^"]*"' || true)
54+
55+
if [ -n "$violations" ]; then
56+
echo "❌ Single-line comments found in $file:"
57+
echo "$violations"
58+
echo ""
59+
violations_found=true
60+
else
61+
echo "$file: No single-line comment violations found"
62+
fi
63+
fi
64+
done < "$CHANGED_FILES"
65+
66+
if [ "$violations_found" = true ]; then
67+
echo ""
68+
echo "=================================="
69+
echo "❌ COMMENT STYLE CHECK FAILED"
70+
echo "=================================="
71+
echo ""
72+
echo "Single-line comments (//) were found in the changed files."
73+
echo "According to the coding standard in CLAUDE.md:"
74+
echo "- MUST only use multi-line comments, no \"//\" style ones"
75+
echo ""
76+
echo "Please replace all single-line comments (//) with multi-line comments (/* */)."
77+
echo ""
78+
echo "Examples:"
79+
echo " ❌ Bad: // This is a comment"
80+
echo " ✅ Good: /* This is a comment */"
81+
echo ""
82+
echo " ❌ Bad: // TODO: implement this"
83+
echo " ✅ Good: /* TODO: implement this */"
84+
echo ""
85+
exit 1
86+
else
87+
echo ""
88+
echo "=================================="
89+
echo "✅ COMMENT STYLE CHECK PASSED"
90+
echo "=================================="
91+
echo "All changed files follow the multi-line comment style standard."
92+
fi

0 commit comments

Comments
 (0)