forked from einoko/Tomato32
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.sh
More file actions
executable file
·159 lines (134 loc) · 3.15 KB
/
Copy pathformat.sh
File metadata and controls
executable file
·159 lines (134 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MODE="format"
usage() {
cat <<'EOF'
Usage: ./format.sh [--check]
Formats project code under app/ and platform/ (plus root CMake files), while
excluding lvgl/ and build output directories.
Options:
--check Verify formatting only (no file changes)
-h, --help Show this help
EOF
}
if [[ $# -gt 1 ]]; then
usage
exit 1
fi
if [[ $# -eq 1 ]]; then
case "$1" in
--check)
MODE="check"
;;
-h | --help)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
fi
cd "$ROOT_DIR"
if ! command -v clang-format >/dev/null 2>&1; then
echo "Error: clang-format is required but not installed." >&2
echo "Install on macOS: brew install clang-format" >&2
exit 1
fi
have_cmake_format="false"
if command -v cmake-format >/dev/null 2>&1; then
have_cmake_format="true"
fi
have_shfmt="false"
if command -v shfmt >/dev/null 2>&1; then
have_shfmt="true"
fi
clang_files=()
while IFS= read -r -d '' file; do
clang_files+=("$file")
done < <(
find app platform \
-type d \( -name lvgl -o -name build -o -name .git \) -prune -o \
-type f \( -name '*.c' -o -name '*.h' -o -name '*.cc' -o -name '*.cpp' -o -name '*.cxx' -o -name '*.hpp' \) \
-print0
)
if [[ -f lv_conf.h ]]; then
clang_files+=("lv_conf.h")
fi
cmake_files=()
while IFS= read -r -d '' file; do
cmake_files+=("$file")
done < <(
find . \
-type d \( -name .git -o -name lvgl -o -name build \) -prune -o \
-type f \( -name 'CMakeLists.txt' -o -name '*.cmake' \) \
-print0
)
sh_files=()
while IFS= read -r -d '' file; do
sh_files+=("$file")
done < <(
find app platform \
-type d \( -name lvgl -o -name build -o -name .git \) -prune -o \
-type f -name '*.sh' -print0
)
if [[ -f format.sh ]]; then
sh_files+=("format.sh")
fi
echo "Mode: $MODE"
echo "C/C++ files: ${#clang_files[@]}"
echo "CMake files: ${#cmake_files[@]}"
echo "Shell files: ${#sh_files[@]}"
if [[ "$MODE" == "check" ]]; then
if ((${#clang_files[@]} > 0)); then
for file in "${clang_files[@]}"; do
clang-format --dry-run --Werror "$file"
done
fi
if [[ "$have_cmake_format" == "true" ]]; then
if ((${#cmake_files[@]} > 0)); then
for file in "${cmake_files[@]}"; do
cmake-format --check "$file"
done
fi
else
echo "Warning: cmake-format not found; skipping CMake format checks." >&2
fi
if [[ "$have_shfmt" == "true" ]]; then
if ((${#sh_files[@]} > 0)); then
for file in "${sh_files[@]}"; do
shfmt -d "$file"
done
fi
else
echo "Warning: shfmt not found; skipping shell format checks." >&2
fi
echo "Formatting checks passed."
exit 0
fi
if ((${#clang_files[@]} > 0)); then
for file in "${clang_files[@]}"; do
clang-format -i "$file"
done
fi
if [[ "$have_cmake_format" == "true" ]]; then
if ((${#cmake_files[@]} > 0)); then
for file in "${cmake_files[@]}"; do
cmake-format -i "$file"
done
fi
else
echo "Warning: cmake-format not found; skipping CMake formatting." >&2
fi
if [[ "$have_shfmt" == "true" ]]; then
if ((${#sh_files[@]} > 0)); then
for file in "${sh_files[@]}"; do
shfmt -w "$file"
done
fi
else
echo "Warning: shfmt not found; skipping shell formatting." >&2
fi
echo "Formatting complete."