Skip to content

PHPC-1118: Add detection of the correct clang-format binary #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: []
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
Expand All @@ -55,7 +54,6 @@ IncludeCategories:
- Regex: '.*'
Priority: 1
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
Expand Down
24 changes: 23 additions & 1 deletion scripts/clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ if test x"$1" = xchanged; then
FILES="$FILES1 $FILES2 $FILES3"
fi

# Find clang-format, we prefer -6.0, but also allow binaries without -suffix as
# long as they're >= 6.0.0
CLANG_FORMAT=`which clang-format-6.0`

if [ -z "$CLANG_FORMAT" ]; then
CLANG_FORMAT=`which clang-format`
fi

if [ -z "$CLANG_FORMAT" ]; then
echo "Couldn't find clang-format"
exit
fi

VERSION=`$CLANG_FORMAT -version | cut -d " " -f 3`
VERSION_MAJOR=`echo $VERSION | cut -d "." -f 1`

if [ $VERSION_MAJOR -lt 6 ]; then
echo "Found clang-format $VERSION but we need >= 6.0.0"
exit
fi

# Run formatter
for i in $FILES; do
clang-format-7 -i $i
$CLANG_FORMAT -i $i
done