Skip to content
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
102 changes: 40 additions & 62 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,90 +1,68 @@
---
# SPDX-License-Identifier: MPL-2.0
#
# clang-format style for dlt-daemon
#
# Compatible with clang-format 14 and later.
# Install: sudo apt-get install clang-format-14
# Check: clang-format-14 --dry-run --Werror --style=file <file>
# Fix: clang-format-14 -i --style=file <file>
#
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
BasedOnStyle: WebKit
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: WebKit
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: BeforeComma
BreakStringLiterals: true
ColumnLimit: 120
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
MaxEmptyLinesToKeep: 3
NamespaceIndentation: None
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
PackConstructorInitializers: BinPack
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortIncludes: Never
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpaceBeforeRangeBasedForLoopColon: true
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInContainerLiterals: false
SpacesInParens: Never
SpacesInSquareBrackets: false
Standard: Cpp11
Standard: c++11
TabWidth: 4
UseTab: Never
PenaltyBreakBeforeFirstCallParameter: 0
PenaltyReturnTypeOnItsOwnLine: 10000
...

24 changes: 24 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#
# SPDX-License-Identifier: MPL-2.0
#
# Pre-commit hook for dlt-daemon
#
# Runs clang-format on staged C/C++ files via run_lint.sh.
# This mirrors the CI pipeline so issues are caught before push.
#
# To enable:
# ./run_lint.sh install-hook
#
# To bypass (emergency only):
# git commit --no-verify
#

set -euo pipefail

# Run from repo root so relative paths resolve correctly
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"

# Delegate to the shared lint script (check mode only - no auto-fix in hook)
./run_lint.sh check
31 changes: 31 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Clang Format

# Disabled until all clang-format violations are fixed.
# To re-enable, uncomment the on: block below.
# on:
# push:
# branches: [ "master" ]
# pull_request:
# branches: [ "master" ]
on:
workflow_dispatch:

jobs:
clang-format:
name: Clang Format
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install clang-format-14
run: |
wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-14 main" | sudo tee /etc/apt/sources.list.d/llvm.list
sudo apt-get update && sudo apt-get install -y clang-format-14

- name: Check formatting
run: CHECK_ALL=1 ./run_lint.sh check
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ you can [learn more](#learn-more) about advanced concepts and features.
## Overview

COVESA DLT provides a standardized logging and tracing interface with support for two protocol versions: **V1** and **V2**.

- **Version 1 (V1)** is based on the AUTOSAR Classic Platform specification [AUTOSAR Classic Platform R19-11 DLT](https://www.autosar.org/fileadmin/standards/R19-11/CP/AUTOSAR_SWS_DiagnosticLogAndTrace.pdf), offering a stable and widely adopted diagnostic logging protocol.
- **Version 2 (V2)** follows the updated AUTOSAR Classic Platform specification [AUTOSAR Classic Platform R22-11 DLT](https://www.autosar.org/fileadmin/standards/R22-11/CP/AUTOSAR_SWS_DiagnosticLogAndTrace.pdf). Currently released as a Minimum Viable Product (MVP), V2 supports a limited feature set.
For more details, refer to [DLT Daemon V2](doc/dlt_daemon_v2.md).
Expand Down Expand Up @@ -198,6 +198,56 @@ make generate_man
Start working, best practice is to commit smaller, compilable pieces during the
work that makes it easier to handle later on.

### Code Style

DLT uses **clang-format 14** to enforce a consistent code style. The style is
defined in [`.clang-format`](.clang-format) and is checked automatically by CI
on every push and pull request.

#### Install clang-format 14

On Ubuntu 20.04 (focal), add the LLVM toolchain repo and install:

```bash
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" | sudo tee /etc/apt/sources.list.d/llvm.list
sudo apt-get update
sudo apt-get install clang-format-14
```

On Ubuntu 22.04 (jammy), clang-format-14 is in the default repos:

```bash
sudo apt-get install clang-format-14
```

#### Check and fix formatting

Use the provided helper script:

```bash
# Install pre-commit hook and fix formatting (default)
./run_lint.sh

# Check formatting only (dry-run, fails on violations)
./run_lint.sh check

# Fix formatting only
./run_lint.sh fix
```

Or run clang-format directly on specific files:

```bash
clang-format-14 -i --style=file src/shared/dlt_common.c
```

#### Pre-commit hook

`./run_lint.sh` automatically installs the pre-commit hook (`.githooks/pre-commit`)
and fixes formatting. The hook runs `./run_lint.sh check` on staged C/C++ files
before each commit. To bypass it in an emergency, use `git commit --no-verify`.

If you want to commit your changes, create a
[Pull Request](https://github.com/covesa/dlt-daemon/pulls) in Github. Please
make sure to follow the
Expand Down
Loading
Loading