Skip to content

Commit d241e66

Browse files
committed
initial release
0 parents  commit d241e66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+5453
-0
lines changed

.clang-format

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# @file .clang-format
2+
# @brief clang-format configuration
3+
#
4+
# MIT License
5+
#
6+
# Copyright (c) 2022-2023 joelguittet and mender-mcu-client contributors
7+
#
8+
# Permission is hereby granted, free of charge, to any person obtaining a copy
9+
# of this software and associated documentation files (the "Software"), to deal
10+
# in the Software without restriction, including without limitation the rights
11+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
# copies of the Software, and to permit persons to whom the Software is
13+
# furnished to do so, subject to the following conditions:
14+
#
15+
# The above copyright notice and this permission notice shall be included in all
16+
# copies or substantial portions of the Software.
17+
#
18+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
# SOFTWARE.
25+
26+
#
27+
# This file is based on BARR-C 2018 format from https://github.com/petertorelli/clang-format-barr-c
28+
# Several modifications are done (braces positions and line width mainly)
29+
#
30+
31+
---
32+
Language: Cpp
33+
AccessModifierOffset: -4
34+
AlignAfterOpenBracket: Align
35+
AlignConsecutiveMacros: true
36+
AlignConsecutiveAssignments: true
37+
AlignConsecutiveDeclarations: true
38+
AlignEscapedNewlines: Left
39+
AlignOperands: true
40+
AlignTrailingComments: true
41+
AllowAllArgumentsOnNextLine: true
42+
AllowAllConstructorInitializersOnNextLine: true
43+
AllowAllParametersOfDeclarationOnNextLine: true
44+
AllowShortBlocksOnASingleLine: Never
45+
AllowShortCaseLabelsOnASingleLine: false
46+
AllowShortFunctionsOnASingleLine: None
47+
AllowShortLambdasOnASingleLine: All
48+
AllowShortIfStatementsOnASingleLine: Never
49+
AllowShortLoopsOnASingleLine: false
50+
AlwaysBreakAfterDefinitionReturnType: TopLevel
51+
AlwaysBreakAfterReturnType: TopLevelDefinitions
52+
AlwaysBreakBeforeMultilineStrings: true
53+
AlwaysBreakTemplateDeclarations: Yes
54+
BinPackArguments: false
55+
BinPackParameters: false
56+
BraceWrapping:
57+
AfterCaseLabel: false
58+
AfterClass: false
59+
AfterControlStatement: false
60+
AfterEnum: false
61+
AfterFunction: false
62+
AfterNamespace: false
63+
AfterObjCDeclaration: false
64+
AfterStruct: false
65+
AfterUnion: false
66+
AfterExternBlock: false
67+
BeforeCatch: false
68+
BeforeElse: false
69+
IndentBraces: false
70+
SplitEmptyFunction: false
71+
SplitEmptyRecord: false
72+
SplitEmptyNamespace: false
73+
BreakBeforeBinaryOperators: All
74+
BreakBeforeBraces: Custom
75+
BreakBeforeInheritanceComma: false
76+
BreakInheritanceList: BeforeComma
77+
BreakBeforeTernaryOperators: true
78+
BreakConstructorInitializersBeforeComma: false
79+
BreakConstructorInitializers: BeforeComma
80+
BreakAfterJavaFieldAnnotations: true
81+
BreakStringLiterals: true
82+
ColumnLimit: 160
83+
CommentPragmas: '^ IWYU pragma:'
84+
CompactNamespaces: false
85+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
86+
ConstructorInitializerIndentWidth: 4
87+
ContinuationIndentWidth: 4
88+
Cpp11BracedListStyle: false
89+
DeriveLineEnding: true
90+
DerivePointerAlignment: false
91+
DisableFormat: false
92+
ExperimentalAutoDetectBinPacking: false
93+
FixNamespaceComments: false
94+
ForEachMacros:
95+
- foreach
96+
- Q_FOREACH
97+
- BOOST_FOREACH
98+
IncludeBlocks: Preserve
99+
IncludeCategories:
100+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
101+
Priority: 2
102+
SortPriority: 0
103+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
104+
Priority: 3
105+
SortPriority: 0
106+
- Regex: '.*'
107+
Priority: 1
108+
SortPriority: 0
109+
IncludeIsMainRegex: '(Test)?$'
110+
IncludeIsMainSourceRegex: ''
111+
IndentCaseLabels: true
112+
IndentGotoLabels: true
113+
IndentPPDirectives: None
114+
IndentWidth: 4
115+
IndentWrappedFunctionNames: false
116+
JavaScriptQuotes: Leave
117+
JavaScriptWrapImports: true
118+
KeepEmptyLinesAtTheStartOfBlocks: true
119+
MacroBlockBegin: ''
120+
MacroBlockEnd: ''
121+
MaxEmptyLinesToKeep: 1
122+
NamespaceIndentation: None
123+
ObjCBinPackProtocolList: Auto
124+
ObjCBlockIndentWidth: 4
125+
ObjCSpaceAfterProperty: true
126+
ObjCSpaceBeforeProtocolList: false
127+
PenaltyBreakAssignment: 2
128+
PenaltyBreakBeforeFirstCallParameter: 19
129+
PenaltyBreakComment: 300
130+
PenaltyBreakFirstLessLess: 120
131+
PenaltyBreakString: 1000
132+
PenaltyBreakTemplateDeclaration: 10
133+
PenaltyExcessCharacter: 1000000
134+
PenaltyReturnTypeOnItsOwnLine: 200
135+
PointerAlignment: Right
136+
ReflowComments: false
137+
SortIncludes: false
138+
SortUsingDeclarations: false
139+
SpaceAfterCStyleCast: false
140+
SpaceAfterLogicalNot: false
141+
SpaceAfterTemplateKeyword: false
142+
SpaceBeforeAssignmentOperators: true
143+
SpaceBeforeCpp11BracedList: true
144+
SpaceBeforeCtorInitializerColon: true
145+
SpaceBeforeInheritanceColon: true
146+
SpaceBeforeParens: ControlStatements
147+
SpaceBeforeRangeBasedForLoopColon: true
148+
SpaceInEmptyBlock: false
149+
SpaceInEmptyParentheses: false
150+
SpacesBeforeTrailingComments: 1
151+
SpacesInAngles: false
152+
SpacesInConditionalStatement: false
153+
SpacesInContainerLiterals: false
154+
SpacesInCStyleCastParentheses: false
155+
SpacesInParentheses: false
156+
SpacesInSquareBrackets: false
157+
SpaceBeforeSquareBrackets: false
158+
Standard: Latest
159+
StatementMacros:
160+
- Q_UNUSED
161+
- QT_REQUIRE_VERSION
162+
TabWidth: 8
163+
UseCRLF: false
164+
UseTab: Never
165+
...
166+

.clang-format-ignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests/mocks/esp-idf/include/esp_crt_bundle.h
2+
tests/mocks/esp-idf/include/esp_err.h
3+
tests/mocks/esp-idf/include/esp_flash_partitions.h
4+
tests/mocks/esp-idf/include/esp_http_client.h
5+
tests/mocks/esp-idf/include/esp_log.h
6+
tests/mocks/esp-idf/include/esp_ota_ops.h
7+
tests/mocks/esp-idf/include/esp_partition.h
8+
tests/mocks/esp-idf/include/nvs.h
9+
tests/mocks/esp-idf/include/nvs_flash.h
10+
tests/mocks/esp-idf/src/esp_crt_bundle.c
11+
tests/mocks/esp-idf/src/esp_err.c
12+
tests/mocks/esp-idf/src/esp_http_client.c
13+
tests/mocks/esp-idf/src/esp_ota_ops.c
14+
tests/mocks/esp-idf/src/nvs.c
15+
tests/mocks/freertos/include/FreeRTOSConfig.h
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# @file check_code_format.sh
3+
# @brief Check code format
4+
#
5+
# MIT License
6+
#
7+
# Copyright (c) 2022-2023 joelguittet and mender-mcu-client contributors
8+
#
9+
# Permission is hereby granted, free of charge, to any person obtaining a copy
10+
# of this software and associated documentation files (the "Software"), to deal
11+
# in the Software without restriction, including without limitation the rights
12+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
# copies of the Software, and to permit persons to whom the Software is
14+
# furnished to do so, subject to the following conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be included in all
17+
# copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
# SOFTWARE.
26+
27+
# Initialize list of files that are not properly formatted
28+
result=""
29+
30+
# Check source and header files
31+
for source_file in `git ls-tree -r HEAD --name-only | grep -E '(.*\.c$|.*\.h$|.*\.cpp$|.*\.hpp$)' | grep -vFf .clang-format-ignore`
32+
do
33+
lines=$(clang-format --dry-run ${source_file} 2>&1 | wc -l)
34+
if [[ ! $lines -eq 0 ]]; then
35+
result="${result}\n${source_file}"
36+
fi
37+
done
38+
39+
# Check result
40+
if [[ ${result} != "" ]]; then
41+
echo "The following files are not properly formatted:"
42+
echo -e $result
43+
exit 1
44+
fi
45+
46+
exit 0
47+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# @file check_equivalence_tests.sh
3+
# @brief Check equivalence tests
4+
#
5+
# MIT License
6+
#
7+
# Copyright (c) 2022-2023 joelguittet and mender-mcu-client contributors
8+
#
9+
# Permission is hereby granted, free of charge, to any person obtaining a copy
10+
# of this software and associated documentation files (the "Software"), to deal
11+
# in the Software without restriction, including without limitation the rights
12+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
# copies of the Software, and to permit persons to whom the Software is
14+
# furnished to do so, subject to the following conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be included in all
17+
# copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
# SOFTWARE.
26+
27+
# Initialize list of files that are not properly formatted
28+
result=""
29+
30+
# Check source and header files
31+
for source_file in `git ls-tree -r HEAD --name-only | grep -E '(.*\.c$|.*\.h$|.*\.cpp$|.*\.hpp$)' | grep -vFf .clang-format-ignore`
32+
do
33+
# This grep matches following formats (which are not allowed):
34+
# - "variable == CONSTANT" / "variable != CONSTANT"
35+
# - "function(...) == CONSTANT" / "function(...) != CONSTANT"
36+
# - "table[...] == CONSTANT" / "table[...] != CONSTANT"
37+
# Where CONSTANT can be a definition or a number
38+
# Any number of spaces before and after "==" / "!=" is catched
39+
lines=$(grep "[])a-z][ ]*[!=]=[ ]*[A-Z0-9]" ${source_file} | wc -l)
40+
if [[ ! $lines -eq 0 ]]; then
41+
result="${result}\n${source_file}"
42+
fi
43+
done
44+
45+
# Check result
46+
if [[ ${result} != "" ]]; then
47+
echo "The following files are not properly formatted:"
48+
echo -e $result
49+
exit 1
50+
fi
51+
52+
exit 0
53+

.github/workflows/check_headers.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
# @file check_headers.sh
3+
# @brief Check headers
4+
#
5+
# MIT License
6+
#
7+
# Copyright (c) 2022-2023 joelguittet and mender-mcu-client contributors
8+
#
9+
# Permission is hereby granted, free of charge, to any person obtaining a copy
10+
# of this software and associated documentation files (the "Software"), to deal
11+
# in the Software without restriction, including without limitation the rights
12+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
# copies of the Software, and to permit persons to whom the Software is
14+
# furnished to do so, subject to the following conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be included in all
17+
# copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
# SOFTWARE.
26+
27+
# Function used to check headers
28+
# Arg1: Source file path
29+
# Arg2: First line, "" if it is not present
30+
# Arg3: String added in front of each new line except the first and last lines
31+
# Arg4: Last line, "" if it is not present
32+
check_header() {
33+
source_file=$1
34+
first_line=$2
35+
new_line=$3
36+
last_line=$4
37+
filename=$(echo $(basename ${source_file}) | sed -r 's/\+/\\+/g')
38+
pcregrep -Me "${first_line}${first_line:+\n}${new_line} @file ${filename}\n${new_line} @brief [[:print:]]*\n${new_line}\n${new_line} MIT License\n${new_line}\n${new_line} Copyright \(c\) 2022-2023 joelguittet and mender-mcu-client contributors\n${new_line}\n${new_line} Permission is hereby granted, free of charge, to any person obtaining a copy\n${new_line} of this software and associated documentation files \(the \"Software\"\), to deal\n${new_line} in the Software without restriction, including without limitation the rights\n${new_line} to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n${new_line} copies of the Software, and to permit persons to whom the Software is\n${new_line} furnished to do so, subject to the following conditions:\n${new_line}\n${new_line} The above copyright notice and this permission notice shall be included in all\n${new_line} copies or substantial portions of the Software.\n${new_line}\n${new_line} THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n${new_line} IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n${new_line} FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n${new_line} AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n${new_line} LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n${new_line} OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n${new_line} SOFTWARE.${last_line:+\n}${last_line}\n" ${source_file} > /dev/null 2>&1
39+
return $?
40+
}
41+
42+
# Initialize list of files that are not properly formatted
43+
result=""
44+
45+
# Check source, header, ASM and linker files
46+
for source_file in `git ls-tree -r HEAD --name-only | grep -E '(.*\.c$|.*\.h$|.*\.cpp$|.*\.hpp$|.*\.s$|.*\.ld$)' | grep -vFf .clang-format-ignore`
47+
do
48+
check_header ${source_file} "/\*\*" " \*" " \*/"
49+
if [[ ! $? -eq 0 ]]; then
50+
result="${result}\n${source_file}"
51+
fi
52+
done
53+
54+
# Check YAML, Python, CMake and configuration files
55+
for source_file in `git ls-tree -r HEAD --name-only | grep -E '(.*\.yml$|.*\.py$|CMakeLists.*\.txt$|.*\.cmake$|.*\.cfg$|.*\.conf$|.clang-format$)' | grep -vFf .clang-format-ignore`
56+
do
57+
check_header ${source_file} "" "#" ""
58+
if [[ ! $? -eq 0 ]]; then
59+
result="${result}\n${source_file}"
60+
fi
61+
done
62+
63+
# Check bash files
64+
for source_file in `git ls-tree -r HEAD --name-only | grep -E '(.*\.sh$)' | grep -vFf .clang-format-ignore`
65+
do
66+
check_header ${source_file} "#!/bin/bash" "#" ""
67+
if [[ ! $? -eq 0 ]]; then
68+
result="${result}\n${source_file}"
69+
fi
70+
done
71+
72+
# Check result
73+
if [[ ${result} != "" ]]; then
74+
echo "The following files have wrong header format:"
75+
echo -e $result
76+
exit 1
77+
fi
78+
79+
exit 0
80+

0 commit comments

Comments
 (0)