From 31fd370babfd046b8ec008ef0ddaddfa77f69114 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 25 Mar 2025 14:04:36 +0100 Subject: [PATCH 1/3] scripts/build: flatten whitespace in `parse_syscalls.py` Syscall regex matches may include whitespace characters other than space (i.e. `\n` or `\t`), which causes `gen_syscalls.py` to fail. This mainly affects long system call signatures wrapped onto multiple lines (e.g. by code formatter). This change replaces all successive whitespace in the regex match groups with a single space. Signed-off-by: Loek Le Blansch --- scripts/build/parse_syscalls.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/build/parse_syscalls.py b/scripts/build/parse_syscalls.py index b748bb1c21089..60b91e0f026b9 100755 --- a/scripts/build/parse_syscalls.py +++ b/scripts/build/parse_syscalls.py @@ -127,8 +127,11 @@ def analyze_headers(include_dir, scan_dir, file_list): try: to_emit = syscall_files[one_file]["emit"] | args.emit_all_syscalls - syscall_result = [(mo.groups(), fn, to_emit) - for mo in syscall_regex.finditer(contents)] + syscall_result = [] + for mo in syscall_regex.finditer(contents): + groups = mo.groups() + groups = [re.sub(r'\s+', ' ', group) for group in groups] + syscall_result.append((groups, fn, to_emit,)) for tag in struct_tags: tagged_struct_update(tagged_ret[tag], tag, contents) except Exception: From 8a104a929d68a576621612648ed3a207efc51c1b Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 28 Mar 2025 13:04:56 +0100 Subject: [PATCH 2/3] tests/cmake: add test for syscall generation scripts This commit adds a test for whitespace in syscall declaration function signatures. Signed-off-by: Loek Le Blansch --- tests/cmake/syscalls/CMakeLists.txt | 6 ++++++ tests/cmake/syscalls/main.c | 8 ++++++++ tests/cmake/syscalls/main.h | 16 ++++++++++++++++ tests/cmake/syscalls/prj.conf | 3 +++ tests/cmake/syscalls/testcase.yaml | 6 ++++++ 5 files changed, 39 insertions(+) create mode 100644 tests/cmake/syscalls/CMakeLists.txt create mode 100644 tests/cmake/syscalls/main.c create mode 100644 tests/cmake/syscalls/main.h create mode 100644 tests/cmake/syscalls/prj.conf create mode 100644 tests/cmake/syscalls/testcase.yaml diff --git a/tests/cmake/syscalls/CMakeLists.txt b/tests/cmake/syscalls/CMakeLists.txt new file mode 100644 index 0000000000000..e618c1d4c46b9 --- /dev/null +++ b/tests/cmake/syscalls/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 +cmake_minimum_required(VERSION 3.28) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(app C) +target_sources(app PRIVATE main.c) diff --git a/tests/cmake/syscalls/main.c b/tests/cmake/syscalls/main.c new file mode 100644 index 0000000000000..75e502185a9de --- /dev/null +++ b/tests/cmake/syscalls/main.c @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "main.h" + +int main(void) { return 0; } diff --git a/tests/cmake/syscalls/main.h b/tests/cmake/syscalls/main.h new file mode 100644 index 0000000000000..f67f82ac51e22 --- /dev/null +++ b/tests/cmake/syscalls/main.h @@ -0,0 +1,16 @@ +#pragma once + +/* + * Copyright (c) 2025 Renesas Electronics Corporation + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/* Newline between return type and function name */ +/* clang-format off */ +__syscall void +test_wrapped(int foo); +/* clang-format on */ + +#include diff --git a/tests/cmake/syscalls/prj.conf b/tests/cmake/syscalls/prj.conf new file mode 100644 index 0000000000000..4a540805c30eb --- /dev/null +++ b/tests/cmake/syscalls/prj.conf @@ -0,0 +1,3 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 +CONFIG_APPLICATION_DEFINED_SYSCALL=y diff --git a/tests/cmake/syscalls/testcase.yaml b/tests/cmake/syscalls/testcase.yaml new file mode 100644 index 0000000000000..b29143be68de5 --- /dev/null +++ b/tests/cmake/syscalls/testcase.yaml @@ -0,0 +1,6 @@ +# Copyright (c) 2025 Renesas Electronics Corporation +# SPDX-License-Identifier: Apache-2.0 +tests: + buildsystem.syscalls: + build_only: true + platform_allow: native_sim From 44b673cca8ed98237db3b087aead8be4d4a1e2c3 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 28 Mar 2025 13:07:23 +0100 Subject: [PATCH 3/3] revert "build: support newlines in syscall decls" This reverts commit 1993ea019b15857786b624b889198e32862ada59 because the `parse_syscalls.py` script has been modified to not output whitespace characters other than spaces in the generated JSON file. Signed-off-by: Loek Le Blansch --- scripts/build/gen_syscalls.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/build/gen_syscalls.py b/scripts/build/gen_syscalls.py index 352130caf8333..8a603989f9d5e 100755 --- a/scripts/build/gen_syscalls.py +++ b/scripts/build/gen_syscalls.py @@ -201,7 +201,6 @@ class SyscallParseException(Exception): def typename_split(item): - item = item.strip().replace("\n", " ") if "[" in item: raise SyscallParseException( "Please pass arrays to syscalls as pointers, unable to process '%s'" % @@ -414,7 +413,7 @@ def analyze_fn(match_group, fn, userspace_only): if args == "void": args = [] else: - args = [typename_split(a) for a in args.split(",")] + args = [typename_split(a.strip()) for a in args.split(",")] func_type, func_name = typename_split(func) except SyscallParseException: