mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-08-14 15:17:46 +00:00
c_wrapper_generator: Added blockstr_format utility function.
Signed-off-by: Minos Galanakis <[email protected]>
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import textwrap
|
||||
import inspect
|
||||
from typing import Dict, NamedTuple, List, Optional, Tuple
|
||||
|
||||
from .c_parsing_helper import ArgumentInfo, FunctionInfo
|
||||
@@ -31,6 +31,9 @@ WrapperInfo = NamedTuple('WrapperInfo', [
|
||||
('wrapper_name', str),
|
||||
])
|
||||
|
||||
def blockstr_format(in_str: str, new_lines: int = 1) -> str:
|
||||
"""Return a whitespace stripped str, appended with user defined empty lines."""
|
||||
return inspect.cleandoc(in_str) + ("\n" * (new_lines + 1))
|
||||
|
||||
class Base:
|
||||
"""Generate a C source file containing wrapper functions."""
|
||||
@@ -67,17 +70,17 @@ class Base:
|
||||
|
||||
This includes a description comment and some include directives.
|
||||
"""
|
||||
prologue = textwrap.dedent(f'''
|
||||
prologue = blockstr_format(f'''
|
||||
/* Automatically generated by {self.program_name}, do not edit! */
|
||||
|
||||
/* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
''').lstrip()
|
||||
''')
|
||||
|
||||
if header:
|
||||
prologue += textwrap.dedent(f'''
|
||||
prologue += blockstr_format(f'''
|
||||
#ifndef {self.header_guard}
|
||||
#define {self.header_guard}
|
||||
|
||||
@@ -85,7 +88,7 @@ class Base:
|
||||
extern "C" {{
|
||||
#endif
|
||||
|
||||
''').lstrip()
|
||||
''')
|
||||
|
||||
for include in self._INCLUDES:
|
||||
prologue += "#include {}\n".format(include)
|
||||
@@ -100,14 +103,14 @@ class Base:
|
||||
"""Write the epilogue of a C file."""
|
||||
epilogue = ""
|
||||
if header:
|
||||
epilogue += textwrap.dedent(f'''
|
||||
epilogue += blockstr_format(f'''
|
||||
#ifdef __cplusplus
|
||||
}}
|
||||
#endif
|
||||
|
||||
#endif /* {self.header_guard} */
|
||||
|
||||
''').lstrip()
|
||||
''')
|
||||
|
||||
epilogue += ('/* End of automatically generated file. */\n')
|
||||
out.write(epilogue)
|
||||
|
||||
Reference in New Issue
Block a user