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

SysV daemon #2

Merged
merged 14 commits into from
Dec 16, 2024
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
86 changes: 86 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BraceWrapping:
SplitEmptyRecord: false
AfterEnum: true
AfterStruct: true
AfterClass: true
AfterControlStatement: true
AfterFunction: true
AfterUnion: true
AfterNamespace: true
AfterExternBlock: true
BeforeElse: true

BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ (coverity|NOSONAR|pragma:)'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
FixNamespaceComments: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeBlocks: Preserve
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 10000 # Raised intentionally; prefer breaking all
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 10000 # Raised intentionally because it hurts readability
PointerAlignment: Left
ReflowComments: true
SortIncludes: Never
SortUsingDeclarations: false
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++14
TabWidth: 8
UseTab: Never
...
37 changes: 37 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Checks: >-
boost-*,
bugprone-*,
cert-*,
clang-analyzer-*,
cppcoreguidelines-*,
google-*,
hicpp-*,
llvm-*,
misc-*,
modernize-*,
performance-*,
portability-*,
readability-*,
-clang-analyzer-core.uninitialized.Assign,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-use-default-member-init,
-google-readability-avoid-underscore-in-googletest-name,
-google-readability-todo,
-llvm-header-guard,
-modernize-concat-nested-namespaces,
-modernize-type-traits,
-modernize-use-constraints,
-modernize-use-default-member-init,
-modernize-use-nodiscard,
-readability-avoid-const-params-in-decls,
-readability-identifier-length,
-*-use-trailing-return-type,
-*-named-parameter,
CheckOptions:
- key: readability-function-cognitive-complexity.Threshold
value: '90'
- key: readability-magic-numbers.IgnoredIntegerValues
value: '1;2;3;4;5;8;10;16;20;32;60;64;100;128;256;500;512;1000'
WarningsAsErrors: '*'
HeaderFilterRegex: 'include/libcyphal/.*\.hpp'
FormatStyle: file
2 changes: 2 additions & 0 deletions .cspell/custom-dictionary-workspace.txt
Copy link
Member

Choose a reason for hiding this comment

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

Are we using VSCode, or is it some kind of compatibility extension for CLion?

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Custom Dictionary Words
ocvsmd
90 changes: 90 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Test Workflow
on: [push, pull_request]
env:
LLVM_VERSION: 15
Copy link
Member

Choose a reason for hiding this comment

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

This is an old version. Can we use v18 at least?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll try

jobs:
debug:
if: github.event_name == 'push'
runs-on: ubuntu-latest
strategy:
matrix:
toolchain: ['clang', 'gcc']
include:
- toolchain: gcc
c-compiler: gcc
cxx-compiler: g++
- toolchain: clang
c-compiler: clang
cxx-compiler: clang++
steps:
- uses: actions/checkout@v4
- run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh $LLVM_VERSION
sudo apt update -y && sudo apt upgrade -y
sudo apt-get -y install gcc-multilib g++-multilib clang-tidy-$LLVM_VERSION
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-$LLVM_VERSION 50
clang-tidy --version
- run: >
cmake
-B ${{ github.workspace }}/build
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_CXX_COMPILER=${{ matrix.cxx-compiler }}
- working-directory: ${{github.workspace}}/build
run: |
make VERBOSE=1
make test
- uses: actions/upload-artifact@v4
if: always()
with:
name: ${{github.job}}_${{matrix.toolchain}}
path: ${{github.workspace}}/**/*
retention-days: 2

optimizations:
if: github.event_name == 'push'
runs-on: ubuntu-latest
strategy:
matrix:
toolchain: ['clang', 'gcc']
build_type: [Release, MinSizeRel]
include:
- toolchain: gcc
c-compiler: gcc
cxx-compiler: g++
- toolchain: clang
c-compiler: clang
cxx-compiler: clang++
steps:
- uses: actions/checkout@v4
- run: |
sudo apt update -y && sudo apt upgrade -y
sudo apt install gcc-multilib g++-multilib
- run: >
cmake
-B ${{ github.workspace }}/build
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_CXX_COMPILER=${{ matrix.cxx-compiler }}
-DNO_STATIC_ANALYSIS=1
- working-directory: ${{github.workspace}}/build
run: |
make VERBOSE=1
make test
- uses: actions/upload-artifact@v4
if: always()
with:
name: ${{github.job}}_${{matrix.toolchain}}_${{matrix.build_type}}
path: ${{github.workspace}}/**/*
retention-days: 2

style_check:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DoozyX/[email protected]
with:
source: './test ./src'
extensions: 'c,h,cpp,hpp'
clangFormatVersion: ${{ env.LLVM_VERSION }}
40 changes: 11 additions & 29 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
# Prerequisites
*.d
# Build folders
**/build/
**/build_*

# Compiled Object files
*.slo
*.lo
*.o
*.obj
# JetBrains
.idea/*
cmake-build-*/

# Precompiled Headers
*.gch
*.pch
# Python
.venv

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
# Dumb OS crap
.DS_Store
*.bak
10 changes: 10 additions & 0 deletions .vscode/settings.json
Copy link
Member

Choose a reason for hiding this comment

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

I guess we are using VSCode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I use mix. For example, I like VSCode when it comes to editing .md files, but I rarely compile and run there preferring CLion instead.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cSpell.customDictionaries": {
"custom-dictionary-workspace": {
"name": "custom-dictionary-workspace",
"path": "${workspaceFolder:opencyphal-vehicle-system-management-daemon}/.cspell/custom-dictionary-workspace.txt",
"addWords": true,
"scope": "workspace"
}
}
}
50 changes: 50 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT
#

cmake_minimum_required(VERSION 3.22.0)

project(ocvsmd
LANGUAGES CXX
HOMEPAGE_URL https://github.com/OpenCyphal-Garage/opencyphal-vehicle-system-management-daemon
)

enable_testing()

set(NO_STATIC_ANALYSIS OFF CACHE BOOL "disable static analysis")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Set the output binary directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(src_dir "${CMAKE_SOURCE_DIR}/src")
set(test_dir "${CMAKE_SOURCE_DIR}/test")
set(include_dir "${CMAKE_SOURCE_DIR}/include")

# clang-format
find_program(clang_format NAMES clang-format)
if (NOT clang_format)
message(STATUS "Could not locate clang-format")
else ()
file(GLOB format_files ${include_dir}/**/*.[ch]pp ${src_dir}/**/*.[ch]pp ${test_dir}/**/*.[ch]pp)
message(STATUS "Using clang-format: ${clang_format}; files: ${format_files}")
add_custom_target(format COMMAND ${clang_format} -i -fallback-style=none -style=file --verbose ${format_files})
endif ()

# Use -DNO_STATIC_ANALYSIS=1 to suppress static analysis.
# If not suppressed, the tools used here shall be available, otherwise the build will fail.
if (NOT NO_STATIC_ANALYSIS)
# clang-tidy (separate config files per directory)
find_program(clang_tidy NAMES clang-tidy)
if (NOT clang_tidy)
message(FATAL_ERROR "Could not locate clang-tidy")
endif ()
message(STATUS "Using clang-tidy: ${clang_tidy}")
set(CMAKE_CXX_CLANG_TIDY ${clang_tidy})
endif()

add_subdirectory(src)
add_subdirectory(test)
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
# OpenCyphal Vehicle System Management Daemon

👻
### Build

```
cd ocvsmd
mkdir build && cd build
cmake ..
make ocvsmd
```

### Installing

#### Installing the Daemon Binary:
```
sudo cp bin/ocvsmd /usr/local/bin/ocvsmd
```

#### Installing the Init Script:
```
sudo cp ../init.d/ocvsmd /etc/init.d/ocvsmd
sudo chmod +x /etc/init.d/ocvsmd
```

#### Enabling at Startup (on SysV-based systems):
```
sudo update-rc.d ocvsmd defaults
```

### Usage
```
sudo /etc/init.d/ocvsmd start
sudo /etc/init.d/ocvsmd status
sudo /etc/init.d/ocvsmd restart
sudo /etc/init.d/ocvsmd stop
```
Loading
Loading