Skip to content

Commit

Permalink
fix build under clang (#45)
Browse files Browse the repository at this point in the history
* fix build under clang

* catch v2.0.1 → v2.13.10

* actions/checkout@v2 → v4

```
stm32
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/checkout@v2. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.
```

* try to switch llvm 12 → 18

* try revert to clang-format-12

* try fix clang format/tidy issues

* disable `modernize-macro-to-enum,`

* disable readability-identifier-length & bugprone-easily-swappable-parameters

* fix style
  • Loading branch information
serges147 authored May 6, 2024
1 parent fdd4d79 commit 46d3863
Show file tree
Hide file tree
Showing 8 changed files with 10,887 additions and 4,934 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: 'recursive'

Expand Down Expand Up @@ -44,23 +44,23 @@ jobs:
stm32:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Install Dependencies
run: |
sudo apt update
wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 12
sudo apt install clang-tidy-12 clang-format-12
wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 18
sudo apt install clang-tidy-18 clang-format-18
- name: Static analysis
working-directory: ${{github.workspace}}/stm32/libcanard/bxcan/
run: clang-tidy-12 src/*.c --extra-arg='-DBXCAN_MAX_IFACE_INDEX=1' --extra-arg='-DBXCAN_BUSYWAIT_DELAY_SYSTEM_CORE_CLOCK=72000000'
run: clang-tidy-18 src/*.c --extra-arg='-DBXCAN_MAX_IFACE_INDEX=1' --extra-arg='-DBXCAN_BUSYWAIT_DELAY_SYSTEM_CORE_CLOCK=72000000'

- name: Format check
working-directory: ${{github.workspace}}/stm32/libcanard/bxcan/
run: |
clang-format-12 -i -fallback-style=none -style=file --verbose src/*.[ch]
clang-format-18 -i -fallback-style=none -style=file --verbose src/*.[ch]
modified="$(git status --porcelain --untracked-files=no)"
if [ -n "$modified" ]; then echo "Please format code properly."; exit 1; fi
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ build/
cmake-build-*/
__pycache__/
dsdlc_generated/

# OS stuff
.DS_Store
*.bak
68 changes: 29 additions & 39 deletions socketcan/libcanard/.clang-format
Original file line number Diff line number Diff line change
@@ -1,67 +1,61 @@
---
Language: Cpp
# BasedOnStyle: LLVM
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
SplitEmptyRecord: false
AfterEnum: true
AfterStruct: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
AfterNamespace: true
AfterExternBlock: false
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
AfterExternBlock: false # Keeps the contents un-indented.
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom

BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
# BreakInheritanceList: AfterColon
BreakConstructorInitializers: BeforeComma
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ (coverity|pragma:)'
ColumnLimit: 120
CommentPragmas: '^ (coverity|pragma:)'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
DisableFormat: false
FixNamespaceComments: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeBlocks: Preserve
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakAssignment: 2
Expand All @@ -72,25 +66,21 @@ PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 10000 # Raised intentionally because it hurts readability
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
ReflowComments: true
SortIncludes: Never
SortUsingDeclarations: false
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeCtorInitializerColon: true
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
Standard: c++14
TabWidth: 8
UseTab: Never
...
2 changes: 1 addition & 1 deletion socketcan/libcanard/src/socketcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define KILO 1000L
#define MEGA (KILO * KILO)

static int16_t getNegatedErrno()
static int16_t getNegatedErrno(void)
{
const int out = -abs(errno);
if (out < 0)
Expand Down
Loading

0 comments on commit 46d3863

Please sign in to comment.