Skip to content

Commit be712c8

Browse files
kr-tPatrickRobbIOL
authored andcommitted
Add lint support (#106)
* Add linter script file * Add CI file * Update linter file * Replace clang-format-14 to clang-format-16 --------- Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
1 parent 0157c8f commit be712c8

55 files changed

Lines changed: 4200 additions & 3998 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ AllowShortEnumsOnASingleLine: false
1111
AllowShortFunctionsOnASingleLine: None
1212
AllowShortIfStatementsOnASingleLine: false
1313
AllowShortLoopsOnASingleLine: false
14-
BitFieldColonSpacing: After
15-
BreakBeforeBraces: Attach
14+
BitFieldColonSpacing: Both
15+
BreakBeforeBraces: Linux
1616
ColumnLimit: 120
1717
ConstructorInitializerIndentWidth: 8
1818
ContinuationIndentWidth: 8
19-
IndentCaseLabels: true
20-
IndentWidth: 4
21-
InsertBraces: true
19+
IndentCaseLabels: true # Linux is false
20+
IndentWidth: 8
21+
LineEnding: LF
2222
SpaceBeforeParens: ControlStatementsExceptControlMacros
23-
SortIncludes: Never
24-
#UseTab: ForContinuationAndIndentation
23+
SortIncludes: false
24+
UseTab: Always
25+
TabWidth: 8
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Coding Guidelines Check
2+
3+
# Trigger this workflow on all pull requests
4+
on:
5+
pull_request:
6+
7+
# Ensure only one instance of this workflow runs per branch
8+
# Cancel any in-progress runs when new commits are pushed
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: checkout
18+
uses: actions/checkout@v5
19+
with:
20+
fetch-depth: 0
21+
22+
# Install clang-format-16 for code formatting checks
23+
- name: Install clang-format-16
24+
run: |
25+
sudo apt-get update
26+
sudo apt-get install -y clang-format-16
27+
28+
- name: Run Formatting Check
29+
run: ./scripts/check_formatting.sh

scripts/check_formatting.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
#
3+
# Simple formatting checker for /src folder
4+
# Checks all C/C++ files against .clang-format rules
5+
#
6+
7+
set -e
8+
9+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
11+
SRC_DIR="$ROOT_DIR/src"
12+
13+
# Check if clang-format-16 is available
14+
if ! command -v clang-format-16 &> /dev/null; then
15+
echo "Error: clang-format-16 not found"
16+
echo "Install it with: sudo apt-get install clang-format-16"
17+
exit 1
18+
fi
19+
20+
# Check if src directory exists
21+
if [ ! -d "$SRC_DIR" ]; then
22+
echo "Error: $SRC_DIR directory not found"
23+
exit 1
24+
fi
25+
26+
echo "Checking formatting in $SRC_DIR/.."
27+
28+
# Find all C/C++ files and check formatting
29+
FAILED_FILES=()
30+
while IFS= read -r -d '' file; do
31+
if ! clang-format-16 --style=file --dry-run --Werror "$file" 2>&1; then
32+
FAILED_FILES+=("$file")
33+
fi
34+
done < <(find "$SRC_DIR" -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.h" \) -print0)
35+
36+
# Report results
37+
if [ ${#FAILED_FILES[@]} -eq 0 ]; then
38+
echo "All files are properly formatted"
39+
exit 0
40+
else
41+
echo ""
42+
echo "The following files have formatting issues:"
43+
for file in "${FAILED_FILES[@]}"; do
44+
echo " - $file"
45+
done
46+
echo ""
47+
echo "It is required to format the code before committing, or it will fail CI checks."
48+
echo ""
49+
echo "1. Install clang-format-16.0.0"
50+
echo ""
51+
echo " You can download the package from:"
52+
echo " https://github.com/llvm/llvm-project/releases"
53+
echo ""
54+
echo " For Debian/Ubuntu:"
55+
echo " sudo apt-get install clang-format-16"
56+
echo ""
57+
echo " For macOS with Homebrew (part of llvm@14):"
58+
echo " brew install llvm@14"
59+
echo " /usr/local/opt/llvm@14/bin/clang-format"
60+
echo ""
61+
echo "2. Format C/C++ source files"
62+
echo ""
63+
echo " Format a single file:"
64+
echo " clang-format-16 --style=file -i path/to/file.c"
65+
echo ""
66+
echo " Format all files in src/:"
67+
echo " find src/ -type f \\( -name '*.c' -o -name '*.cpp' -o -name '*.h' \\) \\"
68+
echo " -exec clang-format-16 --style=file -i {} +"
69+
echo ""
70+
echo "3. Disable formatting for specific code blocks (use sparingly)"
71+
echo ""
72+
echo " Wrap code with clang-format off/on comments when formatted code"
73+
echo " is not readable or friendly:"
74+
echo ""
75+
echo " /* clang-format off */"
76+
echo " your code here"
77+
echo " /* clang-format on */"
78+
echo ""
79+
exit 1
80+
fi

src/messaging/message_types.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
/**
2-
* @copyright Copyright © contributors to Project Ocre,
3-
* which has been established as Project Ocre a Series of LF Projects, LLC
4-
*
5-
* SPDX-License-Identifier: Apache-2.0
6-
*/
7-
8-
#ifndef OCRE_MESSAGING_TYPES_H
9-
#define OCRE_MESSAGING_TYPES_H
10-
11-
struct base {};
12-
13-
#endif
1+
/**
2+
* @copyright Copyright © contributors to Project Ocre,
3+
* which has been established as Project Ocre a Series of LF Projects, LLC
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#ifndef OCRE_MESSAGING_TYPES_H
9+
#define OCRE_MESSAGING_TYPES_H
10+
11+
struct base {
12+
};
13+
14+
#endif

src/ocre/api/ocre_api.c

Lines changed: 76 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626

2727
#include "ocre/utils/utils.h"
2828

29-
#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || defined(CONFIG_OCRE_CONTAINER_MESSAGING)
29+
#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || \
30+
defined(CONFIG_OCRE_CONTAINER_MESSAGING)
3031
#include "ocre_common.h"
31-
#endif
32+
#endif
3233

3334
#ifdef CONFIG_OCRE_SENSORS
3435
#include "../ocre_sensors/ocre_sensors.h"
@@ -42,110 +43,113 @@
4243
#include "../ocre_messaging/ocre_messaging.h"
4344
#endif
4445

45-
int _ocre_posix_uname(wasm_exec_env_t exec_env, struct _ocre_posix_utsname *name) {
46-
wasm_module_inst_t module_inst = wasm_runtime_get_module_inst(exec_env);
47-
if (!module_inst) {
48-
return -1;
49-
}
50-
if (!wasm_runtime_validate_native_addr(module_inst, name, sizeof(struct _ocre_posix_utsname))) {
51-
return -1;
52-
}
46+
int _ocre_posix_uname(wasm_exec_env_t exec_env, struct _ocre_posix_utsname *name)
47+
{
48+
wasm_module_inst_t module_inst = wasm_runtime_get_module_inst(exec_env);
49+
if (!module_inst) {
50+
return -1;
51+
}
52+
if (!wasm_runtime_validate_native_addr(module_inst, name, sizeof(struct _ocre_posix_utsname))) {
53+
return -1;
54+
}
5355

54-
struct utsname info;
55-
if (uname(&info) != 0) {
56-
return -1;
57-
}
56+
struct utsname info;
57+
if (uname(&info) != 0) {
58+
return -1;
59+
}
5860

59-
memset(name, 0, sizeof(struct _ocre_posix_utsname));
61+
memset(name, 0, sizeof(struct _ocre_posix_utsname));
6062

61-
snprintf(name->sysname, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", OCRE_SYSTEM_NAME, info.sysname);
62-
snprintf(name->release, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", APP_VERSION_STRING, info.release);
63-
snprintf(name->version, OCRE_API_POSIX_BUF_SIZE, "%s", info.version);
63+
snprintf(name->sysname, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", OCRE_SYSTEM_NAME, info.sysname);
64+
snprintf(name->release, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", APP_VERSION_STRING, info.release);
65+
snprintf(name->version, OCRE_API_POSIX_BUF_SIZE, "%s", info.version);
6466

6567
#ifdef CONFIG_ARM
6668
#ifdef CONFIG_CPU_CORTEX_M0
67-
strlcat(name->machine, "ARM Cortex-M0", OCRE_API_POSIX_BUF_SIZE);
69+
strlcat(name->machine, "ARM Cortex-M0", OCRE_API_POSIX_BUF_SIZE);
6870
#elif CONFIG_CPU_CORTEX_M3
69-
strlcat(name->machine, "ARM Cortex-M3", OCRE_API_POSIX_BUF_SIZE);
71+
strlcat(name->machine, "ARM Cortex-M3", OCRE_API_POSIX_BUF_SIZE);
7072
#elif CONFIG_CPU_CORTEX_M4
71-
strlcat(name->machine, "ARM Cortex-M4", OCRE_API_POSIX_BUF_SIZE);
73+
strlcat(name->machine, "ARM Cortex-M4", OCRE_API_POSIX_BUF_SIZE);
7274
#elif CONFIG_CPU_CORTEX_M7
73-
strlcat(name->machine, "ARM Cortex-M7", OCRE_API_POSIX_BUF_SIZE);
75+
strlcat(name->machine, "ARM Cortex-M7", OCRE_API_POSIX_BUF_SIZE);
7476
#elif CONFIG_CPU_CORTEX_M33
75-
strlcat(name->machine, "ARM Cortex-M33", OCRE_API_POSIX_BUF_SIZE);
77+
strlcat(name->machine, "ARM Cortex-M33", OCRE_API_POSIX_BUF_SIZE);
7678
#elif CONFIG_CPU_CORTEX_M23
77-
strlcat(name->machine, "ARM Cortex-M23", OCRE_API_POSIX_BUF_SIZE);
79+
strlcat(name->machine, "ARM Cortex-M23", OCRE_API_POSIX_BUF_SIZE);
7880
#elif CONFIG_CPU_CORTEX_M55
79-
strlcat(name->machine, "ARM Cortex-M55", OCRE_API_POSIX_BUF_SIZE);
81+
strlcat(name->machine, "ARM Cortex-M55", OCRE_API_POSIX_BUF_SIZE);
8082
#endif
8183
#else
82-
strlcat(name->machine, info.machine, OCRE_API_POSIX_BUF_SIZE);
84+
strlcat(name->machine, info.machine, OCRE_API_POSIX_BUF_SIZE);
8385
#endif
8486

85-
strlcat(name->nodename, info.nodename, OCRE_API_POSIX_BUF_SIZE);
87+
strlcat(name->nodename, info.nodename, OCRE_API_POSIX_BUF_SIZE);
8688

87-
return 0;
89+
return 0;
8890
}
8991

90-
int ocre_sleep(wasm_exec_env_t exec_env, int milliseconds) {
91-
core_sleep_ms(milliseconds);
92-
return 0;
92+
int ocre_sleep(wasm_exec_env_t exec_env, int milliseconds)
93+
{
94+
core_sleep_ms(milliseconds);
95+
return 0;
9396
}
9497

9598
// Ocre Runtime API
9699
NativeSymbol ocre_api_table[] = {
97-
{"uname", _ocre_posix_uname, "(*)i", NULL},
98-
{"ocre_sleep", ocre_sleep, "(i)i", NULL},
99-
#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || defined(CONFIG_OCRE_CONTAINER_MESSAGING)
100-
{"ocre_get_event", ocre_get_event, "(iiiiii)i", NULL},
101-
{"ocre_register_dispatcher", ocre_register_dispatcher, "(i$)i", NULL},
102-
#endif
100+
{"uname", _ocre_posix_uname, "(*)i", NULL},
101+
{"ocre_sleep", ocre_sleep, "(i)i", NULL},
102+
#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || \
103+
defined(CONFIG_OCRE_CONTAINER_MESSAGING)
104+
{"ocre_get_event", ocre_get_event, "(iiiiii)i", NULL},
105+
{"ocre_register_dispatcher", ocre_register_dispatcher, "(i$)i", NULL},
106+
#endif
103107
// Container Messaging API
104108
#ifdef CONFIG_OCRE_CONTAINER_MESSAGING
105-
{"ocre_publish_message", ocre_messaging_publish, "(***i)i", NULL},
106-
{"ocre_subscribe_message", ocre_messaging_subscribe, "(*)i", NULL},
107-
{"ocre_messaging_free_module_event_data", ocre_messaging_free_module_event_data, "(iii)i", NULL},
109+
{"ocre_publish_message", ocre_messaging_publish, "(***i)i", NULL},
110+
{"ocre_subscribe_message", ocre_messaging_subscribe, "(*)i", NULL},
111+
{"ocre_messaging_free_module_event_data", ocre_messaging_free_module_event_data, "(iii)i", NULL},
108112
#endif
109113
// Sensor API
110114
#ifdef CONFIG_OCRE_SENSORS
111-
{"ocre_sensors_init", ocre_sensors_init, "()i", NULL},
112-
{"ocre_sensors_discover", ocre_sensors_discover, "()i", NULL},
113-
{"ocre_sensors_open", ocre_sensors_open, "(i)i", NULL},
114-
{"ocre_sensors_get_handle", ocre_sensors_get_handle, "(i)i", NULL},
115-
{"ocre_sensors_get_channel_count", ocre_sensors_get_channel_count, "(i)i", NULL},
116-
{"ocre_sensors_get_channel_type", ocre_sensors_get_channel_type, "(ii)i", NULL},
117-
{"ocre_sensors_read", ocre_sensors_read, "(ii)F", NULL},
118-
{"ocre_sensors_open_by_name", ocre_sensors_open_by_name, "($)i", NULL},
119-
{"ocre_sensors_get_handle_by_name", ocre_sensors_get_handle_by_name, "($)i", NULL},
120-
{"ocre_sensors_get_channel_count_by_name", ocre_sensors_get_channel_count_by_name, "($)i", NULL},
121-
{"ocre_sensors_get_channel_type_by_name", ocre_sensors_get_channel_type_by_name, "($i)i", NULL},
122-
{"ocre_sensors_read_by_name", ocre_sensors_read_by_name, "($i)F", NULL},
123-
{"ocre_sensors_get_list", ocre_sensors_get_list, "($i)i", NULL},
115+
{"ocre_sensors_init", ocre_sensors_init, "()i", NULL},
116+
{"ocre_sensors_discover", ocre_sensors_discover, "()i", NULL},
117+
{"ocre_sensors_open", ocre_sensors_open, "(i)i", NULL},
118+
{"ocre_sensors_get_handle", ocre_sensors_get_handle, "(i)i", NULL},
119+
{"ocre_sensors_get_channel_count", ocre_sensors_get_channel_count, "(i)i", NULL},
120+
{"ocre_sensors_get_channel_type", ocre_sensors_get_channel_type, "(ii)i", NULL},
121+
{"ocre_sensors_read", ocre_sensors_read, "(ii)F", NULL},
122+
{"ocre_sensors_open_by_name", ocre_sensors_open_by_name, "($)i", NULL},
123+
{"ocre_sensors_get_handle_by_name", ocre_sensors_get_handle_by_name, "($)i", NULL},
124+
{"ocre_sensors_get_channel_count_by_name", ocre_sensors_get_channel_count_by_name, "($)i", NULL},
125+
{"ocre_sensors_get_channel_type_by_name", ocre_sensors_get_channel_type_by_name, "($i)i", NULL},
126+
{"ocre_sensors_read_by_name", ocre_sensors_read_by_name, "($i)F", NULL},
127+
{"ocre_sensors_get_list", ocre_sensors_get_list, "($i)i", NULL},
124128
#endif
125129
// Timer API
126130
#ifdef CONFIG_OCRE_TIMER
127-
{"ocre_timer_create", ocre_timer_create, "(i)i", NULL},
128-
{"ocre_timer_start", ocre_timer_start, "(iii)i", NULL},
129-
{"ocre_timer_stop", ocre_timer_stop, "(i)i", NULL},
130-
{"ocre_timer_delete", ocre_timer_delete, "(i)i", NULL},
131-
{"ocre_timer_get_remaining", ocre_timer_get_remaining, "(i)i", NULL},
131+
{"ocre_timer_create", ocre_timer_create, "(i)i", NULL},
132+
{"ocre_timer_start", ocre_timer_start, "(iii)i", NULL},
133+
{"ocre_timer_stop", ocre_timer_stop, "(i)i", NULL},
134+
{"ocre_timer_delete", ocre_timer_delete, "(i)i", NULL},
135+
{"ocre_timer_get_remaining", ocre_timer_get_remaining, "(i)i", NULL},
132136
#endif
133137
// GPIO API
134138
#ifdef CONFIG_OCRE_GPIO
135-
{"ocre_gpio_init", ocre_gpio_wasm_init, "()i", NULL},
136-
{"ocre_gpio_configure", ocre_gpio_wasm_configure, "(iii)i", NULL},
137-
{"ocre_gpio_pin_set", ocre_gpio_wasm_set, "(iii)i", NULL},
138-
{"ocre_gpio_pin_get", ocre_gpio_wasm_get, "(ii)i", NULL},
139-
{"ocre_gpio_pin_toggle", ocre_gpio_wasm_toggle, "(ii)i", NULL},
140-
{"ocre_gpio_register_callback", ocre_gpio_wasm_register_callback, "(ii)i", NULL},
141-
{"ocre_gpio_unregister_callback", ocre_gpio_wasm_unregister_callback, "(ii)i", NULL},
142-
143-
{"ocre_gpio_configure_by_name", ocre_gpio_wasm_configure_by_name, "($i)i", NULL},
144-
{"ocre_gpio_set_by_name", ocre_gpio_wasm_set_by_name, "($i)i", NULL},
145-
{"ocre_gpio_get_by_name", ocre_gpio_wasm_get_by_name, "($)i", NULL},
146-
{"ocre_gpio_toggle_by_name", ocre_gpio_wasm_toggle_by_name, "($)i", NULL},
147-
{"ocre_gpio_register_callback_by_name", ocre_gpio_wasm_register_callback_by_name, "($)i", NULL},
148-
{"ocre_gpio_unregister_callback_by_name", ocre_gpio_wasm_unregister_callback_by_name, "($)i", NULL},
139+
{"ocre_gpio_init", ocre_gpio_wasm_init, "()i", NULL},
140+
{"ocre_gpio_configure", ocre_gpio_wasm_configure, "(iii)i", NULL},
141+
{"ocre_gpio_pin_set", ocre_gpio_wasm_set, "(iii)i", NULL},
142+
{"ocre_gpio_pin_get", ocre_gpio_wasm_get, "(ii)i", NULL},
143+
{"ocre_gpio_pin_toggle", ocre_gpio_wasm_toggle, "(ii)i", NULL},
144+
{"ocre_gpio_register_callback", ocre_gpio_wasm_register_callback, "(ii)i", NULL},
145+
{"ocre_gpio_unregister_callback", ocre_gpio_wasm_unregister_callback, "(ii)i", NULL},
146+
147+
{"ocre_gpio_configure_by_name", ocre_gpio_wasm_configure_by_name, "($i)i", NULL},
148+
{"ocre_gpio_set_by_name", ocre_gpio_wasm_set_by_name, "($i)i", NULL},
149+
{"ocre_gpio_get_by_name", ocre_gpio_wasm_get_by_name, "($)i", NULL},
150+
{"ocre_gpio_toggle_by_name", ocre_gpio_wasm_toggle_by_name, "($)i", NULL},
151+
{"ocre_gpio_register_callback_by_name", ocre_gpio_wasm_register_callback_by_name, "($)i", NULL},
152+
{"ocre_gpio_unregister_callback_by_name", ocre_gpio_wasm_unregister_callback_by_name, "($)i", NULL},
149153
#endif
150154
};
151155

src/ocre/api/ocre_api.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
#endif
1818

1919
struct _ocre_posix_utsname {
20-
char sysname[OCRE_API_POSIX_BUF_SIZE];
21-
char nodename[OCRE_API_POSIX_BUF_SIZE];
22-
char release[OCRE_API_POSIX_BUF_SIZE];
23-
char version[OCRE_API_POSIX_BUF_SIZE];
24-
char machine[OCRE_API_POSIX_BUF_SIZE];
25-
char domainname[OCRE_API_POSIX_BUF_SIZE];
20+
char sysname[OCRE_API_POSIX_BUF_SIZE];
21+
char nodename[OCRE_API_POSIX_BUF_SIZE];
22+
char release[OCRE_API_POSIX_BUF_SIZE];
23+
char version[OCRE_API_POSIX_BUF_SIZE];
24+
char machine[OCRE_API_POSIX_BUF_SIZE];
25+
char domainname[OCRE_API_POSIX_BUF_SIZE];
2626
};
2727

2828
int _ocre_posix_uname(wasm_exec_env_t exec_env, struct _ocre_posix_utsname *name);

0 commit comments

Comments
 (0)