Skip to content

Commit 9612439

Browse files
authored
Add linting and precommit hooks (#7)
* Add pre-commit linting * Add additional linters * Add generate-if-needed to build target * Fix clang auto-ordering issue * Ensure submodules are downloaded before build
1 parent e029b3e commit 9612439

39 files changed

+248
-240
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
BasedOnStyle: Chromium
33
IndentWidth: 4
44
ColumnLimit: 120
5-
AccessModifierOffset: -2
5+
AccessModifierOffset: -2

.github/workflows/ci.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@ on:
77
- main
88

99
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Lint
15+
run: |
16+
make fmt
1017
build:
1118
runs-on: ubuntu-latest
1219
steps:
1320
- uses: actions/checkout@v4
1421
- name: Build
1522
run: |
16-
make
23+
make build
1724
- name: Archive
1825
uses: actions/upload-artifact@v4
1926
with:
2027
name: artifacts
2128
path: |
2229
build-artifacts/zephyr.uf2
2330
build-artifacts/zephyr/fprime-zephyr-deployment/dict/ReferenceDeploymentTopologyDictionary.json
24-

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-json
9+
- id: check-added-large-files
10+
11+
- repo: https://github.com/codespell-project/codespell
12+
rev: v2.4.1
13+
hooks:
14+
- id: codespell
15+
16+
- repo: https://github.com/pre-commit/mirrors-clang-format
17+
rev: v20.1.8
18+
hooks:
19+
- id: clang-format

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ endif()
1111
find_package(Zephyr HINTS "${CMAKE_CURRENT_LIST_DIR}/lib/zephyr-workspace")
1212
project(fprime-zephyr-reference C CXX)
1313

14-
# Put in an option to force the device back into programable state for automated testing
15-
option(FPRIME_CI_FAILSAFE_ENABLED "Cycle count before a forced reset to programable state" OFF)
14+
# Put in an option to force the device back into programmable state for automated testing
15+
option(FPRIME_CI_FAILSAFE_ENABLED "Cycle count before a forced reset to programmable state" OFF)
1616
if (FPRIME_CI_FAILSAFE_ENABLED)
1717
set(FPRIME_CI_FAILSAFE_CYCLE_COUNT 6000 CACHE STRING "Cycles before a forced reset")
1818
add_compile_definitions(FPRIME_CI_FAILSAFE_CYCLE_COUNT=${FPRIME_CI_FAILSAFE_CYCLE_COUNT})

CMakePresets.json

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
{
2-
"version": 4,
32
"configurePresets": [
4-
{
5-
"name": "fprime-zephyr-teensy41",
6-
"displayName": "F´ Zephyr (teensy41)",
7-
"description": "F´ release build using local fprime-venv",
8-
"binaryDir": "${sourceDir}/build-fprime-automatic-zephyr",
9-
"environment": {
10-
"VIRTUAL_ENV": "${fileDir}/fprime-venv",
11-
"PATH": "$env{VIRTUAL_ENV}/bin:$penv{PATH}"
12-
},
13-
"cacheVariables": {
14-
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
15-
"CMAKE_BUILD_TYPE": "Release",
16-
"BOARD": "teensy41"
17-
},
18-
"toolchainFile": "${fileDir}/lib/fprime-zephyr/cmake/toolchain/zephyr.cmake",
19-
"generator": "Ninja"
20-
}]
3+
{
4+
"binaryDir": "${sourceDir}/build-fprime-automatic-zephyr",
5+
"cacheVariables": {
6+
"BOARD": "teensy41",
7+
"CMAKE_BUILD_TYPE": "Release",
8+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
9+
},
10+
"description": "F\u00b4 release build using local fprime-venv",
11+
"displayName": "F\u00b4 Zephyr (teensy41)",
12+
"environment": {
13+
"PATH": "$env{VIRTUAL_ENV}/bin:$penv{PATH}",
14+
"VIRTUAL_ENV": "${fileDir}/fprime-venv"
15+
},
16+
"generator": "Ninja",
17+
"name": "fprime-zephyr-teensy41",
18+
"toolchainFile": "${fileDir}/lib/fprime-zephyr/cmake/toolchain/zephyr.cmake"
19+
}
20+
],
21+
"version": 4
2122
}

FprimeZephyrReference/Components/FatalHandler/FatalHandler.cpp

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,39 @@
1010
//
1111
// ======================================================================
1212

13-
#include <Fw/Logger/Logger.hpp>
13+
#include <zephyr/sys/reboot.h>
1414
#include <FprimeZephyrReference/Components/FatalHandler/FatalHandler.hpp>
1515
#include <Fw/FPrimeBasicTypes.hpp>
16-
#include <zephyr/sys/reboot.h>
16+
#include <Fw/Logger/Logger.hpp>
1717

1818
namespace Components {
1919

20-
// ----------------------------------------------------------------------
21-
// Construction, initialization, and destruction
22-
// ----------------------------------------------------------------------
20+
// ----------------------------------------------------------------------
21+
// Construction, initialization, and destruction
22+
// ----------------------------------------------------------------------
2323

24-
FatalHandler ::
25-
FatalHandler(
26-
const char *const compName
27-
) : FatalHandlerComponentBase(compName)
28-
{
24+
FatalHandler ::FatalHandler(const char* const compName) : FatalHandlerComponentBase(compName) {}
2925

30-
}
26+
FatalHandler ::~FatalHandler() {}
3127

32-
FatalHandler ::
33-
~FatalHandler()
34-
{
35-
36-
}
37-
38-
void FatalHandler::reboot() {
39-
// When running in CI failsafe mode and the board is a teensy,
40-
// then we should invoke bkpt #251 to trigger the soft reboot enabling a
41-
// flash of new software
42-
#if defined(FPRIME_CI_FAILSAFE_CYCLE_COUNT)
43-
// Magic bootloader breakpoint, provided by PRJC
44-
if (strncmp(CONFIG_BOARD, "teensy", 6) == 0) {
28+
void FatalHandler::reboot() {
29+
// When running in CI failsafe mode and the board is a teensy,
30+
// then we should invoke bkpt #251 to trigger the soft reboot enabling a
31+
// flash of new software
32+
#if defined(FPRIME_CI_FAILSAFE_CYCLE_COUNT)
33+
// Magic bootloader breakpoint, provided by PRJC
34+
if (strncmp(CONFIG_BOARD, "teensy", 6) == 0) {
4535
asm("bkpt #251");
46-
}
47-
#endif
36+
}
37+
#endif
4838
// Otherwise, use Zephyr to reboot the system
4939
sys_reboot(SYS_REBOOT_COLD);
50-
}
51-
52-
void FatalHandler::FatalReceive_handler(
53-
const FwIndexType portNum,
54-
FwEventIdType Id) {
55-
Fw::Logger::log("FATAL %" PRI_FwEventIdType "handled.\n",Id);
56-
Os::Task::delay(Fw::TimeInterval(0, 1000)); // Delay to allow log to be processed
57-
this->reboot(); // Reboot the system
58-
}
40+
}
5941

42+
void FatalHandler::FatalReceive_handler(const FwIndexType portNum, FwEventIdType Id) {
43+
Fw::Logger::log("FATAL %" PRI_FwEventIdType "handled.\n", Id);
44+
Os::Task::delay(Fw::TimeInterval(0, 1000)); // Delay to allow log to be processed
45+
this->reboot(); // Reboot the system
46+
}
6047

61-
} // end namespace Svc
48+
} // namespace Components

FprimeZephyrReference/Components/FatalHandler/FatalHandler.hpp

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,37 @@
1717

1818
namespace Components {
1919

20-
class FatalHandler final :
21-
public FatalHandlerComponentBase
22-
{
23-
24-
public:
25-
26-
// ----------------------------------------------------------------------
27-
// Construction, initialization, and destruction
28-
// ----------------------------------------------------------------------
29-
30-
//! Construct object FatalHandler
31-
//!
32-
FatalHandler(
33-
const char *const compName /*!< The component name*/
34-
);
35-
36-
//! Destroy object FatalHandler
37-
//!
38-
~FatalHandler();
39-
40-
//! Reboot the device
41-
//!
42-
void reboot();
43-
44-
private:
45-
46-
// ----------------------------------------------------------------------
47-
// Handler implementations for user-defined typed input ports
48-
// ----------------------------------------------------------------------
49-
50-
//! Handler implementation for FatalReceive
51-
//!
52-
void FatalReceive_handler(
53-
const FwIndexType portNum, /*!< The port number*/
54-
FwEventIdType Id /*!< The ID of the FATAL event*/
55-
);
56-
};
57-
58-
} // end namespace Svc
20+
class FatalHandler final : public FatalHandlerComponentBase {
21+
public:
22+
// ----------------------------------------------------------------------
23+
// Construction, initialization, and destruction
24+
// ----------------------------------------------------------------------
25+
26+
//! Construct object FatalHandler
27+
//!
28+
FatalHandler(const char* const compName /*!< The component name*/
29+
);
30+
31+
//! Destroy object FatalHandler
32+
//!
33+
~FatalHandler();
34+
35+
//! Reboot the device
36+
//!
37+
void reboot();
38+
39+
private:
40+
// ----------------------------------------------------------------------
41+
// Handler implementations for user-defined typed input ports
42+
// ----------------------------------------------------------------------
43+
44+
//! Handler implementation for FatalReceive
45+
//!
46+
void FatalReceive_handler(const FwIndexType portNum, /*!< The port number*/
47+
FwEventIdType Id /*!< The ID of the FATAL event*/
48+
);
49+
};
50+
51+
} // namespace Components
5952

6053
#endif

FprimeZephyrReference/Components/Led/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ register_fprime_library(
2222
# DEPENDS
2323
# MyPackage_MyOtherModule
2424
)
25-

FprimeZephyrReference/Components/Led/Led.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ Led ::~Led() {}
2222
// ----------------------------------------------------------------------
2323

2424
void Led ::run_handler(FwIndexType portNum, U32 context) {
25-
26-
U32 interval = this->m_blinkInterval; // Get the blink interval from the member variable
25+
U32 interval = this->m_blinkInterval; // Get the blink interval from the member variable
2726

2827
// Only perform actions when set to blinking
2928
if (this->m_blinking && (interval != 0)) {
@@ -77,12 +76,12 @@ void Led ::BLINKING_ON_OFF_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, Fw::On on
7776
void Led ::SET_BLINK_INTERVAL_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, U32 interval) {
7877
// Update the member variable
7978
this->m_blinkInterval = interval;
80-
79+
8180
// Log the event
8281
this->log_ACTIVITY_HI_BlinkIntervalSet(interval);
83-
82+
8483
// Provide command response
8584
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
8685
}
8786

88-
} // namespace Components
87+
} // namespace Components

FprimeZephyrReference/Components/Led/Led.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ module Components {
6464
telemetry port tlmOut
6565

6666
}
67-
}
67+
}

0 commit comments

Comments
 (0)