Skip to content

Commit

Permalink
refactor: reorganize sources, update ci/devcontainer, formatting, lin…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
paradajz committed Dec 8, 2024
1 parent 887007e commit 72ac10a
Show file tree
Hide file tree
Showing 27 changed files with 974 additions and 3,217 deletions.
47 changes: 23 additions & 24 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
---
Checks: 'clang-analyzer-*,readability-braces-around-statements,readability-else-after-return,readability-inconsistent-declaration-parameter-name,modernize-use-equals-default,modernize-use-using,modernize-redundant-void-arg,modernize-concat-nested-namespaces,misc-redundant-expression,readability-static-accessed-through-instance,readability-static-accessed-through-instance,performance-inefficient-vector-operation,readability-identifier-naming'
WarningsAsErrors: ''
AnalyzeTemporaryDtors: false
FormatStyle: file
CheckOptions:
- key: readability-braces-around-statements.ShortStatementLines
value: '0'
- key: readability-inconsistent-declaration-parameter-name.Strict
value: 'true'
- key: readability-identifier-naming.IgnoreMainLikeFunctions
value: 'true'
- key: readability-identifier-naming.FunctionIgnoredRegexp
value: 'main'
- key: readability-identifier-naming.ClassCase
value: 'CamelCase'
- key: readability-identifier-naming.ClassMethodCase
value: 'camelBack'
- key: readability-identifier-naming.PrivateMemberCase
value: 'camelBack'
- key: readability-identifier-naming.PrivateMemberPrefix
value: '_'
- key: readability-identifier-naming.ConstexprVariableCase
- key: readability-identifier-naming.ConstantMemberCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.ConstexprFunctionCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.StructCase
value: 'camelBack'
- key: readability-identifier-naming.StructSuffix
value: '_t'
- key: readability-identifier-naming.EnumConstantCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.ConstantMemberCase
- key: readability-identifier-naming.ConstexprVariableCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.LocalConstantCase
- key: readability-identifier-naming.EnumConstantCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.FunctionIgnoredRegexp
value: 'main'
- key: readability-identifier-naming.GlobalConstantCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.GlobalPointerCase
value: 'camelBack'
- key: readability-identifier-naming.GlobalVariableCase
value: 'camelBack'
- key: readability-identifier-naming.IgnoreMainLikeFunctions
value: 'true'
- key: readability-identifier-naming.LocalConstantCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.LocalConstantPointerCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.LocalVariableCase
value: 'camelBack'
- key: readability-identifier-naming.NamespaceCase
value: 'lower_case'
- key: readability-identifier-naming.ParameterCase
value: 'camelBack'
- key: readability-identifier-naming.VirtualMethodCase
- key: readability-identifier-naming.PrivateMemberCase
value: 'camelBack'
- key: readability-identifier-naming.PrivateMemberPrefix
value: '_'
- key: readability-identifier-naming.StaticConstantCase
value: 'UPPER_CASE'
- key: readability-identifier-naming.StaticVariableCase
value: 'camelBack'
- key: readability-identifier-naming.LocalVariableCase
- key: readability-identifier-naming.StructCase
value: 'CamelCase'
- key: readability-identifier-naming.VirtualMethodCase
value: 'camelBack'
- key: readability-identifier-naming.NamespaceCase
value: 'camelBack'
- key: readability-inconsistent-declaration-parameter-name.Strict
value: 'true'
24 changes: 24 additions & 0 deletions .devcontainer/.git_branch_bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
GIT_BRANCH_COLOR_CLEAN=$(tput setaf 2)
GIT_BRANCH_COLOR_DIRTY=$(tput setaf 1)
BOLD=$(tput bold)
NORM=$(tput sgr0)
NO_COLOR=$(tput sgr0)

parse_git_branch()
{
branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/')

if [[ -n $branch ]]
then
if [ -n "$(git status --untracked-files=no --porcelain)" ]
then
# Uncommitted changes
branch+='*'
echo "${GIT_BRANCH_COLOR_DIRTY}${BOLD}${branch}${NORM}${NO_COLOR}"
else
echo "${GIT_BRANCH_COLOR_CLEAN}${branch}${NO_COLOR}"
fi
fi
}

export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]\[\033[01;34m\] \w\[\$(parse_git_branch)\]\[\e[00m\]\n> "
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile.ghcr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM ghcr.io/shanteacontrols/opendeck:381baf2ef11a606d36e5798c302d185ba0f165ee
44 changes: 44 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "${localWorkspaceFolderBasename}",
"build": {
"dockerfile": "Dockerfile.ghcr",
"context": "${localWorkspaceFolder}"
},
"workspaceMount": "src=${localWorkspaceFolder},dst=/home/ubuntu/workspace/${localWorkspaceFolderBasename},type=bind",
"workspaceFolder": "/home/ubuntu/workspace/${localWorkspaceFolderBasename}",
"mounts": [
{
"source": "/dev",
"target": "/dev",
"type": "bind"
},
{
"source": "${localEnv:HOME}/.gitconfig",
"target": "/etc/gitconfig",
"type": "bind"
},
{
"source": "${localEnv:HOME}/.ssh",
"target": "/home/ubuntu/.ssh",
"type": "bind"
}
],
"runArgs": [
"--network=host",
"--hostname=${localWorkspaceFolderBasename}"
],
"containerUser": "ubuntu",
"privileged": true,
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools",
"llvm-vs-code-extensions.vscode-clangd",
"eamodio.gitlens",
"xaver.clang-format",
"timonwong.shellcheck",
"marus25.cortex-debug"
]
}
}
}
117 changes: 99 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,109 @@ on: [push]

jobs:
build:
name: Build
runs-on: ubuntu-22.04
container:
image: paradajz168/opendeck-dev:latest
options: --user root
name: Build/Test
runs-on: ubuntu-latest
steps:
- name: Mark repository as safe
run: git config --global --add safe.directory /__w/midi-lib/midi-lib
- name: Pull the repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: false
- name: Check formatting
fetch-depth: 0
- name: Restore ccache
uses: actions/cache/restore@v4
with:
path: ccache
key: ccache-
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup missing directories and files on the runner
run: |
make format
mkdir -p ~/.ssh
touch ~/.gitconfig
- name: Prepare container
uses: devcontainers/[email protected]
with:
imageName: opendeck # Local name only
imageTag: latest # Local tag only
push: never
- name: Build library
uses: devcontainers/[email protected]
with:
imageName: opendeck
imageTag: latest
push: never
runCmd: |
make
- name: Save ccache
uses: actions/cache/save@v4
if: always()
with:
path: ccache
key: "ccache-${{ github.run_id }}"
format:
name: Code formatting
runs-on: ubuntu-latest
steps:
- name: Pull the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup missing directories and files on the runner
run: |
make lib
- name: Lint
run: |
make lint
- name: Run tests
mkdir -p ~/.ssh
touch ~/.gitconfig
- name: Prepare container
uses: devcontainers/[email protected]
with:
imageName: opendeck # Local name only
imageTag: latest # Local tag only
push: never
- name: Check formatting
uses: devcontainers/[email protected]
with:
imageName: opendeck
imageTag: latest
push: never
runCmd: |
make format
lint:
name: Code linting
runs-on: ubuntu-latest
steps:
- name: Pull the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup missing directories and files on the runner
run: |
make test
mkdir -p ~/.ssh
touch ~/.gitconfig
- name: Prepare container
uses: devcontainers/[email protected]
with:
imageName: opendeck # Local name only
imageTag: latest # Local tag only
push: never
- name: Lint
uses: devcontainers/[email protected]
with:
imageName: opendeck
imageTag: latest
push: never
runCmd: |
make lint
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "Test",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/tests/src/test/midi-test",
"program": "${workspaceFolder}/build/tests/src/test/libmidi-test",
"args": [],
"stopAtEntry": true,
"environment": [],
Expand Down
26 changes: 13 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
cmake_minimum_required(VERSION 3.22)

project(MIDI)
project(libmidi)

include(CTest)

add_library(midi-lib STATIC)
add_library(libmidi STATIC)

target_sources(midi-lib
target_sources(libmidi
PRIVATE
src/MIDI.cpp
src/transport/BLE.cpp
src/transport/Serial.cpp
src/transport/USB.cpp
src/midi.cpp
src/transport/ble.cpp
src/transport/serial.cpp
src/transport/usb.cpp
)

target_include_directories(midi-lib
target_include_directories(libmidi
PUBLIC
include
)

add_custom_target(midi-format
add_custom_target(libmidi-format
COMMAND echo Checking code formatting...
COMMAND ${CMAKE_CURRENT_LIST_DIR}/scripts/code_format.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)

set_target_properties(midi-format PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(libmidi-format PROPERTIES EXCLUDE_FROM_ALL TRUE)

if (CMAKE_EXPORT_COMPILE_COMMANDS STREQUAL ON)
add_custom_target(midi-lint
add_custom_target(libmidi-lint
COMMAND ${CMAKE_CURRENT_LIST_DIR}/scripts/clang_tidy_wrapper.sh --output=${CMAKE_CURRENT_BINARY_DIR}/clang-tidy-fixes.yml
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

set_target_properties(midi-lint PROPERTIES EXCLUDE_FROM_ALL TRUE)
add_dependencies(midi-lint midi-lib)
set_target_properties(libmidi-lint PROPERTIES EXCLUDE_FROM_ALL TRUE)
add_dependencies(libmidi-lint libmidi)
endif()

if (BUILD_TESTING_MIDI STREQUAL ON)
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ all: cmake_config
@cmake --build $(LIB_BUILD_DIR)

lib: cmake_config
@cmake --build $(LIB_BUILD_DIR) --target midi-lib
@cmake --build $(LIB_BUILD_DIR) --target libmidi

test: cmake_config
@cmake --build $(LIB_BUILD_DIR) --target test

format: cmake_config
@cmake --build $(LIB_BUILD_DIR) --target midi-format
@cmake --build $(LIB_BUILD_DIR) --target libmidi-format

lint: cmake_config
@cmake --build $(LIB_BUILD_DIR) --target midi-lint
@cmake --build $(LIB_BUILD_DIR) --target libmidi-lint

clean:
@echo Cleaning up.
Expand Down
Loading

0 comments on commit 72ac10a

Please sign in to comment.