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

Add build workflows; fix macos build errors/warnings; update code formatting #5

Merged
merged 9 commits into from
Jul 31, 2023
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
147 changes: 139 additions & 8 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,26 +1,157 @@
---
BasedOnStyle: LLVM
ColumnLimit: 100
IndentWidth: 4
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignEscapedNewlines: DontAlign
AlignOperands: Align
AlignTrailingComments: Never
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: MultiLine
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterExternBlock: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyNamespace: false
SplitEmptyRecord: false
BreakAfterAttributes: Never
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeConceptDeclarations: Always
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
CompactNamespaces: true
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeCategories:
# NOTE: A header is grouped by first matching regex
# Project headers
- Regex: '^<log_surgeon'
Priority: 4
# Third-party headers. Update when adding new third-party library
- Regex: '^<(Catch2)'
Priority: 3
# C headers
- Regex: '^<.*\.h>$'
Priority: 1
# C++ standard libraries
- Regex: '^<.*>$'
Priority: 2
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: false
IndentPPDirectives: BeforeHash
IndentRequiresClause: false
IndentWrappedFunctionNames: false
InsertBraces: true
InsertNewlineAtEOF: true
IntegerLiteralSeparator:
Binary: 4
BinaryMinDigits: 4
Decimal: 3
DecimalMinDigits: 5
Hex: 4
HexMinDigits: 4
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
LineEnding: LF
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
PPIndentWidth: -1
PackConstructorInitializers: CurrentLine
PenaltyBreakAssignment: 50
PenaltyBreakOpenParenthesis: 25
PenaltyBreakBeforeFirstCallParameter: 25
PenaltyReturnTypeOnItsOwnLine: 100
PointerAlignment: Left
QualifierAlignment: Right
ReflowComments: false
QualifierAlignment: Custom
QualifierOrder:
- static
- friend
- inline
# constexpr west as explained in https://www.youtube.com/watch?v=z6s6bacI424
- constexpr
- type
- const
- volatile
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: true
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 0
SortIncludes: CaseInsensitive
SortUsingDeclarations: Lexicographic
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: true
# AfterFunctionDeclarationName: true
# AfterFunctionDefinitionName: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 4
UseTab: Never
22 changes: 19 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
---
Checks: 'cert-*,clang-analyzer-*,clang-diagnostic-*,cppcoreguidelines-*,modernize-*,performance-*,readability-*,-readability-identifier-length,-readability-simplify-boolean-expr'
Checks: >-
bugprone-*,
-bugprone-easily-swappable-parameters,
cert-*,
clang-analyzer-*,
clang-diagnostic-*,
concurrency-*,
cppcoreguidelines-*,
misc-*,
modernize-*,
performance-*,
portability-*,
readability-*,
-readability-identifier-length,
-readability-simplify-boolean-expr,

WarningsAsErrors: '*'
FormatStyle: file
HeaderFileExtensions: ['','h','hh','hpp','hxx','tpp']
ImplementationFileExtensions: ['','c','cc','cpp','cxx']
CheckOptions:
misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true
readability-identifier-naming.ClassCase: 'CamelCase'
readability-identifier-naming.ClassMemberCase: 'lower_case'
readability-identifier-naming.ClassMemberPrefix: 'm_'
Expand All @@ -23,4 +38,5 @@ CheckOptions:
readability-identifier-naming.ParameterCase: 'lower_case'
readability-identifier-naming.StructCase: 'CamelCase'
readability-identifier-naming.TypedefCase: 'CamelCase'
readability-identifier-naming.TypedefIgnoredRegexp: '[a-z_]+_t'
readability-identifier-naming.UnionCase: 'CamelCase'
27 changes: 27 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build

on:
pull_request:
push:
workflow_call:

jobs:
build:
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
build_type: [Release, Debug]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3

- if: ${{ 'macos-latest' == matrix.os }}
run: |
brew update
brew install llvm

- run: cmake -B ./build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}

- run: cmake --build ./build --config ${{ matrix.build_type }}

- run: cmake --install ./build --prefix ./install
27 changes: 12 additions & 15 deletions src/log_surgeon/Buffer.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
#ifndef LOG_SURGEON_BUFFER_HPP
#define LOG_SURGEON_BUFFER_HPP

// C++ libraries
#include <cstdint>
#include <vector>

// Project Headers
#include "Constants.hpp"
#include "Reader.hpp"
#include <log_surgeon/Constants.hpp>
#include <log_surgeon/Reader.hpp>

namespace log_surgeon {
/**
* A base class for the efficient implementation of a single growing buffer.
* Under the hood it keeps track of one static buffer and multiple dynamic
* buffers. The buffer object uses the underlying static buffer whenever
* possible, as the static buffer is on the stack and results in faster
* reads and writes. In outlier cases, where the static buffer is not large
* enough to fit all the needed data, the buffer object switches to using
* the underlying dynamic buffers. A new dynamic buffer is used each time
* the size must be grown to preserve any pointers to the buffer. All
* pointers to the buffer are valid until reset() is called and the
* buffer returns to using the underlying static buffer. The base class does
* not grow the buffer itself, the child class is responsible for doing
* this.
* possible, as the static buffer is on the stack and results in faster reads
* and writes. In outlier cases, where the static buffer is not large enough to
* fit all the needed data, the buffer object switches to using the underlying
* dynamic buffers. A new dynamic buffer is used each time the size must be
* grown to preserve any pointers to the buffer. All pointers to the buffer are
* valid until reset() is called and the buffer returns to using the underlying
* static buffer. The base class does not grow the buffer itself, the child
* class is responsible for doing this.
*/
template <typename Item>
class Buffer {
Expand Down Expand Up @@ -94,6 +91,6 @@ class Buffer {
Item m_static_storage[cStaticByteBuffSize];
Item* m_active_storage{m_static_storage};
};
} // namespace log_surgeon
} // namespace log_surgeon

#endif // LOG_SURGEON_BUFFER_HPP
#endif // LOG_SURGEON_BUFFER_HPP
34 changes: 19 additions & 15 deletions src/log_surgeon/BufferParser.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
#include "BufferParser.hpp"

#include <string>

#include "BufferParser.hpp"
#include "Constants.hpp"
#include "LogEvent.hpp"
#include "Schema.hpp"
#include <log_surgeon/Constants.hpp>
#include <log_surgeon/LogEvent.hpp>
#include <log_surgeon/Schema.hpp>

namespace log_surgeon {
BufferParser::BufferParser(Schema& schema) : m_log_parser(schema.get_schema_ast_ptr()) {}

BufferParser::BufferParser(std::string const& schema_file_path)
: m_log_parser(LogParser(schema_file_path)) {}
: m_log_parser(LogParser(schema_file_path)) {}

auto BufferParser::reset() -> void {
m_log_parser.reset();
m_done = false;
}

auto BufferParser::get_next_event_view(char* buf,
size_t size,
size_t& offset,
LogEventView& event_view,
bool finished_reading_input) -> ErrorCode {
auto BufferParser::get_next_event_view(
char* buf,
size_t size,
size_t& offset,
LogEventView& event_view,
bool finished_reading_input
) -> ErrorCode {
event_view.reset();
// TODO in order to allow logs/tokens to wrap user buffers this function
// will need more parameters or the input buffer may need to be exposed to
Expand Down Expand Up @@ -48,17 +51,18 @@ auto BufferParser::get_next_event_view(char* buf,
for (uint32_t i = start; i < event_view.m_log_output_buffer->pos(); i++) {
Token* token = &event_view.m_log_output_buffer->get_mutable_token(i);
event_view.add_token(token->m_type_ids_ptr->at(0), token);
if (token->m_type_ids_ptr->at(0) == (int)SymbolID::TokenNewlineId &&
first_newline_pos == 0) {
if (token->m_type_ids_ptr->at(0) == (int)SymbolID::TokenNewlineId && first_newline_pos == 0)
{
first_newline_pos = i;
}
}
// To be a multiline log there must be at least one token between the
// newline token and the last token in the output buffer.
if (event_view.m_log_output_buffer->has_timestamp() && 0 < first_newline_pos &&
first_newline_pos + 1 < event_view.m_log_output_buffer->pos()) {
if (event_view.m_log_output_buffer->has_timestamp() && 0 < first_newline_pos
&& first_newline_pos + 1 < event_view.m_log_output_buffer->pos())
{
event_view.set_multiline(true);
}
return ErrorCode::Success;
}
} // namespace log_surgeon
} // namespace log_surgeon
22 changes: 12 additions & 10 deletions src/log_surgeon/BufferParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <optional>
#include <string>

#include "LogEvent.hpp"
#include "LogParser.hpp"
#include "Schema.hpp"
#include <log_surgeon/LogEvent.hpp>
#include <log_surgeon/LogParser.hpp>
#include <log_surgeon/Schema.hpp>

namespace log_surgeon {
/**
Expand Down Expand Up @@ -67,11 +67,13 @@ class BufferParser {
* internally before this method returns.
* @return ErrorCode from LogParser::parse.
*/
auto get_next_event_view(char* buf,
size_t size,
size_t& offset,
LogEventView& event_view,
bool finished_reading_input = false) -> ErrorCode;
auto get_next_event_view(
char* buf,
size_t size,
size_t& offset,
LogEventView& event_view,
bool finished_reading_input = false
) -> ErrorCode;

/**
* @return The underlying LogParser.
Expand Down Expand Up @@ -100,6 +102,6 @@ class BufferParser {
LogParser m_log_parser;
bool m_done{false};
};
} // namespace log_surgeon
} // namespace log_surgeon

#endif // LOG_SURGEON_BUFFER_PARSER_HPP
#endif // LOG_SURGEON_BUFFER_PARSER_HPP
Loading