mirror of
https://github.com/HarbourMasters/Shipwright
synced 2026-06-19 16:00:27 -04:00
d912fd2c01
Recent distros and Homebrew ship only newer clang-format, so contributors can't easily get the version CI uses (14, matching the OoT/MM decomp). - docs/FORMATTING.md: how to get a 14.x binary (apt, AUR, muttleyxd static binaries, uvx/pipx wheel, brew) and how to run the formatter. - run-clang-format.sh: default to clang-format-14 but honor $CLANG_FORMAT so any matching binary works. Any 14.x produces byte-identical output here. - .pre-commit-config.yaml: opt-in hook to format staged C/C++ on commit. - README: link the new doc. The llvm@14 formula is available on Linux too, so filing it under a macOS-only heading was too narrow. * Support spaced paths in CLANG_FORMAT; document run-clang-format.ps1 eval the clang-format invocation so CLANG_FORMAT can carry arguments (uvx clang-format@14) or a quoted path with spaces without one breaking the other. The NUL-separated file list reaches xargs over the pipe, so filenames never pass through eval. Document the native Windows run-clang-format.ps1 path alongside the Git Bash/WSL route. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
37 lines
1.5 KiB
Bash
Executable File
37 lines
1.5 KiB
Bash
Executable File
# Default to clang-format-14; override CLANG_FORMAT to use another 14.x binary
|
|
# (distro pkg, muttleyxd static binary, uvx clang-format@14, ...). See docs/FORMATTING.md.
|
|
CLANG_FORMAT="${CLANG_FORMAT:-clang-format-14}"
|
|
|
|
# this line does quite a bit, so let's break it down
|
|
#
|
|
# find soh
|
|
# use "find" to look in the "soh" directory
|
|
# this ensures we don't try to format stuff in the submodules
|
|
#
|
|
# -type f
|
|
# only look for files
|
|
#
|
|
# -name "*.c" -o -name "*.cpp"
|
|
# find all .c and .cpp files
|
|
#
|
|
# ( -name "*.h" -o -name "*.hpp" ) ! -path "soh/src/**.h" ! -path "soh/include/**.h"
|
|
# find all .h and .hpp files that aren't in soh/src or soh/include
|
|
# this is because zret decomp only runs clang-format on c files
|
|
# https://github.com/zeldaret/mm/blob/b7e5468ca16315a7e322055eff3d97fe980bbc25/format.py#L182
|
|
#
|
|
# ! -path "soh/assets/*"
|
|
# asset headers are autogenerated, don't fight them
|
|
#
|
|
# -print0
|
|
# separate paths with NUL bytes, avoiding issues with spaces in paths
|
|
#
|
|
# | eval "xargs -0 $CLANG_FORMAT -i --verbose"
|
|
# use xargs to take each path we've found
|
|
# and pass it as an argument to clang-format
|
|
# verbose to print files being formatted and X out of Y status
|
|
# eval so CLANG_FORMAT can carry arguments ("uvx clang-format@14")
|
|
# or a quoted path with spaces; the NUL-separated file list reaches
|
|
# xargs over the pipe, so it never passes through eval
|
|
|
|
find soh -type f \( -name "*.c" -o -name "*.cpp" -o \( \( -name "*.h" -o -name "*.hpp" \) ! -path "soh/src/*" ! -path "soh/include/*" \) \) ! -path "soh/assets/*" -print0 | eval "xargs -0 $CLANG_FORMAT -i --verbose"
|