Skip to content

Commit 42bff7a

Browse files
Add .clang-format to enforce project style (#204)
* Add .clang-format to enforce project style The settings here match the current settings for the pytorch/pytorch project, with the exception that 8-character-width tabs are preferred in place of spaces. * Mass reformat of all .c and .h files Now that we have a clang-format file defined, clean up all usages once. * Enable clang-format-check workflow Enforce clang-format consistency on all new changes.
1 parent 313524a commit 42bff7a

File tree

251 files changed

+33425
-32250
lines changed

Some content is hidden

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

251 files changed

+33425
-32250
lines changed

.clang-format

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
AccessModifierOffset: -1
3+
AlignAfterOpenBracket: AlwaysBreak
4+
AlignConsecutiveAssignments: false
5+
AlignConsecutiveDeclarations: false
6+
AlignEscapedNewlinesLeft: true
7+
AlignOperands: false
8+
AlignTrailingComments: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: Empty
13+
AllowShortIfStatementsOnASingleLine: false
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterReturnType: None
16+
AlwaysBreakBeforeMultilineStrings: true
17+
AlwaysBreakTemplateDeclarations: true
18+
BinPackArguments: false
19+
BinPackParameters: false
20+
BraceWrapping:
21+
AfterClass: false
22+
AfterControlStatement: false
23+
AfterEnum: false
24+
AfterFunction: false
25+
AfterNamespace: false
26+
AfterObjCDeclaration: false
27+
AfterStruct: false
28+
AfterUnion: false
29+
BeforeCatch: false
30+
BeforeElse: false
31+
IndentBraces: false
32+
BreakBeforeBinaryOperators: None
33+
BreakBeforeBraces: Attach
34+
BreakBeforeTernaryOperators: true
35+
BreakConstructorInitializersBeforeComma: false
36+
BreakAfterJavaFieldAnnotations: false
37+
BreakStringLiterals: false
38+
ColumnLimit: 120
39+
CommentPragmas: '^ IWYU pragma:'
40+
CompactNamespaces: false
41+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
42+
ConstructorInitializerIndentWidth: 8
43+
ContinuationIndentWidth: 8
44+
Cpp11BracedListStyle: true
45+
DerivePointerAlignment: false
46+
DisableFormat: false
47+
ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ]
48+
IncludeCategories:
49+
- Regex: '^<.*\.h(pp)?>'
50+
Priority: 1
51+
- Regex: '^<.*'
52+
Priority: 2
53+
- Regex: '.*'
54+
Priority: 3
55+
IndentCaseLabels: true
56+
IndentWidth: 8
57+
IndentWrappedFunctionNames: false
58+
KeepEmptyLinesAtTheStartOfBlocks: false
59+
MacroBlockBegin: ''
60+
MacroBlockEnd: ''
61+
MaxEmptyLinesToKeep: 1
62+
NamespaceIndentation: None
63+
PenaltyBreakBeforeFirstCallParameter: 1
64+
PenaltyBreakComment: 300
65+
PenaltyBreakFirstLessLess: 120
66+
PenaltyBreakString: 1000
67+
PenaltyExcessCharacter: 1000000
68+
PenaltyReturnTypeOnItsOwnLine: 2000000
69+
PointerAlignment: Left
70+
ReflowComments: true
71+
SortIncludes: true
72+
SpaceAfterCStyleCast: false
73+
SpaceBeforeAssignmentOperators: true
74+
SpaceBeforeParens: ControlStatements
75+
SpaceInEmptyParentheses: false
76+
SpacesBeforeTrailingComments: 1
77+
SpacesInAngles: false
78+
SpacesInContainerLiterals: true
79+
SpacesInCStyleCastParentheses: false
80+
SpacesInParentheses: false
81+
SpacesInSquareBrackets: false
82+
Standard: Cpp11
83+
TabWidth: 8
84+
UseTab: Always
85+
---
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: clang-format
2+
on: [push, pull_request]
3+
jobs:
4+
formatting-check:
5+
name: Formatting Check
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- name: Run clang-format style check.
10+
uses: jidicula/clang-format-action@v4.5.0
11+
with:
12+
exclude-regex: 'deps\/'

bench/get-current.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <cpuinfo.h>
44

5-
65
static void cpuinfo_get_current_processor(benchmark::State& state) {
76
cpuinfo_initialize();
87
while (state.KeepRunning()) {

bench/init.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <cpuinfo.h>
44

5-
65
static void cpuinfo_initialize(benchmark::State& state) {
76
while (state.KeepRunning()) {
87
cpuinfo_initialize();

include/cpuinfo-mock.h

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,35 @@
77

88
#include <cpuinfo.h>
99
#if defined(__linux__)
10-
#include <sys/types.h>
10+
#include <sys/types.h>
1111
#endif
1212

1313
#if !defined(CPUINFO_MOCK) || !(CPUINFO_MOCK)
14-
#error This header is intended only for test use
14+
#error This header is intended only for test use
1515
#endif
1616

17-
1817
#ifdef __cplusplus
1918
extern "C" {
2019
#endif
2120

22-
2321
#if CPUINFO_ARCH_ARM
24-
void CPUINFO_ABI cpuinfo_set_fpsid(uint32_t fpsid);
25-
void CPUINFO_ABI cpuinfo_set_wcid(uint32_t wcid);
22+
void CPUINFO_ABI cpuinfo_set_fpsid(uint32_t fpsid);
23+
void CPUINFO_ABI cpuinfo_set_wcid(uint32_t wcid);
2624
#endif /* CPUINFO_ARCH_ARM */
2725

2826
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
29-
struct cpuinfo_mock_cpuid {
30-
uint32_t input_eax;
31-
uint32_t input_ecx;
32-
uint32_t eax;
33-
uint32_t ebx;
34-
uint32_t ecx;
35-
uint32_t edx;
36-
};
27+
struct cpuinfo_mock_cpuid {
28+
uint32_t input_eax;
29+
uint32_t input_ecx;
30+
uint32_t eax;
31+
uint32_t ebx;
32+
uint32_t ecx;
33+
uint32_t edx;
34+
};
3735

38-
void CPUINFO_ABI cpuinfo_mock_set_cpuid(struct cpuinfo_mock_cpuid* dump, size_t entries);
39-
void CPUINFO_ABI cpuinfo_mock_get_cpuid(uint32_t eax, uint32_t regs[4]);
40-
void CPUINFO_ABI cpuinfo_mock_get_cpuidex(uint32_t eax, uint32_t ecx, uint32_t regs[4]);
36+
void CPUINFO_ABI cpuinfo_mock_set_cpuid(struct cpuinfo_mock_cpuid* dump, size_t entries);
37+
void CPUINFO_ABI cpuinfo_mock_get_cpuid(uint32_t eax, uint32_t regs[4]);
38+
void CPUINFO_ABI cpuinfo_mock_get_cpuidex(uint32_t eax, uint32_t ecx, uint32_t regs[4]);
4139
#endif /* CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 */
4240

4341
struct cpuinfo_mock_file {
@@ -53,22 +51,22 @@ struct cpuinfo_mock_property {
5351
};
5452

5553
#if defined(__linux__)
56-
void CPUINFO_ABI cpuinfo_mock_filesystem(struct cpuinfo_mock_file* files);
57-
int CPUINFO_ABI cpuinfo_mock_open(const char* path, int oflag);
58-
int CPUINFO_ABI cpuinfo_mock_close(int fd);
59-
ssize_t CPUINFO_ABI cpuinfo_mock_read(int fd, void* buffer, size_t capacity);
54+
void CPUINFO_ABI cpuinfo_mock_filesystem(struct cpuinfo_mock_file* files);
55+
int CPUINFO_ABI cpuinfo_mock_open(const char* path, int oflag);
56+
int CPUINFO_ABI cpuinfo_mock_close(int fd);
57+
ssize_t CPUINFO_ABI cpuinfo_mock_read(int fd, void* buffer, size_t capacity);
6058

61-
#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
62-
void CPUINFO_ABI cpuinfo_set_hwcap(uint32_t hwcap);
63-
#endif
64-
#if CPUINFO_ARCH_ARM
65-
void CPUINFO_ABI cpuinfo_set_hwcap2(uint32_t hwcap2);
66-
#endif
59+
#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
60+
void CPUINFO_ABI cpuinfo_set_hwcap(uint32_t hwcap);
61+
#endif
62+
#if CPUINFO_ARCH_ARM
63+
void CPUINFO_ABI cpuinfo_set_hwcap2(uint32_t hwcap2);
64+
#endif
6765
#endif
6866

6967
#if defined(__ANDROID__)
70-
void CPUINFO_ABI cpuinfo_mock_android_properties(struct cpuinfo_mock_property* properties);
71-
void CPUINFO_ABI cpuinfo_mock_gl_renderer(const char* renderer);
68+
void CPUINFO_ABI cpuinfo_mock_android_properties(struct cpuinfo_mock_property* properties);
69+
void CPUINFO_ABI cpuinfo_mock_gl_renderer(const char* renderer);
7270
#endif
7371

7472
#ifdef __cplusplus

0 commit comments

Comments
 (0)