Skip to content
Draft
77 changes: 77 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
Language: Cpp
# BasedOnStyle: Chromium
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
AfterNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: WebKit
BreakBeforeTernaryOperators: true
BreakStringLiterals: true
ColumnLimit: 150
CommentPragmas: '^ IWYU pragma:'
ContinuationIndentWidth: 4
DerivePointerAlignment: false
IncludeBlocks: Preserve
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
CompactNamespaces: false
KeepEmptyLinesAtTheStartOfBlocks: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: Never
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ on:
- master

jobs:
clang-format-check:
runs-on: macos-11
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Install clang-format
run: |
brew install clang-format
clang-format --version
- name: Run clang format check
run: |
bash scripts/check-clang.sh

mac-os-build-clang:
runs-on: macos-12
env:
Expand Down
29 changes: 29 additions & 0 deletions scripts/check-clang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

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

if NOT type $CLANG_FORMAT 2> /dev/null ; then
echo "No appropriate clang-format found."
exit 1
fi

FAIL=0
SOURCE_FILES=`find src samples -type f \( -name '*.h' -o -name '*.c' \) -not -path "*/external/*"`
echo "Performing clang format compliance check...."
for i in $SOURCE_FILES
do
$CLANG_FORMAT -output-replacements-xml $i | grep -c "<replacement " > /dev/null
if [ $? -ne 1 ]
then
echo "$i failed clang-format check."
FAIL=1
fi
done

if [ $FAIL -ne 1 ]; then
echo "Clang check passed for the project"
fi

exit $FAIL
39 changes: 39 additions & 0 deletions scripts/clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
parse_args() {
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-f)
echo "Clang formatting the files specified"
clang-format -style=file -i -fallback-style=none $2
shift # past argument
shift # past value
;;
-d)
echo "Clang formatting all files in the directory"
find $2 -iname *.h -o -iname *.cpp -o -iname *.h | xargs clang-format -style=file -i -fallback-style=none
shift # past argument
shift # past value
;;
-g)
echo "Clang formatting only git diff'ed output"
clang-format -style=file -fallback-style=none -i `git ls-files -om "*.[ch]"`
shift # past argument
;;
-h|--help)
echo "-f: Pass list of files to be clang formatted"
echo "-a: Clang format all files in the project"
echo "-d: Clang format all files in the directory passed after this option"
echo "-g: Clang formatting only git diff'ed output"
exit 0
;;
*) # unknown option
echo "Unknown option $key"
exit 1
;;
esac
done
}

parse_args $@