Skip to content
Closed
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
177 changes: 177 additions & 0 deletions .clang-format
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative to duplicating the file is passing root_dir into generate_codecs and then using just referencing it (e.g. os.path.join(root_dir, ".clang-format")

Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: TopLevel
AlwaysBreakAfterReturnType: TopLevel
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Never
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: false
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Mozilla
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: false
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PenaltyIndentedWhitespace: 0
PointerAlignment: Left
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true
ShortNamespaceLines: 1
SortIncludes: Never
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

11 changes: 11 additions & 0 deletions clang_formatter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import subprocess


class ClangFormatter:
def fix_formatting(self, file_path):
"""Check and modifies file if needs formatting"""
try:
subprocess.run(['clang-format', '-i', file_path],
capture_output=True, check=True)
except subprocess.CalledProcessError as e:
print(f"clang-format error for file {file_path}: {e}")
1 change: 0 additions & 1 deletion cpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ def cpp_escape_keyword(value):

"Schema": "serialization::pimpl::schema",
"List_Schema": "std::vector<serialization::pimpl::schema>",
"Version": "version",
}

_cpp_types_encode = {
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PyYAML
jsonschema
jinja2
jinja2
clang-format
18 changes: 12 additions & 6 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from yaml import MarkedYAMLError

from binary import FixSizedEntryListTypes, FixSizedTypes, FixSizedListTypes, FixSizedMapTypes
from clang_formatter import ClangFormatter
from cpp import (
cpp_ignore_service_list,
cpp_types_decode,
Expand Down Expand Up @@ -205,13 +206,15 @@ def generate_codecs(services, custom_services, template, output_dir, lang, env):
data_containing_requests = generate_data_containing_requests_lookup_table(services, custom_services)

id_fmt = "0x%02x%02x%02x"
codecs_header_file = join(output_dir, "codecs.h")
codecs_source_file = join(output_dir, "codecs.cpp")
if lang is SupportedLanguages.CPP:
curr_dir = dirname(realpath(__file__))
cpp_dir = "%s/cpp" % curr_dir
content = get_rendered_text("header_includes.j2", env)
save_file(join(output_dir, "codecs.h"), content)
save_file(codecs_header_file, content)
content = get_rendered_text("source_header.j2", env)
save_file(join(output_dir, "codecs.cpp"), content)
save_file(codecs_source_file, content)

for service in services:
if ignore_service(service, lang):
Expand Down Expand Up @@ -246,15 +249,15 @@ def generate_codecs(services, custom_services, template, output_dir, lang, env):
method=method,
contains_serialized_data_in_request=contains_serialized_data_in_request
)
save_file(join(output_dir, "codecs.h"), content, "a+")
save_file(codecs_header_file, content, "a+")

codec_template = env.get_template("codec-template.cpp.j2")
content = codec_template.render(
service_name=service_name,
method=method,
contains_serialized_data_in_request=contains_serialized_data_in_request
)
save_file(join(output_dir, "codecs.cpp"), content, "a+")
save_file(codecs_source_file, content, "a+")
else:
content = template.render(
service_name=service_name,
Expand All @@ -267,8 +270,11 @@ def generate_codecs(services, custom_services, template, output_dir, lang, env):

if lang is SupportedLanguages.CPP:
content = get_rendered_text("footer.j2", env)
save_file(join(output_dir, "codecs.h"), content, "a+")
save_file(join(output_dir, "codecs.cpp"), content, "a+")
save_file(codecs_header_file, content, "a+")
clang_formatter = ClangFormatter()
clang_formatter.fix_formatting(codecs_header_file)
save_file(codecs_source_file, content, "a+")
clang_formatter.fix_formatting(codecs_source_file)


def generate_custom_codecs(services, template, output_dir, lang, env):
Expand Down