Procházet zdrojové kódy

makefile and github action for formatting

Jariullah Safi před 4 měsíci
rodič
revize
8e75220a18
3 změnil soubory, kde provedl 171 přidání a 0 odebrání
  1. 118 0
      .clang-format
  2. 25 0
      .github/workflows/format.yml
  3. 28 0
      Makefile

+ 118 - 0
.clang-format

@@ -0,0 +1,118 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Linux kernel clang-format style (https://github.com/torvalds/linux, .clang-format).
+# The upstream file's ~680-line ForEachMacros list is omitted: those entries only
+# affect formatting of the kernel's own iterator macros, none of which exist here,
+# so they have no effect on this codebase. Pin: clang-format 18 (see Makefile/CI).
+#
+# Docs: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass: false
+  AfterControlStatement: false
+  AfterEnum: false
+  AfterFunction: true
+  AfterNamespace: true
+  AfterObjCDeclaration: false
+  AfterStruct: false
+  AfterUnion: false
+  AfterExternBlock: false
+  BeforeCatch: false
+  BeforeElse: false
+  IndentBraces: false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+
+IncludeBlocks: Preserve
+IncludeCategories:
+  - Regex: '.*'
+    Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+IndentGotoLabels: false
+IndentPPDirectives: None
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatementsExceptForEachMacros
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...

+ 25 - 0
.github/workflows/format.yml

@@ -0,0 +1,25 @@
+name: Format
+
+on:
+  push:
+  pull_request:
+
+jobs:
+  clang-format:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Check out repository
+        uses: actions/checkout@v4
+
+      - name: Install clang-format
+        # Pinned to 18 so CI matches the version contributors run locally;
+        # clang-format output differs between major versions.
+        run: |
+          sudo apt-get update
+          sudo apt-get install -y clang-format-18
+
+      - name: Check formatting
+        # Fails the job (and blocks the PR) the moment any file differs from
+        # the Linux kernel .clang-format style. Run `make format` to fix.
+        run: make format-check

+ 28 - 0
Makefile

@@ -0,0 +1,28 @@
+# OpenPuck developer convenience targets.
+
+# Pin to clang-format 18 to match CI; output differs between versions, so a
+# mismatch would make CI reject locally-formatted code. Resolve the binary in
+# order of preference: the apt-style versioned name (CI / Linux), the Homebrew
+# llvm@18 keg (macOS), then a bare clang-format as a last resort. Override with
+# `make format CLANG_FORMAT=/path/to/clang-format` if yours lives elsewhere.
+CLANG_FORMAT ?= $(shell command -v clang-format-18 \
+	|| ([ -x /opt/homebrew/opt/llvm@18/bin/clang-format ] && echo /opt/homebrew/opt/llvm@18/bin/clang-format) \
+	|| ([ -x /usr/local/opt/llvm@18/bin/clang-format ] && echo /usr/local/opt/llvm@18/bin/clang-format) \
+	|| command -v clang-format)
+
+# All hand-written C/C++ sources. Generated headers (git_version.h) are
+# gitignored and excluded here so formatting never touches them.
+FORMAT_FILES := $(shell find OpenPuck puck_sniffer pairtui \
+	\( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' -o -name '*.ino' \) \
+	-not -name 'git_version.h')
+
+.PHONY: format format-check
+
+## Reformat all C/C++ sources in place using the Linux kernel style.
+format:
+	$(CLANG_FORMAT) -i $(FORMAT_FILES)
+
+## Verify all C/C++ sources are formatted; exit non-zero if any differ.
+## Used by CI to reject unformatted code.
+format-check:
+	$(CLANG_FORMAT) --dry-run --Werror $(FORMAT_FILES)