Skip to content

Commit

Permalink
Add graceful fallback to clang formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannavl committed Oct 10, 2023
1 parent 28a6bf2 commit 8eb54fd
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,22 @@ fmt_rs() {

fmt_cpp() {
echo "> fmt: cpp"
local clang_ver=${CLANG_DEFAULT_VERSION}
local clang_ver=${CLANG_DEFAULT_VERSION:-15}
local clang_formatters=("clang-format-${clang_ver}" "clang-format")
local index=-1
for ((idx=0; idx<${#clang_formatters[@]}; ++idx)); do
if "${clang_formatters[$idx]}" --version &> /dev/null; then
index="$idx"
break
fi
done
if [[ "$index" == -1 ]]; then
echo "No clang formatter found".
exit 1
fi

find src/masternodes \( -iname "*.cpp" -o -iname "*.h" \) \
-exec clang-format-"${clang_ver}" -i -style=file {} \;
-exec "${clang_formatters[$index]}" -i -style=file {} +;
}

fmt_lib() {
Expand Down

0 comments on commit 8eb54fd

Please sign in to comment.