includes for generated c types
This commit is contained in:
parent
013a480f6d
commit
62eb9eb081
3 changed files with 13 additions and 4 deletions
|
@ -355,10 +355,13 @@ class StructType:
|
|||
_union_options = {}
|
||||
union_type_field = None
|
||||
existing_c_struct = None
|
||||
c_includes = set()
|
||||
|
||||
# noinspection PyMethodOverriding
|
||||
def __init_subclass__(cls, /, union_type_field=None, existing_c_struct=None, **kwargs):
|
||||
def __init_subclass__(cls, /, union_type_field=None, existing_c_struct=None, c_includes=None, **kwargs):
|
||||
cls.union_type_field = union_type_field
|
||||
if c_includes is not None:
|
||||
cls.c_includes |= set(c_includes)
|
||||
if cls.existing_c_struct is not None:
|
||||
# TODO: can we make it possible? does it even make sense?
|
||||
raise TypeError('subclassing an external c struct is not possible')
|
||||
|
|
|
@ -158,7 +158,7 @@ class RawFTMEntry(StructType):
|
|||
|
||||
|
||||
@dataclass
|
||||
class FirmwareAppDescription(StructType, existing_c_struct="esp_app_desc_t"):
|
||||
class FirmwareAppDescription(StructType, existing_c_struct="esp_app_desc_t", c_includes=['<esp_app_desc.h>']):
|
||||
magic_word: int = field(metadata={"format": SimpleConstFormat('I', 0xAB_CD_54_32)}, repr=False)
|
||||
secure_version: int = field(metadata={"format": SimpleFormat('I')})
|
||||
reserv1: list[int] = field(metadata={"format": SimpleFormat('2I')}, repr=False)
|
||||
|
|
|
@ -2,7 +2,7 @@ from dataclasses import fields
|
|||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from c3nav.mesh.baseformats import normalize_name
|
||||
from c3nav.mesh.baseformats import normalize_name, StructType
|
||||
from c3nav.mesh.messages import MeshMessage
|
||||
from c3nav.mesh.utils import indent_c
|
||||
|
||||
|
@ -18,13 +18,19 @@ class Command(BaseCommand):
|
|||
struct_max_sizes = []
|
||||
done_definitions = set()
|
||||
|
||||
for include in StructType.c_includes:
|
||||
print(f'#include {include}')
|
||||
|
||||
ignore_names = set(field_.name for field_ in fields(MeshMessage))
|
||||
for msg_type, msg_class in MeshMessage.get_types().items():
|
||||
if msg_class.c_struct_name:
|
||||
if msg_class.c_struct_name in done_struct_names:
|
||||
continue
|
||||
done_struct_names.add(msg_class.c_struct_name)
|
||||
msg_class = MeshMessage.c_structs[msg_class.c_struct_name]
|
||||
if MeshMessage.c_structs[msg_class.c_struct_name] != msg_class:
|
||||
# the purpose of MeshMessage.c_structs is unclear, currently this never triggers
|
||||
# todo get rid of the whole c_structs thing if it doesn't turn out to be useful for anything
|
||||
raise ValueError('what happened?')
|
||||
|
||||
base_name = (msg_class.c_struct_name or normalize_name(
|
||||
getattr(msg_type, 'name', msg_class.__name__)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue