From ae7419869adf7c619865e06e13250be88a76b413 Mon Sep 17 00:00:00 2001 From: Paul Elder Date: Thu, 27 May 2021 14:10:25 +0900 Subject: utils: ipc: mojo: Error if ControlInfoMap/List doesn't prefix libcamera The mojo parser is fine if there are types that are used in array/map members that it does not know about. These are usually caught by the C++ compiler, because the generated code refers to unknown types. This feature is necessary for us for supporting FrameBuffer::Plane as an array/map member, since as long as the type has an IPADataSerializer and the struct defined in C++, the generated code will run fine (FrameBuffer::Plane is not defined anywhere in mojom but is used as an array member in IPABuffer). The types that are defined in controls.h (or any header included in ipa_interface.h) will all be compiled by the C++ compiler fine, since the generated files all include controls.h. The types that are there that are not ControlInfoMap or ControlList (like ControlValue) will still fail at the linker stage. For example: struct A { array a; }; will compile fine, but will fail to link, since IPADataSerializer doesn't exist. This behavior, although not the best, is acceptable. The issue is that if ControlInfoMap or ControlList are used as array/map members without the libcamera prefix, the compiler will not complain, as the types are valid, and the linker will also not complain, as IPADataSerializer and IPADataSerializer both exist. However, the code generator will not recognize them as types that require a ControlSerializer (since mojo doesn't recognize them, so they are different from the ones that it does recognize with the libcamera namespace), and so the ControlSerializer will not be passed to the serializer in the generated code. This is the cause of the FATAL breakage: FATAL IPADataSerializer ipa_data_serializer.cpp:437 ControlSerializer not provided for serialization of ControlInfoMap Since ControlInfoMap and ControlList are the only types that will run into this issue, we solve this by simply detecting if they are used without the prefix, and produce an error at that point in the code generator. As the code generator stage no longer has information on the source code file and line, we output the struct name in which the error was found (ninja will output the file name). Signed-off-by: Paul Elder Reviewed-by: Laurent Pinchart --- utils/ipc/generators/mojom_libcamera_generator.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/ipc/generators/mojom_libcamera_generator.py b/utils/ipc/generators/mojom_libcamera_generator.py index effdfed6..c609f4e5 100644 --- a/utils/ipc/generators/mojom_libcamera_generator.py +++ b/utils/ipc/generators/mojom_libcamera_generator.py @@ -129,6 +129,9 @@ def GetAllAttrs(element): def NeedsControlSerializer(element): types = GetAllTypes(element) + for type in ['ControlList', 'ControlInfoMap']: + if f'x:{type}' in types: + raise Exception(f'Unknown type "{type}" in {element.mojom_name}, did you mean "libcamera.{type}"?') return "ControlList" in types or "ControlInfoMap" in types def HasFd(element): -- cgit v1.2.1