Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-format: Update to 16 #2139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
46 changes: 25 additions & 21 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
Expand All @@ -28,29 +30,30 @@ BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterExternBlock: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
SplitEmptyRecord: true
BreakAfterAttributes: Never
BreakAfterJavaFieldAnnotations: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakConstructorInitializersBeforeComma: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 140
CommentPragmas: '^ IWYU pragma:'
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
Expand All @@ -75,24 +78,26 @@ IncludeCategories:
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
- Regex: ".*"
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IncludeIsMainRegex: "(Test)?$"
IncludeIsMainSourceRegex: ""
IndentAccessModifiers: false
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 2
IndentWrappedFunctionNames: false
# Requires Clang >= 15, could also cause incorrect code formatting:
# InsertBraces: true
# Could lead to incorrect formatting, but I think that the tradeoff is worth it
InsertBraces: true
InsertNewlineAtEOF: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
LineEnding: LF
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PackConstructorInitializers: NextLine
Expand All @@ -107,35 +112,34 @@ PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReferenceAlignment: Pointer
ReflowComments: true
RemoveSemicolon: true
SeparateDefinitionBlocks: Always
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
SpaceAroundPointerQualifiers: Default
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
...
78 changes: 39 additions & 39 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ name: Code formatting

on:
pull_request:
branches: [ main ]
branches: [main]
paths:
- '**.cpp'
- '**.h'
- '!src/libs/**'
- '!src/FreeRTOS/**'
- "src/**.cpp"
- "src/**.h"
- "!src/libs/**"
- "!src/FreeRTOS/**"

jobs:
test-format:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1000

Expand All @@ -23,48 +23,48 @@ jobs:
- name: Install clang-format
run: |
sudo apt-get update
sudo apt-get -y install clang-format-14
sudo apt-get -y install clang-format-16

- name: Check formatting
run: tests/test-format.sh

- name: Upload patches
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
name: Patches
path: ./*.patch
test-clang-tidy:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
container:
image: infinitime/infinitime-build
steps:
# This workaround fixes the error "unsafe repository (REPO is owned by someone else)".
# See https://github.com/actions/checkout/issues/760 and https://github.com/actions/checkout/issues/766
# The fix in "actions/checkout@v2" was not sufficient as the build process also uses git (to get the current
# commit hash, for example).
- name: Workaround permission issues
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Checkout source files
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 1000
- name: Fetch base branch
run: git fetch origin "$GITHUB_BASE_REF":"$GITHUB_BASE_REF"
- name: Install clang-tidy
run: |
apt-get update
apt-get -y install clang-tidy-14
- name: Prepare environment
shell: bash
env:
SOURCES_DIR: .
run: |
. docker/build.sh
GetGcc
# I guess these already exist inside the docker?
#GetNrfSdk
#GetMcuBoot
CmakeGenerate
- run: tests/test-tidy.sh
# This workaround fixes the error "unsafe repository (REPO is owned by someone else)".
# See https://github.com/actions/checkout/issues/760 and https://github.com/actions/checkout/issues/766
# The fix in "actions/checkout@v2" was not sufficient as the build process also uses git (to get the current
# commit hash, for example).
- name: Workaround permission issues
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Checkout source files
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 1000
- name: Fetch base branch
run: git fetch origin "$GITHUB_BASE_REF":"$GITHUB_BASE_REF"
- name: Install clang-tidy
run: |
apt-get update
apt-get -y install clang-tidy-14
- name: Prepare environment
shell: bash
env:
SOURCES_DIR: .
run: |
. docker/build.sh
GetGcc
# I guess these already exist inside the docker?
#GetNrfSdk
#GetMcuBoot
CmakeGenerate
- run: tests/test-tidy.sh
4 changes: 2 additions & 2 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -z "$(command -v "git-$name")" ]; then
name="$(basename -a $(find $(echo "$PATH" | tr ':' ' ') -maxdepth 1 -type f -executable -name 'git-clang-format*') | sort | tail -n 1 | sed 's/^git-//')"
fi

minVersion="14.0.0"
minVersion="16.0.0"

for file in $(find $(echo "$PATH" | tr ':' ' ') -maxdepth 1 -type f -executable -name 'clang-format*'); do
curBin="$file"
Expand All @@ -23,7 +23,7 @@ if [ -z "$name" ] || [ -z "$bin" ]; then
exit 1
fi

args="--binary $bin -q --extensions cpp,h --style file --staged -- :!src/FreeRTOS :!src/libs"
args="--binary $bin -q --extensions cpp,h --style file --staged -- src :!src/FreeRTOS :!src/libs"

changedFiles="$(git "$name" --diffstat $args)"
git "$name" $args
Expand Down
12 changes: 8 additions & 4 deletions src/components/ble/AlertNotificationClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ int AlertNotificationClient::OnCharacteristicsDiscoveryEvent(uint16_t connection
NRF_LOG_INFO("ANS Characteristic discovery complete");
if (isCharacteristicDiscovered) {
ble_gattc_disc_all_dscs(connectionHandle, newAlertHandle, ansEndHandle, OnAlertNotificationDescriptorDiscoveryEventCallback, this);
} else
} else {
onServiceDiscovered(connectionHandle);
}
} else {
if (characteristic != nullptr && ble_uuid_cmp(&supportedNewAlertCategoryUuid.u, &characteristic->uuid.u) == 0) {
NRF_LOG_INFO("ANS Characteristic discovered : supportedNewAlertCategoryUuid");
Expand All @@ -101,8 +102,9 @@ int AlertNotificationClient::OnCharacteristicsDiscoveryEvent(uint16_t connection
} else if (characteristic != nullptr && ble_uuid_cmp(&controlPointUuid.u, &characteristic->uuid.u) == 0) {
NRF_LOG_INFO("ANS Characteristic discovered : controlPointUuid");
controlPointHandle = characteristic->val_handle;
} else
} else {
NRF_LOG_INFO("ANS Characteristic discovered : 0x%x", characteristic->val_handle);
}
}
return 0;
}
Expand Down Expand Up @@ -135,8 +137,9 @@ int AlertNotificationClient::OnDescriptorDiscoveryEventCallback(uint16_t connect
}
}
} else {
if (!isDescriptorFound)
if (!isDescriptorFound) {
onServiceDiscovered(connectionHandle);
}
}
return 0;
}
Expand All @@ -150,8 +153,9 @@ void AlertNotificationClient::OnNotification(ble_gap_event* event) {

// Ignore notifications with empty message
const auto packetLen = OS_MBUF_PKTLEN(event->notify_rx.om);
if (packetLen <= headerSize)
if (packetLen <= headerSize) {
return;
}

size_t bufferSize = std::min(packetLen + stringTerminatorSize, maxBufferSize);
auto messageSize = std::min(maxMessageSize, (bufferSize - headerSize));
Expand Down
2 changes: 1 addition & 1 deletion src/components/ble/BleClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ namespace Pinetime {
virtual void Discover(uint16_t connectionHandle, std::function<void(uint16_t)> lambda) = 0;
};
}
}
}
Loading
Loading