Repository navigation
Expand file tree
/
Copy pathformat.sh
More file actions
executable file
·92 lines (72 loc) · 2.5 KB
/
Copy pathformat.sh
File metadata and controls
executable file
·92 lines (72 loc) · 2.5 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
#!/bin/bash
# format.sh - Format all C++ files in project
set -e
# Directories to format (excluding thirdparty/, scripts/, docs/, etc.)
DIRECTORIES=("collective" "ep" "p2p" "include" "experimental")
EXTENSIONS=("cpp" "cxx" "cc" "h" "hpp" "cu" "cuh")
EXCLUDE=(
"collective/afxdp/lib"
"experimental/lite/lite-collective/thirdparty"
)
REQUIRED_VERSION="14"
# Use CLANG_FORMAT if set; otherwise prefer clang-format-14, then fall back to clang-format
if [ -n "$CLANG_FORMAT" ]; then
:
elif command -v clang-format-14 &> /dev/null; then
CLANG_FORMAT="clang-format-14"
else
CLANG_FORMAT="clang-format"
fi
# Check if clang-format is installed
if ! command -v "$CLANG_FORMAT" &> /dev/null; then
echo "$CLANG_FORMAT could not be found. Please install clang-format-14 (e.g. pip install clang-format==14)."
exit 1
fi
# Ensure clang-format version is exactly 14.
# Use sed for portability (BSD grep on macOS does not support -P).
INSTALLED_VERSION=$("$CLANG_FORMAT" --version | sed -nE 's/.*[Vv]ersion[[:space:]]+([0-9]+)(\.[0-9]+){1,2}.*/\1/p' | head -1)
if [ "$INSTALLED_VERSION" != "$REQUIRED_VERSION" ]; then
echo "clang-format version $REQUIRED_VERSION is required. Found version: $INSTALLED_VERSION ($CLANG_FORMAT)."
echo "Install version 14 (e.g. apt install clang-format-14) or set CLANG_FORMAT=/path/to/clang-format-14."
exit 1
fi
echo "Formatting C++ files..."
EXCLUDE_ARGS=()
for EXC in "${EXCLUDE[@]}"; do
EXCLUDE_ARGS+=( -path "$EXC" -prune -o )
done
FILES=()
for DIR in "${DIRECTORIES[@]}"; do
if [ -d "$DIR" ]; then
for EXT in "${EXTENSIONS[@]}"; do
while IFS= read -r -d '' FILE; do
FILES+=("$FILE")
done < <(find "$DIR" "${EXCLUDE_ARGS[@]}" -type f -name "*.${EXT}" -print0)
done
fi
done
if [ ${#FILES[@]} -eq 0 ]; then
echo "No files to format."
exit 0
fi
for FILE in "${FILES[@]}"; do
echo "Formatting $FILE"
"$CLANG_FORMAT" -i "$FILE"
done
echo "Formatting Python files with black..."
PYTHON_DIRS=("p2p" "ep") # Adjust as needed
BLACK_EXCLUDES=("thirdparty" "docs" "build")
# Convert to exclude args
BLACK_EXCLUDE_ARGS=$(IFS="|"; echo "${BLACK_EXCLUDES[*]}")
if command -v black &>/dev/null; then
for DIR in "${PYTHON_DIRS[@]}"; do
if [ -d "$DIR" ]; then
echo " → $DIR"
black "$DIR" --exclude "$BLACK_EXCLUDE_ARGS"
fi
done
else
echo "black could not be found. Please install black (e.g. pip install black)."
exit 1
fi
echo "Formatting complete."