From a214e7fdb6e4d8bc505e03ee64fd4517444b742a Mon Sep 17 00:00:00 2001 From: Ramid Khan Date: Fri, 17 Jan 2025 14:15:59 +1100 Subject: [PATCH] Add clang-format to build --- .clang-format | 65 +++++++++++++++++++++++++++++++++++++ .github/workflows/style.yml | 3 ++ tools/clang-format.sh | 15 +++++++++ 3 files changed, 83 insertions(+) create mode 100644 .clang-format create mode 100755 tools/clang-format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..3ec42c7 --- /dev/null +++ b/.clang-format @@ -0,0 +1,65 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: None +AlignConsecutiveMacros: true +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +BreakAfterReturnType: None +BreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: false +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 +CompactNamespaces: false +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentPPDirectives: AfterHash +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index cfaacbd..f5b594b 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -6,8 +6,11 @@ on: jobs: build: runs-on: ubuntu-latest + continue-on-error: true steps: - name: Checkout repository uses: actions/checkout@v4 - name: Check simple style run: ./tools/simple-style.sh + - name: Clang format + run: ./tools/clang-format.sh --dry-run --Werror diff --git a/tools/clang-format.sh b/tools/clang-format.sh new file mode 100755 index 0000000..f713146 --- /dev/null +++ b/tools/clang-format.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if ! command -v "${CLANG_FORMAT}" &>/dev/null; then + CLANG_FORMAT=clang-format-19 +fi + +if ! command -v "${CLANG_FORMAT}" &>/dev/null; then + CLANG_FORMAT=clang-format-18 +fi + +if ! command -v "${CLANG_FORMAT}" &>/dev/null; then + CLANG_FORMAT=clang-format +fi + +find kernel/src/ \( -iname '*.h' -o -iname '*.c' \) -print0 | xargs -0 "${CLANG_FORMAT}" "$@" -i