-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathformat.sh
More file actions
executable file
·36 lines (30 loc) · 1.04 KB
/
format.sh
File metadata and controls
executable file
·36 lines (30 loc) · 1.04 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
#!/bin/bash
# This script formats all source files in the workspace.
# It should be run from the workspace root, e.g., via `bazel run //:format`.
set -euo pipefail
if [ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]; then
cd ${BUILD_WORKSPACE_DIRECTORY}
fi
echo "Current directory: "$PWD
echo "Searching for files to format in workspace..."
# Find files and format them.
# -print0 and xargs -0 handle filenames with spaces or other special characters.
# Exclude bazel-* directories to avoid formatting generated files.
find . -type d -name "bazel-*" -prune -o -type f \( \
-name "*.h" \
-o -name "*.cpp" \
-o -name "*.hpp" \
-o -name "*.cu" \
-o -name "*.cuh" \
\) -print0 | xargs -0 clang-format-16 -style=file -i
find . -type f \( \
-name "*.bazel" \
-o -name "*.bzl" \
-o -name "BUILD" \
-o -name "WORKSPACE" \
\) -exec buildifier {} \;
# Format Python files using Black with Google style (line length 100)
find . -type d -name "bazel-*" -prune -o -type f \( \
-name "*.py" \
\) -print0 | xargs -0 black --target-version=py311
echo "Formatting complete."