From patchwork Fri Aug 9 00:59:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20851 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E261CBE173 for ; Fri, 9 Aug 2024 00:59:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 19C3B633BD; Fri, 9 Aug 2024 02:59:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rThDv1Pb"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4F4176337E for ; Fri, 9 Aug 2024 02:59:40 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 59DA083F for ; Fri, 9 Aug 2024 02:58:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723165126; bh=Cg8pAQzex1NdRaF1U100ZMUm9brX4D/j6NRkEQDwsOs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rThDv1PbHjY8pUTC+XoA1fRHj8BxXh7cEZRJxVn+yEkismiDK1WYc2FDIteRkoldj 0/rE6XP1Pp7xz0d9YJGQ/VMUTDavcBXZ7qOxdG+wOoUDmA1K+hMewSA+eRWC4j/Dy2 0lgIFmV5CdouGrxT+fX12+jvVd627oiJXGkxCLNA= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 01/10] meson: Store controls and properties YAML files in variables Date: Fri, 9 Aug 2024 03:59:05 +0300 Message-ID: <20240809005914.20662-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> References: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When generating control headers, the YAML files to be used are determined dynamically based on the selected pipeline handlers. As part of this process, the build system populates an array of meson File objects used an an input for the control headers generation custom target, as well as an array of file names (as strings). The file names array is later used to generate the control source files for the libcamera core, as well as the source code for controls support in the Python bindings. Both of the source code generators manually turn the array of file names into File objects. This duplicates code and reduces readability. A third similar implementation has also been proposed to generate control support sources in the GStreamer element, making the issue worse. To simplify this, store File objects instead of file names in the controls_files array. As the meson configuration summary doesn't support File objects, create a separate controls_files_names to store the file names for that sole purpose. The exact same process occurs for properties, address them the same way. Signed-off-by: Laurent Pinchart Reviewed-by: Daniel Scally Reviewed-by: Paul Elder --- include/libcamera/meson.build | 8 ++++++-- meson.build | 4 ++-- src/libcamera/meson.build | 2 -- src/py/libcamera/meson.build | 15 ++------------- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index c8c900eba66a..36de1c2a393c 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -47,7 +47,9 @@ controls_map = { control_headers = [] controls_files = [] +controls_files_names = [] properties_files = [] +properties_files_names = [] foreach mode, entry : controls_map files_list = [] @@ -70,10 +72,12 @@ foreach mode, entry : controls_map outfile = '' if mode == 'controls' outfile = 'control_ids.h' - controls_files += files_list + controls_files += input_files + controls_files_names += files_list else outfile = 'property_ids.h' - properties_files += files_list + properties_files += input_files + properties_files_names += files_list endif template_file = files(outfile + '.in') diff --git a/meson.build b/meson.build index 59293e478b00..432ae1337b4a 100644 --- a/meson.build +++ b/meson.build @@ -278,8 +278,8 @@ py_mod.find_installation('python3', modules : py_modules) summary({ 'Enabled pipelines': pipelines, 'Enabled IPA modules': enabled_ipa_names, - 'Controls files': controls_files, - 'Properties files': properties_files, + 'Controls files': controls_files_names, + 'Properties files': properties_files_names, 'Hotplug support': libudev.found(), 'Tracing support': tracing_enabled, 'Android support': android_enabled, diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index c3efc5278ec8..79b8cbaf1311 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -134,8 +134,6 @@ controls_mode_files = { } foreach mode, input_files : controls_mode_files - input_files = files(input_files) - if mode == 'controls' template_file = files('control_ids.cpp.in') else diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index 4807ca7d75ed..2e67407598db 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -28,32 +28,21 @@ pycamera_sources = files([ # Generate controls -gen_py_controls_input_files = [] gen_py_controls_template = files('py_controls_generated.cpp.in') - gen_py_controls = files('gen-py-controls.py') -foreach file : controls_files - gen_py_controls_input_files += files('../../libcamera/' + file) -endforeach - pycamera_sources += custom_target('py_gen_controls', - input : gen_py_controls_input_files, + input : controls_files, output : ['py_controls_generated.cpp'], command : [gen_py_controls, '--mode', 'controls', '-o', '@OUTPUT@', '-t', gen_py_controls_template, '@INPUT@']) # Generate properties -gen_py_property_enums_input_files = [] gen_py_properties_template = files('py_properties_generated.cpp.in') -foreach file : properties_files - gen_py_property_enums_input_files += files('../../libcamera/' + file) -endforeach - pycamera_sources += custom_target('py_gen_properties', - input : gen_py_property_enums_input_files, + input : properties_files, output : ['py_properties_generated.cpp'], command : [gen_py_controls, '--mode', 'properties', '-o', '@OUTPUT@', '-t', gen_py_properties_template, '@INPUT@']) From patchwork Fri Aug 9 00:59:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20852 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C8596BE173 for ; Fri, 9 Aug 2024 00:59:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4049E633C1; Fri, 9 Aug 2024 02:59:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="UYS45QSx"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1FE62633B5 for ; Fri, 9 Aug 2024 02:59:42 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F214083F for ; Fri, 9 Aug 2024 02:58:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723165128; bh=jd2QQBhLPPfiGPBnMr+g2I5+IpA7OOjgA4P7Kq/+tcM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UYS45QSxfRaVKN/kML4ZBhmpqqKMATQkAW0nQwx/CHkMv0cz9wCRPL7raAj49XSln eo2IKH61y9K78KedskQn5LFui4XWqtfGJrliE7jrtYmFh0Q8K4JvDgDxjff2I8Rxl+ Lt+1B/DXmX3wrBLbZujPK2/eG656LSG+A3Dd3dYs= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 02/10] meson: Fix mismatch in controls and properties generated file names Date: Fri, 9 Aug 2024 03:59:06 +0300 Message-ID: <20240809005914.20662-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> References: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The header for controls and properties are generated from the control_ids.h.in and property_ids.h.in templates respectively, and the generated files are named control_ids.h and property_ids.h. For sources, the templates are named control_ids.cpp.in and property_ids.cpp.in, but the output files are named controls_ids.cpp and properties_ids.cpp. This discrepancy causes confusion. Fix it. Signed-off-by: Laurent Pinchart Reviewed-by: Daniel Scally Reviewed-by: Paul Elder --- src/libcamera/meson.build | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 79b8cbaf1311..e5e959d9c7bd 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -129,21 +129,25 @@ endif control_sources = [] controls_mode_files = { - 'controls' : controls_files, - 'properties' : properties_files, + 'controls': [ + controls_files, + 'control_ids.cpp', + ], + 'properties': [ + properties_files, + 'property_ids.cpp', + ], } -foreach mode, input_files : controls_mode_files - if mode == 'controls' - template_file = files('control_ids.cpp.in') - else - template_file = files('property_ids.cpp.in') - endif +foreach mode, inout_files : controls_mode_files + input_files = inout_files[0] + output_file = inout_files[1] + template_file = files(output_file + '.in') ranges_file = files('control_ranges.yaml') control_sources += custom_target(mode + '_cpp', input : input_files, - output : mode + '_ids.cpp', + output : output_file, command : [gen_controls, '-o', '@OUTPUT@', '--mode', mode, '-t', template_file, '-r', ranges_file, '@INPUT@']) From patchwork Fri Aug 9 00:59:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20853 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id CEC2CC324E for ; Fri, 9 Aug 2024 00:59:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EFCE4633C0; Fri, 9 Aug 2024 02:59:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Z/DzbCYS"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 51C416337E for ; Fri, 9 Aug 2024 02:59:43 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5F99183F for ; Fri, 9 Aug 2024 02:58:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723165129; bh=bpPsiFz01JR4BpbZzSqUnZavO0+A5yr7ndfQSt0Aq4w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Z/DzbCYS8RIwPrpRuc6Jf4OOggk0OrUoSqsr6bfsXB+6jKJ5UlQF+xbjikiFtHlTy rXWtYS43lND1eRJVD1d/Uv1wHXkB7hPoStirj26ng5J29W4I21eQbdnMicfVlqRKUc /QsTXIqIccIYPWbPNw4zUQW3HbeHAaKmFkjiKlzw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 03/10] libcamera: Drop remaining file names from header comment blocks Date: Fri, 9 Aug 2024 03:59:07 +0300 Message-ID: <20240809005914.20662-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> References: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Commit 829acb3ab0b1 ("libcamera: Drop file name from header comment blocks in templates") dropped file names from header comment blocks in templates, but forget the control and property .cpp templates. Fix it. Fixes: 829acb3ab0b1 ("libcamera: Drop file name from header comment blocks in templates") Signed-off-by: Laurent Pinchart Reviewed-by: Daniel Scally Reviewed-by: Paul Elder --- src/libcamera/control_ids.cpp.in | 2 +- src/libcamera/property_ids.cpp.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/control_ids.cpp.in b/src/libcamera/control_ids.cpp.in index d283c1c1f401..0b028c92d852 100644 --- a/src/libcamera/control_ids.cpp.in +++ b/src/libcamera/control_ids.cpp.in @@ -2,7 +2,7 @@ /* * Copyright (C) 2019, Google Inc. * - * control_ids.cpp : Control ID list + * Control ID list * * This file is auto-generated. Do not edit. */ diff --git a/src/libcamera/property_ids.cpp.in b/src/libcamera/property_ids.cpp.in index 8b274c38c74b..2d3f192eb6ef 100644 --- a/src/libcamera/property_ids.cpp.in +++ b/src/libcamera/property_ids.cpp.in @@ -2,7 +2,7 @@ /* * Copyright (C) 2019, Google Inc. * - * property_ids.cpp : Property ID list + * Property ID list * * This file is auto-generated. Do not edit. */ From patchwork Fri Aug 9 00:59:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20854 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 304E5BE173 for ; Fri, 9 Aug 2024 00:59:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D2D6F633C7; Fri, 9 Aug 2024 02:59:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HIjY3hLf"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D20FD63382 for ; Fri, 9 Aug 2024 02:59:44 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BDC80B7E for ; Fri, 9 Aug 2024 02:58:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723165131; bh=tPzPgNA/2Grnk+CFQA2thiNx1qAQOQ0MBetZqBaGZvE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HIjY3hLfEmvO1q5ZG4gkUNt3/jknrnaKotL1cOX360P2jf/GzhBp4Vra+nugMNKdF TcXqt+FITHQqnJ/hmm/bJAUP9uRE4gP/z4Wu7HSlNOXlFyoOCN9vcMGU0lpo6K7adn PUCfoxtc+75/BwZSMtWsDsF9gxoRRckzk4iBF658= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 04/10] meson: Move all code generation scripts to utils/codegen/ Date: Fri, 9 Aug 2024 03:59:08 +0300 Message-ID: <20240809005914.20662-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> References: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" We have multiple code generation scripts in utils/, mixed with other miscellaneous utilities, as well as a larger code base based on mojom in utils/ipc/. To make code sharing easier between the generator scripts, without creating a mess in the utils/ directory, move all the code generation code to utils/codegen/. Signed-off-by: Laurent Pinchart Reviewed-by: Daniel Scally Reviewed-by: Paul Elder --- include/libcamera/internal/meson.build | 2 +- utils/{ => codegen}/gen-controls.py | 0 utils/{ => codegen}/gen-formats.py | 0 utils/{ => codegen}/gen-header.sh | 0 utils/{ => codegen}/gen-ipa-pub-key.py | 0 utils/{tracepoints => codegen}/gen-tp-header.py | 0 utils/{ => codegen}/ipc/extract-docs.py | 0 utils/{ => codegen}/ipc/generate.py | 0 utils/{ => codegen}/ipc/generators/__init__.py | 0 .../libcamera_templates/core_ipa_interface.h.tmpl | 0 .../libcamera_templates/core_ipa_serializer.h.tmpl | 0 .../libcamera_templates/definition_functions.tmpl | 0 .../ipc/generators/libcamera_templates/meson.build | 0 .../libcamera_templates/module_ipa_interface.h.tmpl | 0 .../libcamera_templates/module_ipa_proxy.cpp.tmpl | 0 .../libcamera_templates/module_ipa_proxy.h.tmpl | 0 .../module_ipa_proxy_worker.cpp.tmpl | 0 .../module_ipa_serializer.h.tmpl | 0 .../libcamera_templates/proxy_functions.tmpl | 0 .../generators/libcamera_templates/serializer.tmpl | 0 utils/{ => codegen}/ipc/generators/meson.build | 0 .../ipc/generators/mojom_libcamera_generator.py | 0 utils/{ => codegen}/ipc/meson.build | 0 utils/{ => codegen}/ipc/mojo/README | 0 utils/{ => codegen}/ipc/mojo/public/LICENSE | 0 .../{ => codegen}/ipc/mojo/public/tools/.style.yapf | 0 utils/{ => codegen}/ipc/mojo/public/tools/BUILD.gn | 0 .../ipc/mojo/public/tools/bindings/BUILD.gn | 0 .../ipc/mojo/public/tools/bindings/README.md | 0 .../mojo/public/tools/bindings/checks/__init__.py | 0 .../tools/bindings/checks/mojom_attributes_check.py | 0 .../checks/mojom_attributes_check_unittest.py | 0 .../bindings/checks/mojom_definitions_check.py | 0 .../checks/mojom_interface_feature_check.py | 0 .../mojom_interface_feature_check_unittest.py | 0 .../bindings/checks/mojom_restrictions_check.py | 0 .../checks/mojom_restrictions_checks_unittest.py | 0 .../mojo/public/tools/bindings/concatenate-files.py | 0 .../concatenate_and_replace_closure_exports.py | 0 .../public/tools/bindings/gen_data_files_list.py | 0 .../public/tools/bindings/generate_type_mappings.py | 0 .../public/tools/bindings/minify_with_terser.py | 0 .../ipc/mojo/public/tools/bindings/mojom.gni | 0 .../tools/bindings/mojom_bindings_generator.py | 0 .../bindings/mojom_bindings_generator_unittest.py | 0 .../tools/bindings/validate_typemap_config.py | 0 .../ipc/mojo/public/tools/mojom/BUILD.gn | 0 .../ipc/mojo/public/tools/mojom/README.md | 0 .../tools/mojom/check_stable_mojom_compatibility.py | 0 .../check_stable_mojom_compatibility_unittest.py | 0 .../ipc/mojo/public/tools/mojom/const_unittest.py | 0 .../ipc/mojo/public/tools/mojom/enum_unittest.py | 0 .../ipc/mojo/public/tools/mojom/feature_unittest.py | 0 .../ipc/mojo/public/tools/mojom/mojom/BUILD.gn | 0 .../ipc/mojo/public/tools/mojom/mojom/__init__.py | 0 .../ipc/mojo/public/tools/mojom/mojom/error.py | 0 .../ipc/mojo/public/tools/mojom/mojom/fileutil.py | 0 .../public/tools/mojom/mojom/fileutil_unittest.py | 0 .../public/tools/mojom/mojom/generate/__init__.py | 0 .../mojo/public/tools/mojom/mojom/generate/check.py | 0 .../public/tools/mojom/mojom/generate/generator.py | 0 .../mojom/mojom/generate/generator_unittest.py | 0 .../public/tools/mojom/mojom/generate/module.py | 0 .../tools/mojom/mojom/generate/module_unittest.py | 0 .../mojo/public/tools/mojom/mojom/generate/pack.py | 0 .../tools/mojom/mojom/generate/pack_unittest.py | 0 .../tools/mojom/mojom/generate/template_expander.py | 0 .../public/tools/mojom/mojom/generate/translate.py | 0 .../mojom/mojom/generate/translate_unittest.py | 0 .../mojo/public/tools/mojom/mojom/parse/__init__.py | 0 .../ipc/mojo/public/tools/mojom/mojom/parse/ast.py | 0 .../public/tools/mojom/mojom/parse/ast_unittest.py | 0 .../tools/mojom/mojom/parse/conditional_features.py | 0 .../mojom/parse/conditional_features_unittest.py | 0 .../mojo/public/tools/mojom/mojom/parse/lexer.py | 0 .../tools/mojom/mojom/parse/lexer_unittest.py | 0 .../mojo/public/tools/mojom/mojom/parse/parser.py | 0 .../tools/mojom/mojom/parse/parser_unittest.py | 0 .../ipc/mojo/public/tools/mojom/mojom_parser.py | 0 .../public/tools/mojom/mojom_parser_test_case.py | 0 .../public/tools/mojom/mojom_parser_unittest.py | 0 .../public/tools/mojom/stable_attribute_unittest.py | 0 .../ipc/mojo/public/tools/mojom/union_unittest.py | 0 .../tools/mojom/version_compatibility_unittest.py | 0 .../mojo/public/tools/run_all_python_unittests.py | 0 utils/{ => codegen}/ipc/parser.py | 0 utils/{ => codegen}/ipc/tools/README | 0 .../ipc/tools/diagnosis/crbug_1001171.py | 0 utils/codegen/meson.build | 13 +++++++++++++ utils/meson.build | 10 +--------- utils/tracepoints/meson.build | 5 ----- 91 files changed, 15 insertions(+), 15 deletions(-) rename utils/{ => codegen}/gen-controls.py (100%) rename utils/{ => codegen}/gen-formats.py (100%) rename utils/{ => codegen}/gen-header.sh (100%) rename utils/{ => codegen}/gen-ipa-pub-key.py (100%) rename utils/{tracepoints => codegen}/gen-tp-header.py (100%) rename utils/{ => codegen}/ipc/extract-docs.py (100%) rename utils/{ => codegen}/ipc/generate.py (100%) rename utils/{ => codegen}/ipc/generators/__init__.py (100%) rename utils/{ => codegen}/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl (100%) rename utils/{ => codegen}/ipc/generators/libcamera_templates/core_ipa_serializer.h.tmpl (100%) rename utils/{ => codegen}/ipc/generators/libcamera_templates/definition_functions.tmpl (100%) rename utils/{ => codegen}/ipc/generators/libcamera_templates/meson.build (100%) rename utils/{ => codegen}/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl (100%) rename utils/{ => codegen}/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl (100%) rename utils/{ => codegen}/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl (100%) rename utils/{ => codegen}/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl (100%) rename utils/{ => codegen}/ipc/generators/libcamera_templates/module_ipa_serializer.h.tmpl (100%) rename utils/{ => codegen}/ipc/generators/libcamera_templates/proxy_functions.tmpl (100%) rename utils/{ => codegen}/ipc/generators/libcamera_templates/serializer.tmpl (100%) rename utils/{ => codegen}/ipc/generators/meson.build (100%) rename utils/{ => codegen}/ipc/generators/mojom_libcamera_generator.py (100%) rename utils/{ => codegen}/ipc/meson.build (100%) rename utils/{ => codegen}/ipc/mojo/README (100%) rename utils/{ => codegen}/ipc/mojo/public/LICENSE (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/.style.yapf (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/BUILD.gn (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/BUILD.gn (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/README.md (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/checks/__init__.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/checks/mojom_attributes_check.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/checks/mojom_attributes_check_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/checks/mojom_definitions_check.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/checks/mojom_interface_feature_check.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/checks/mojom_interface_feature_check_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/checks/mojom_restrictions_check.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/checks/mojom_restrictions_checks_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/concatenate-files.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/concatenate_and_replace_closure_exports.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/gen_data_files_list.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/generate_type_mappings.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/minify_with_terser.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/mojom.gni (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/mojom_bindings_generator.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/mojom_bindings_generator_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/bindings/validate_typemap_config.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/BUILD.gn (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/README.md (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/const_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/enum_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/feature_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/BUILD.gn (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/__init__.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/error.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/fileutil.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/fileutil_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/generate/__init__.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/generate/check.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/generate/generator.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/generate/generator_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/generate/module.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/generate/module_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/generate/pack.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/generate/pack_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/generate/template_expander.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/generate/translate.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/parse/__init__.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/parse/ast.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/parse/ast_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/parse/conditional_features.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/parse/conditional_features_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/parse/lexer.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/parse/lexer_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/parse/parser.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom/parse/parser_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom_parser.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom_parser_test_case.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/mojom_parser_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/stable_attribute_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/union_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/mojom/version_compatibility_unittest.py (100%) rename utils/{ => codegen}/ipc/mojo/public/tools/run_all_python_unittests.py (100%) rename utils/{ => codegen}/ipc/parser.py (100%) rename utils/{ => codegen}/ipc/tools/README (100%) rename utils/{ => codegen}/ipc/tools/diagnosis/crbug_1001171.py (100%) create mode 100644 utils/codegen/meson.build delete mode 100644 utils/tracepoints/meson.build diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 39230facc8a4..1c5eef9cab80 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -48,7 +48,7 @@ tracepoints_h = custom_target( 'tp_header', input : ['tracepoints.h.in', tracepoint_files], output : 'tracepoints.h', - command : [gen_tracepoints_header, include_build_dir, '@OUTPUT@', '@INPUT@'], + command : [gen_tracepoints, include_build_dir, '@OUTPUT@', '@INPUT@'], ) libcamera_internal_headers += tracepoints_h diff --git a/utils/gen-controls.py b/utils/codegen/gen-controls.py similarity index 100% rename from utils/gen-controls.py rename to utils/codegen/gen-controls.py diff --git a/utils/gen-formats.py b/utils/codegen/gen-formats.py similarity index 100% rename from utils/gen-formats.py rename to utils/codegen/gen-formats.py diff --git a/utils/gen-header.sh b/utils/codegen/gen-header.sh similarity index 100% rename from utils/gen-header.sh rename to utils/codegen/gen-header.sh diff --git a/utils/gen-ipa-pub-key.py b/utils/codegen/gen-ipa-pub-key.py similarity index 100% rename from utils/gen-ipa-pub-key.py rename to utils/codegen/gen-ipa-pub-key.py diff --git a/utils/tracepoints/gen-tp-header.py b/utils/codegen/gen-tp-header.py similarity index 100% rename from utils/tracepoints/gen-tp-header.py rename to utils/codegen/gen-tp-header.py diff --git a/utils/ipc/extract-docs.py b/utils/codegen/ipc/extract-docs.py similarity index 100% rename from utils/ipc/extract-docs.py rename to utils/codegen/ipc/extract-docs.py diff --git a/utils/ipc/generate.py b/utils/codegen/ipc/generate.py similarity index 100% rename from utils/ipc/generate.py rename to utils/codegen/ipc/generate.py diff --git a/utils/ipc/generators/__init__.py b/utils/codegen/ipc/generators/__init__.py similarity index 100% rename from utils/ipc/generators/__init__.py rename to utils/codegen/ipc/generators/__init__.py diff --git a/utils/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl b/utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl similarity index 100% rename from utils/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl rename to utils/codegen/ipc/generators/libcamera_templates/core_ipa_interface.h.tmpl diff --git a/utils/ipc/generators/libcamera_templates/core_ipa_serializer.h.tmpl b/utils/codegen/ipc/generators/libcamera_templates/core_ipa_serializer.h.tmpl similarity index 100% rename from utils/ipc/generators/libcamera_templates/core_ipa_serializer.h.tmpl rename to utils/codegen/ipc/generators/libcamera_templates/core_ipa_serializer.h.tmpl diff --git a/utils/ipc/generators/libcamera_templates/definition_functions.tmpl b/utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl similarity index 100% rename from utils/ipc/generators/libcamera_templates/definition_functions.tmpl rename to utils/codegen/ipc/generators/libcamera_templates/definition_functions.tmpl diff --git a/utils/ipc/generators/libcamera_templates/meson.build b/utils/codegen/ipc/generators/libcamera_templates/meson.build similarity index 100% rename from utils/ipc/generators/libcamera_templates/meson.build rename to utils/codegen/ipc/generators/libcamera_templates/meson.build diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl similarity index 100% rename from utils/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl rename to utils/codegen/ipc/generators/libcamera_templates/module_ipa_interface.h.tmpl diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl similarity index 100% rename from utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl rename to utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl similarity index 100% rename from utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl rename to utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl similarity index 100% rename from utils/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl rename to utils/codegen/ipc/generators/libcamera_templates/module_ipa_proxy_worker.cpp.tmpl diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_serializer.h.tmpl b/utils/codegen/ipc/generators/libcamera_templates/module_ipa_serializer.h.tmpl similarity index 100% rename from utils/ipc/generators/libcamera_templates/module_ipa_serializer.h.tmpl rename to utils/codegen/ipc/generators/libcamera_templates/module_ipa_serializer.h.tmpl diff --git a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl b/utils/codegen/ipc/generators/libcamera_templates/proxy_functions.tmpl similarity index 100% rename from utils/ipc/generators/libcamera_templates/proxy_functions.tmpl rename to utils/codegen/ipc/generators/libcamera_templates/proxy_functions.tmpl diff --git a/utils/ipc/generators/libcamera_templates/serializer.tmpl b/utils/codegen/ipc/generators/libcamera_templates/serializer.tmpl similarity index 100% rename from utils/ipc/generators/libcamera_templates/serializer.tmpl rename to utils/codegen/ipc/generators/libcamera_templates/serializer.tmpl diff --git a/utils/ipc/generators/meson.build b/utils/codegen/ipc/generators/meson.build similarity index 100% rename from utils/ipc/generators/meson.build rename to utils/codegen/ipc/generators/meson.build diff --git a/utils/ipc/generators/mojom_libcamera_generator.py b/utils/codegen/ipc/generators/mojom_libcamera_generator.py similarity index 100% rename from utils/ipc/generators/mojom_libcamera_generator.py rename to utils/codegen/ipc/generators/mojom_libcamera_generator.py diff --git a/utils/ipc/meson.build b/utils/codegen/ipc/meson.build similarity index 100% rename from utils/ipc/meson.build rename to utils/codegen/ipc/meson.build diff --git a/utils/ipc/mojo/README b/utils/codegen/ipc/mojo/README similarity index 100% rename from utils/ipc/mojo/README rename to utils/codegen/ipc/mojo/README diff --git a/utils/ipc/mojo/public/LICENSE b/utils/codegen/ipc/mojo/public/LICENSE similarity index 100% rename from utils/ipc/mojo/public/LICENSE rename to utils/codegen/ipc/mojo/public/LICENSE diff --git a/utils/ipc/mojo/public/tools/.style.yapf b/utils/codegen/ipc/mojo/public/tools/.style.yapf similarity index 100% rename from utils/ipc/mojo/public/tools/.style.yapf rename to utils/codegen/ipc/mojo/public/tools/.style.yapf diff --git a/utils/ipc/mojo/public/tools/BUILD.gn b/utils/codegen/ipc/mojo/public/tools/BUILD.gn similarity index 100% rename from utils/ipc/mojo/public/tools/BUILD.gn rename to utils/codegen/ipc/mojo/public/tools/BUILD.gn diff --git a/utils/ipc/mojo/public/tools/bindings/BUILD.gn b/utils/codegen/ipc/mojo/public/tools/bindings/BUILD.gn similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/BUILD.gn rename to utils/codegen/ipc/mojo/public/tools/bindings/BUILD.gn diff --git a/utils/ipc/mojo/public/tools/bindings/README.md b/utils/codegen/ipc/mojo/public/tools/bindings/README.md similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/README.md rename to utils/codegen/ipc/mojo/public/tools/bindings/README.md diff --git a/utils/ipc/mojo/public/tools/bindings/checks/__init__.py b/utils/codegen/ipc/mojo/public/tools/bindings/checks/__init__.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/checks/__init__.py rename to utils/codegen/ipc/mojo/public/tools/bindings/checks/__init__.py diff --git a/utils/ipc/mojo/public/tools/bindings/checks/mojom_attributes_check.py b/utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_attributes_check.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/checks/mojom_attributes_check.py rename to utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_attributes_check.py diff --git a/utils/ipc/mojo/public/tools/bindings/checks/mojom_attributes_check_unittest.py b/utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_attributes_check_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/checks/mojom_attributes_check_unittest.py rename to utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_attributes_check_unittest.py diff --git a/utils/ipc/mojo/public/tools/bindings/checks/mojom_definitions_check.py b/utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_definitions_check.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/checks/mojom_definitions_check.py rename to utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_definitions_check.py diff --git a/utils/ipc/mojo/public/tools/bindings/checks/mojom_interface_feature_check.py b/utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_interface_feature_check.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/checks/mojom_interface_feature_check.py rename to utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_interface_feature_check.py diff --git a/utils/ipc/mojo/public/tools/bindings/checks/mojom_interface_feature_check_unittest.py b/utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_interface_feature_check_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/checks/mojom_interface_feature_check_unittest.py rename to utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_interface_feature_check_unittest.py diff --git a/utils/ipc/mojo/public/tools/bindings/checks/mojom_restrictions_check.py b/utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_restrictions_check.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/checks/mojom_restrictions_check.py rename to utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_restrictions_check.py diff --git a/utils/ipc/mojo/public/tools/bindings/checks/mojom_restrictions_checks_unittest.py b/utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_restrictions_checks_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/checks/mojom_restrictions_checks_unittest.py rename to utils/codegen/ipc/mojo/public/tools/bindings/checks/mojom_restrictions_checks_unittest.py diff --git a/utils/ipc/mojo/public/tools/bindings/concatenate-files.py b/utils/codegen/ipc/mojo/public/tools/bindings/concatenate-files.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/concatenate-files.py rename to utils/codegen/ipc/mojo/public/tools/bindings/concatenate-files.py diff --git a/utils/ipc/mojo/public/tools/bindings/concatenate_and_replace_closure_exports.py b/utils/codegen/ipc/mojo/public/tools/bindings/concatenate_and_replace_closure_exports.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/concatenate_and_replace_closure_exports.py rename to utils/codegen/ipc/mojo/public/tools/bindings/concatenate_and_replace_closure_exports.py diff --git a/utils/ipc/mojo/public/tools/bindings/gen_data_files_list.py b/utils/codegen/ipc/mojo/public/tools/bindings/gen_data_files_list.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/gen_data_files_list.py rename to utils/codegen/ipc/mojo/public/tools/bindings/gen_data_files_list.py diff --git a/utils/ipc/mojo/public/tools/bindings/generate_type_mappings.py b/utils/codegen/ipc/mojo/public/tools/bindings/generate_type_mappings.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/generate_type_mappings.py rename to utils/codegen/ipc/mojo/public/tools/bindings/generate_type_mappings.py diff --git a/utils/ipc/mojo/public/tools/bindings/minify_with_terser.py b/utils/codegen/ipc/mojo/public/tools/bindings/minify_with_terser.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/minify_with_terser.py rename to utils/codegen/ipc/mojo/public/tools/bindings/minify_with_terser.py diff --git a/utils/ipc/mojo/public/tools/bindings/mojom.gni b/utils/codegen/ipc/mojo/public/tools/bindings/mojom.gni similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/mojom.gni rename to utils/codegen/ipc/mojo/public/tools/bindings/mojom.gni diff --git a/utils/ipc/mojo/public/tools/bindings/mojom_bindings_generator.py b/utils/codegen/ipc/mojo/public/tools/bindings/mojom_bindings_generator.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/mojom_bindings_generator.py rename to utils/codegen/ipc/mojo/public/tools/bindings/mojom_bindings_generator.py diff --git a/utils/ipc/mojo/public/tools/bindings/mojom_bindings_generator_unittest.py b/utils/codegen/ipc/mojo/public/tools/bindings/mojom_bindings_generator_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/mojom_bindings_generator_unittest.py rename to utils/codegen/ipc/mojo/public/tools/bindings/mojom_bindings_generator_unittest.py diff --git a/utils/ipc/mojo/public/tools/bindings/validate_typemap_config.py b/utils/codegen/ipc/mojo/public/tools/bindings/validate_typemap_config.py similarity index 100% rename from utils/ipc/mojo/public/tools/bindings/validate_typemap_config.py rename to utils/codegen/ipc/mojo/public/tools/bindings/validate_typemap_config.py diff --git a/utils/ipc/mojo/public/tools/mojom/BUILD.gn b/utils/codegen/ipc/mojo/public/tools/mojom/BUILD.gn similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/BUILD.gn rename to utils/codegen/ipc/mojo/public/tools/mojom/BUILD.gn diff --git a/utils/ipc/mojo/public/tools/mojom/README.md b/utils/codegen/ipc/mojo/public/tools/mojom/README.md similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/README.md rename to utils/codegen/ipc/mojo/public/tools/mojom/README.md diff --git a/utils/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility.py b/utils/codegen/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility.py rename to utils/codegen/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility.py diff --git a/utils/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/const_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/const_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/const_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/const_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/enum_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/enum_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/enum_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/enum_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/feature_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/feature_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/feature_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/feature_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/BUILD.gn b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/BUILD.gn similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/BUILD.gn rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/BUILD.gn diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/__init__.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/__init__.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/__init__.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/__init__.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/error.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/error.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/error.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/error.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/fileutil.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/fileutil.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/fileutil.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/fileutil.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/fileutil_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/fileutil_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/fileutil_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/fileutil_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/__init__.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/__init__.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/generate/__init__.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/__init__.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/check.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/check.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/generate/check.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/check.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/generator.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/generator.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/generate/generator.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/generator.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/generator_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/generator_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/generate/generator_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/generator_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/module.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/module.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/generate/module.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/module.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/module_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/module_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/generate/module_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/module_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/pack.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/pack.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/generate/pack.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/pack.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/pack_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/pack_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/generate/pack_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/pack_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/template_expander.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/template_expander.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/generate/template_expander.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/template_expander.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/translate.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/translate.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/generate/translate.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/translate.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/generate/translate_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/parse/__init__.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/__init__.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/parse/__init__.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/__init__.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/parse/ast.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/ast.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/parse/ast.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/ast.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/parse/ast_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/ast_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/parse/ast_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/ast_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/parse/conditional_features.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/conditional_features.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/parse/conditional_features.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/conditional_features.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/parse/conditional_features_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/conditional_features_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/parse/conditional_features_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/conditional_features_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/parse/lexer.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/lexer.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/parse/lexer.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/lexer.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/parse/lexer_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/lexer_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/parse/lexer_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/lexer_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/parse/parser.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/parser.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/parse/parser.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/parser.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom/parse/parser_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/parser_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom/parse/parser_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom/parse/parser_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom_parser.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom_parser.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom_parser.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom_parser.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom_parser_test_case.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom_parser_test_case.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom_parser_test_case.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom_parser_test_case.py diff --git a/utils/ipc/mojo/public/tools/mojom/mojom_parser_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/mojom_parser_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/mojom_parser_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/mojom_parser_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/stable_attribute_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/stable_attribute_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/stable_attribute_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/stable_attribute_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/union_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/union_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/union_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/union_unittest.py diff --git a/utils/ipc/mojo/public/tools/mojom/version_compatibility_unittest.py b/utils/codegen/ipc/mojo/public/tools/mojom/version_compatibility_unittest.py similarity index 100% rename from utils/ipc/mojo/public/tools/mojom/version_compatibility_unittest.py rename to utils/codegen/ipc/mojo/public/tools/mojom/version_compatibility_unittest.py diff --git a/utils/ipc/mojo/public/tools/run_all_python_unittests.py b/utils/codegen/ipc/mojo/public/tools/run_all_python_unittests.py similarity index 100% rename from utils/ipc/mojo/public/tools/run_all_python_unittests.py rename to utils/codegen/ipc/mojo/public/tools/run_all_python_unittests.py diff --git a/utils/ipc/parser.py b/utils/codegen/ipc/parser.py similarity index 100% rename from utils/ipc/parser.py rename to utils/codegen/ipc/parser.py diff --git a/utils/ipc/tools/README b/utils/codegen/ipc/tools/README similarity index 100% rename from utils/ipc/tools/README rename to utils/codegen/ipc/tools/README diff --git a/utils/ipc/tools/diagnosis/crbug_1001171.py b/utils/codegen/ipc/tools/diagnosis/crbug_1001171.py similarity index 100% rename from utils/ipc/tools/diagnosis/crbug_1001171.py rename to utils/codegen/ipc/tools/diagnosis/crbug_1001171.py diff --git a/utils/codegen/meson.build b/utils/codegen/meson.build new file mode 100644 index 000000000000..7dd312e16559 --- /dev/null +++ b/utils/codegen/meson.build @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: CC0-1.0 + +## Code generation + +py_modules += ['jinja2', 'yaml'] + +gen_controls = files('gen-controls.py') +gen_formats = files('gen-formats.py') +gen_header = files('gen-header.sh') +gen_ipa_pub_key = files('gen-ipa-pub-key.py') +gen_tracepoints = files('gen-tp-header.py') + +subdir('ipc') diff --git a/utils/meson.build b/utils/meson.build index 8e28ada7165a..95d657ac965f 100644 --- a/utils/meson.build +++ b/utils/meson.build @@ -1,15 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 -subdir('ipc') +subdir('codegen') subdir('ipu3') -subdir('tracepoints') - -## Code generation -py_modules += ['yaml'] -gen_controls = files('gen-controls.py') -gen_formats = files('gen-formats.py') -gen_header = files('gen-header.sh') ## Module signing gen_ipa_priv_key = files('gen-ipa-priv-key.sh') -gen_ipa_pub_key = files('gen-ipa-pub-key.py') diff --git a/utils/tracepoints/meson.build b/utils/tracepoints/meson.build deleted file mode 100644 index 807230fc092d..000000000000 --- a/utils/tracepoints/meson.build +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-License-Identifier: CC0-1.0 - -py_modules += ['jinja2'] - -gen_tracepoints_header = find_program('./gen-tp-header.py') From patchwork Fri Aug 9 00:59:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20855 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 43815C324E for ; Fri, 9 Aug 2024 00:59:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BF47E633CC; Fri, 9 Aug 2024 02:59:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lmBxY0tJ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6129B633B5 for ; Fri, 9 Aug 2024 02:59:46 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6F67A83F for ; Fri, 9 Aug 2024 02:58:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723165132; bh=94VQjMKqgNrCpBOkdblxoiuR+MwLFIQit34kpjxveUg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lmBxY0tJlImRmWdJKyUnyv4oEtwfwgImXlveumCU6210QmJ/dI+Ipb5OWd2jgAe0T 2Qy8zOoIRqeW45hxcPGzxEKd7gbPyGieFMZZ+lJrY+62VW9rUwzgKjRd2qlX1Cx43x flS4VVKfHoyID4rUKyFRX/QTb5usdf+EhNNFKPPo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 05/10] meson: utils: Provide environment for Python scripts Date: Fri, 9 Aug 2024 03:59:09 +0300 Message-ID: <20240809005914.20662-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> References: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Python scripts run as part of the build process need to take a few actions specific to the environment in which they operate. One of those is disabling the Python bytecode cache, to avoid writing file to the source tree. This is done manually in the IPC generate.py and parser.py scripts. The current implementation is not ideal because it hardcodes in the scripts information related to the environment in which they operate. As those scripts are part of libcamera this is more of a theoretical issue than a practical one. A second issue is that future Python scripts will need to duplicate similar mechanisms, resulting in a higher maintenance burden. Address the issue with a different approach, by creating a meson environment for the Python scripts, and passing it to the custom_target() functions. The environment only disables the bytecode cache for now. The diffstat shows an increase in code size. This is expected to be offset by usage of the environment for more Python scripts, as well as support of more variables in the environment. Signed-off-by: Laurent Pinchart Reviewed-by: Tomi Valkeinen Reviewed-by: Daniel Scally Reviewed-by: Paul Elder --- include/libcamera/ipa/meson.build | 21 ++++++++++++------- src/libcamera/proxy/meson.build | 3 ++- src/libcamera/proxy/worker/meson.build | 3 ++- .../include/libcamera/ipa/meson.build | 9 +++++--- utils/codegen/ipc/generate.py | 3 --- utils/codegen/ipc/meson.build | 3 ++- utils/codegen/ipc/parser.py | 3 --- utils/codegen/meson.build | 4 ++++ 8 files changed, 30 insertions(+), 19 deletions(-) diff --git a/include/libcamera/ipa/meson.build b/include/libcamera/ipa/meson.build index 96fca42cc0b8..bf55e124e97e 100644 --- a/include/libcamera/ipa/meson.build +++ b/include/libcamera/ipa/meson.build @@ -26,7 +26,8 @@ ipa_mojom_core = custom_target(core_mojom_file.split('.')[0] + '_mojom_module', '--output-root', meson.project_build_root(), '--input-root', meson.project_source_root(), '--mojoms', '@INPUT@' - ]) + ], + env : py_build_env) # core_ipa_interface.h libcamera_ipa_headers += custom_target('core_ipa_interface_h', @@ -42,7 +43,8 @@ libcamera_ipa_headers += custom_target('core_ipa_interface_h', '--libcamera_generate_core_header', '--libcamera_output_path=@OUTPUT@', './' +'@INPUT@' - ]) + ], + env : py_build_env) # core_ipa_serializer.h libcamera_ipa_headers += custom_target('core_ipa_serializer_h', @@ -56,7 +58,8 @@ libcamera_ipa_headers += custom_target('core_ipa_serializer_h', '--libcamera_generate_core_serializer', '--libcamera_output_path=@OUTPUT@', './' +'@INPUT@' - ]) + ], + env : py_build_env) # Mapping from pipeline handler name to mojom file pipeline_ipa_mojom_mapping = { @@ -99,7 +102,8 @@ foreach pipeline, file : pipeline_ipa_mojom_mapping '--output-root', meson.project_build_root(), '--input-root', meson.project_source_root(), '--mojoms', '@INPUT@' - ]) + ], + env : py_build_env) # {interface}_ipa_interface.h header = custom_target(name + '_ipa_interface_h', @@ -115,7 +119,8 @@ foreach pipeline, file : pipeline_ipa_mojom_mapping '--libcamera_generate_header', '--libcamera_output_path=@OUTPUT@', './' +'@INPUT@' - ]) + ], + env : py_build_env) # {interface}_ipa_serializer.h serializer = custom_target(name + '_ipa_serializer_h', @@ -129,7 +134,8 @@ foreach pipeline, file : pipeline_ipa_mojom_mapping '--libcamera_generate_serializer', '--libcamera_output_path=@OUTPUT@', './' +'@INPUT@' - ]) + ], + env : py_build_env) # {interface}_ipa_proxy.h proxy_header = custom_target(name + '_proxy_h', @@ -143,7 +149,8 @@ foreach pipeline, file : pipeline_ipa_mojom_mapping '--libcamera_generate_proxy_h', '--libcamera_output_path=@OUTPUT@', './' +'@INPUT@' - ]) + ], + env : py_build_env) ipa_mojoms += { 'name': name, diff --git a/src/libcamera/proxy/meson.build b/src/libcamera/proxy/meson.build index d7de518a0549..8bd1b135d0f5 100644 --- a/src/libcamera/proxy/meson.build +++ b/src/libcamera/proxy/meson.build @@ -13,7 +13,8 @@ foreach mojom : ipa_mojoms '--libcamera_generate_proxy_cpp', '--libcamera_output_path=@OUTPUT@', './' + '@INPUT@' - ]) + ], + env : py_build_env) libcamera_internal_sources += proxy endforeach diff --git a/src/libcamera/proxy/worker/meson.build b/src/libcamera/proxy/worker/meson.build index b5ab9794c622..8c54a2e206a5 100644 --- a/src/libcamera/proxy/worker/meson.build +++ b/src/libcamera/proxy/worker/meson.build @@ -15,7 +15,8 @@ foreach mojom : ipa_mojoms '--libcamera_generate_proxy_worker', '--libcamera_output_path=@OUTPUT@', './' + '@INPUT@' - ]) + ], + env : py_build_env) proxy = executable(mojom['name'] + '_ipa_proxy', worker, install : true, diff --git a/test/serialization/generated_serializer/include/libcamera/ipa/meson.build b/test/serialization/generated_serializer/include/libcamera/ipa/meson.build index 6f8794c188a3..ae08e9bee6b9 100644 --- a/test/serialization/generated_serializer/include/libcamera/ipa/meson.build +++ b/test/serialization/generated_serializer/include/libcamera/ipa/meson.build @@ -9,7 +9,8 @@ mojom = custom_target('test_mojom_module', '--output-root', meson.project_build_root(), '--input-root', meson.project_source_root(), '--mojoms', '@INPUT@' - ]) + ], + env : py_build_env) # test_ipa_interface.h generated_test_header = custom_target('test_ipa_interface_h', @@ -23,7 +24,8 @@ generated_test_header = custom_target('test_ipa_interface_h', '--libcamera_generate_header', '--libcamera_output_path=@OUTPUT@', './' +'@INPUT@' - ]) + ], + env : py_build_env) # test_ipa_serializer.h generated_test_serializer = custom_target('test_ipa_serializer_h', @@ -37,4 +39,5 @@ generated_test_serializer = custom_target('test_ipa_serializer_h', '--libcamera_generate_serializer', '--libcamera_output_path=@OUTPUT@', './' +'@INPUT@' - ]) + ], + env : py_build_env) diff --git a/utils/codegen/ipc/generate.py b/utils/codegen/ipc/generate.py index c2b3fcb72e1f..dfbe659bc0ca 100755 --- a/utils/codegen/ipc/generate.py +++ b/utils/codegen/ipc/generate.py @@ -9,9 +9,6 @@ import os import sys -# TODO set sys.pycache_prefix for >= python3.8 -sys.dont_write_bytecode = True - sys.path.insert(0, f'{os.path.dirname(__file__)}/mojo/public/tools/bindings') import mojo.public.tools.bindings.mojom_bindings_generator as generator diff --git a/utils/codegen/ipc/meson.build b/utils/codegen/ipc/meson.build index 973a5417dc99..f77bf32497ba 100644 --- a/utils/codegen/ipc/meson.build +++ b/utils/codegen/ipc/meson.build @@ -13,6 +13,7 @@ mojom_docs_extractor = find_program('./extract-docs.py') mojom_templates = custom_target('mojom_templates', input : mojom_template_files, output : 'libcamera_templates.zip', - command : [mojom_generator, '-o', '@OUTDIR@', 'precompile']) + command : [mojom_generator, '-o', '@OUTDIR@', 'precompile'], + env : py_build_env) mojom_templates_dir = meson.current_build_dir() diff --git a/utils/codegen/ipc/parser.py b/utils/codegen/ipc/parser.py index cb5608b7c165..8e70322d1bdb 100755 --- a/utils/codegen/ipc/parser.py +++ b/utils/codegen/ipc/parser.py @@ -9,9 +9,6 @@ import os import sys -# TODO set sys.pycache_prefix for >= python3.8 -sys.dont_write_bytecode = True - # Make sure that mojom_parser.py can import mojom sys.path.insert(0, f'{os.path.dirname(__file__)}/mojo/public/tools/mojom') diff --git a/utils/codegen/meson.build b/utils/codegen/meson.build index 7dd312e16559..fb2196ee0d20 100644 --- a/utils/codegen/meson.build +++ b/utils/codegen/meson.build @@ -2,6 +2,10 @@ ## Code generation +py_build_env = environment() +# \todo Investigate usage of PYTHONPYCACHEPREFIX for Python >= 3.8 +py_build_env.set('PYTHONDONTWRITEBYTECODE', '1') + py_modules += ['jinja2', 'yaml'] gen_controls = files('gen-controls.py') From patchwork Fri Aug 9 00:59:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20856 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 36765BE173 for ; Fri, 9 Aug 2024 00:59:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CD74A633C1; Fri, 9 Aug 2024 02:59:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="mT/AcNKw"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CCE38633BD for ; Fri, 9 Aug 2024 02:59:47 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CF93E83F for ; Fri, 9 Aug 2024 02:58:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723165134; bh=9MzqF6BTpYdwHomjvD1Dc0CQb9pfsvcCpV6mhVdvlew=; h=From:To:Subject:Date:In-Reply-To:References:From; b=mT/AcNKwUdA7sxvD1iCb4HWFUx1KFr19Aq8rAkWQIyGLocLlTmlp9zemfc//5C6ff Tzcstxi5N8y7ObSwKt8pnE95w+cyRo8kuR5CfQAR1THMuJD+YXAWmKMIfu48pPfmnU s4TIO+YSAHvlpWkFi3/UWgQvUVmQgeZRBbKg4wmI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 06/10] utils: codegen: gen-header.sh: Generate libcamera.h based on meson.build Date: Fri, 9 Aug 2024 03:59:10 +0300 Message-ID: <20240809005914.20662-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> References: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The libcamera.h header is a top-level library header that contains every other libcamera header. It is currently generated by listing the files in include/libcamera/ and dropping the .in suffix from template files. This assumes a 1:1 mapping between generate header file names and the name of their templates. Drop that assumption and make the libcamera.h generation based on the libcamera public headers listed in meson.build. This makes the libcamera.h header generation more future-proof. Signed-off-by: Laurent Pinchart Reviewed-by: Daniel Scally Reviewed-by: Paul Elder --- include/libcamera/meson.build | 20 ++++++++++---------- utils/codegen/gen-header.sh | 7 +++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 36de1c2a393c..87b9a9412fe7 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -107,16 +107,6 @@ formats_h = custom_target('formats_h', install_dir : libcamera_headers_install_dir) libcamera_public_headers += formats_h -# libcamera.h -libcamera_h = custom_target('gen-header', - input : 'meson.build', - output : 'libcamera.h', - command : [gen_header, meson.current_source_dir(), '@OUTPUT@'], - install : true, - install_dir : libcamera_headers_install_dir) - -libcamera_public_headers += libcamera_h - # version.h version = libcamera_version.split('.') libcamera_version_config = configuration_data() @@ -129,3 +119,13 @@ version_h = configure_file(input : 'version.h.in', configuration : libcamera_version_config, install_dir : libcamera_headers_install_dir) libcamera_public_headers += version_h + +# libcamera.h +libcamera_h = custom_target('gen-header', + input : 'meson.build', + output : 'libcamera.h', + command : [gen_header, '@OUTPUT@', libcamera_public_headers], + install : true, + install_dir : libcamera_headers_install_dir) + +libcamera_public_headers += libcamera_h diff --git a/utils/codegen/gen-header.sh b/utils/codegen/gen-header.sh index d4692758eeb4..c78f085992ef 100755 --- a/utils/codegen/gen-header.sh +++ b/utils/codegen/gen-header.sh @@ -1,7 +1,7 @@ #!/bin/sh -src_dir="$1" -dst_file="$2" +dst_file="$1" +shift cat < "$dst_file" /* SPDX-License-Identifier: LGPL-2.1-or-later */ @@ -16,9 +16,8 @@ cat < "$dst_file" EOF -headers=$(for header in "$src_dir"/*.h "$src_dir"/*.h.in ; do +headers=$(for header in "$@" ; do header=$(basename "$header") - header="${header%.in}" echo "$header" done | sort) From patchwork Fri Aug 9 00:59:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20857 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 19578C324E for ; Fri, 9 Aug 2024 00:59:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C177A633CA; Fri, 9 Aug 2024 02:59:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RfscQgkX"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 57226633C1 for ; Fri, 9 Aug 2024 02:59:49 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3B239B7E for ; Fri, 9 Aug 2024 02:58:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723165135; bh=m2BDCSxnwKOufznelIctS8HRcKjM8GxloMDipDWtv5Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RfscQgkX7URDYY3kAEUOnlpgQT/fmrr+N/C/z1v+fGv+HE23t3ZvscwCK7lI9o3Ta XlOvw6RnpWg6PmA0t9i8v0UyA3lF09HHvAk7MZTBhYL6QKTYw1tJ/DT2ZHAR1d9YBr wUkBtbYGg945u5lYZotuJUI8uQYrmXNoX6MTpOgI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 07/10] utils: codegen: gen-controls.py: Convert to jinja2 templates Date: Fri, 9 Aug 2024 03:59:11 +0300 Message-ID: <20240809005914.20662-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> References: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Jinja2 templates help separating the logic related to the template from the generation of the data. The python code gets much clearer as a result. As an added bonus, we can use a single template file for both controls and properties. Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder --- include/libcamera/control_ids.h.in | 40 +++- include/libcamera/meson.build | 2 +- include/libcamera/property_ids.h.in | 34 ---- src/libcamera/control_ids.cpp.in | 101 ++++++++-- src/libcamera/meson.build | 5 +- src/libcamera/property_ids.cpp.in | 48 ----- utils/codegen/gen-controls.py | 285 ++++++---------------------- 7 files changed, 176 insertions(+), 339 deletions(-) delete mode 100644 include/libcamera/property_ids.h.in delete mode 100644 src/libcamera/property_ids.cpp.in diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in index 293ba966fbc4..858ef872e9ee 100644 --- a/include/libcamera/control_ids.h.in +++ b/include/libcamera/control_ids.h.in @@ -2,7 +2,7 @@ /* * Copyright (C) 2019, Google Inc. * - * Control ID list + * {{mode|capitalize}} ID list * * This file is auto-generated. Do not edit. */ @@ -18,18 +18,42 @@ namespace libcamera { -namespace controls { +namespace {{mode}} { + +extern const ControlIdMap {{mode}}; + +{%- for vendor, ctrls in controls -%} + +{% if vendor != 'libcamera' %} +namespace {{vendor}} { + +#define LIBCAMERA_HAS_{{vendor|upper}}_VENDOR_{{mode|upper}} +{%- endif %} enum { -${ids} +{%- for ctrl in ctrls %} + {{ctrl.name|snake_case|upper}} = {{ctrl.id}}, +{%- endfor %} }; -${controls} +{% for ctrl in ctrls -%} +{% if ctrl.is_enum -%} +enum {{ctrl.name}}Enum { +{%- for enum in ctrl.enum_values %} + {{enum.name}} = {{enum.value}}, +{%- endfor %} +}; +extern const std::array {{ctrl.name}}Values; +extern const std::map {{ctrl.name}}NameValueMap; +{% endif -%} +extern const Control<{{ctrl.type}}> {{ctrl.name}}; +{% endfor -%} -extern const ControlIdMap controls; +{% if vendor != 'libcamera' %} +} /* namespace {{vendor}} */ +{% endif -%} -${vendor_controls} - -} /* namespace controls */ +{% endfor %} +} /* namespace {{mode}} */ } /* namespace libcamera */ diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 87b9a9412fe7..d90a8615e52d 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -80,7 +80,7 @@ foreach mode, entry : controls_map properties_files_names += files_list endif - template_file = files(outfile + '.in') + template_file = files('control_ids.h.in') ranges_file = files('../../src/libcamera/control_ranges.yaml') control_headers += custom_target(header + '_h', input : input_files, diff --git a/include/libcamera/property_ids.h.in b/include/libcamera/property_ids.h.in deleted file mode 100644 index e6edabca771f..000000000000 --- a/include/libcamera/property_ids.h.in +++ /dev/null @@ -1,34 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * Property ID list - * - * This file is auto-generated. Do not edit. - */ - -#pragma once - -#include -#include -#include - -#include - -namespace libcamera { - -namespace properties { - -enum { -${ids} -}; - -${controls} - -extern const ControlIdMap properties; - -${vendor_controls} - -} /* namespace properties */ - -} /* namespace libcamera */ diff --git a/src/libcamera/control_ids.cpp.in b/src/libcamera/control_ids.cpp.in index 0b028c92d852..05c8fb385d20 100644 --- a/src/libcamera/control_ids.cpp.in +++ b/src/libcamera/control_ids.cpp.in @@ -2,51 +2,120 @@ /* * Copyright (C) 2019, Google Inc. * - * Control ID list + * {{mode}} ID list * * This file is auto-generated. Do not edit. */ -#include +#include #include /** - * \file control_ids.h - * \brief Camera control identifiers + * \file {{filename}}.h + * \brief Camera {{mode}} identifiers */ namespace libcamera { /** - * \brief Namespace for libcamera controls + * \brief Namespace for libcamera {{mode}} */ -namespace controls { +namespace {{mode}} { -${controls_doc} +{%- for vendor, ctrls in controls -%} -${vendor_controls_doc} +{%- if vendor != 'libcamera' %} +/** + * \brief Namespace for {{vendor}} {{mode}} + */ +namespace {{vendor}} { +{%- endif -%} + +{% for ctrl in ctrls %} + +{% if ctrl.is_enum -%} +/** + * \enum {{ctrl.name}}Enum + * \brief Supported {{ctrl.name}} values +{%- for enum in ctrl.enum_values %} + * + * \var {{enum.name}} + * \brief {{enum.description|format_description}} +{%- endfor %} + */ + +/** + * \var {{ctrl.name}}Values + * \brief List of all {{ctrl.name}} supported values + */ + +/** + * \var {{ctrl.name}}NameValueMap + * \brief Map of all {{ctrl.name}} supported value names (in std::string format) to value + */ + +{% endif -%} +/** + * \var {{ctrl.name}} + * \brief {{ctrl.description|format_description}} + */ +{%- endfor %} +{% if vendor != 'libcamera' %} +} /* namespace {{vendor}} */ +{% endif -%} + +{%- endfor %} #ifndef __DOXYGEN__ /* - * Keep the controls definitions hidden from doxygen as it incorrectly parses + * Keep the {{mode}} definitions hidden from doxygen as it incorrectly parses * them as functions. */ -${controls_def} +{% for vendor, ctrls in controls -%} -${vendor_controls_def} +{% if vendor != 'libcamera' %} +namespace {{vendor}} { +{% endif %} -#endif +{%- for ctrl in ctrls %} +{% if ctrl.is_enum -%} +extern const std::array {{ctrl.name}}Values = { +{%- for enum in ctrl.enum_values %} + static_cast<{{ctrl.type}}>({{enum.name}}), +{%- endfor %} +}; +extern const std::map {{ctrl.name}}NameValueMap = { +{%- for enum in ctrl.enum_values %} + { "{{enum.name}}", {{enum.name}} }, +{%- endfor %} +}; +{% endif -%} +extern const Control<{{ctrl.type}}> {{ctrl.name}}({{ctrl.name|snake_case|upper}}, "{{ctrl.name}}"); +{%- endfor %} + +{% if vendor != 'libcamera' %} +} /* namespace {{vendor}} */ +{% endif -%} + +{%- endfor %} +#endif /* __DOXYGEN__ */ /** - * \brief List of all supported libcamera controls + * \brief List of all supported libcamera {{mode}} +{%- if mode == 'controls' %} * * Unless otherwise stated, all controls are bi-directional, i.e. they can be * set through Request::controls() and returned out through Request::metadata(). +{%- endif %} */ -extern const ControlIdMap controls { -${controls_map} +extern const ControlIdMap {{mode}} { +{%- for vendor, ctrls in controls -%} +{%- for ctrl in ctrls %} + { {{ctrl.namespace}}{{ctrl.name|snake_case|upper}}, &{{ctrl.namespace}}{{ctrl.name}} }, +{%- endfor -%} +{%- endfor %} }; -} /* namespace controls */ +} /* namespace {{mode}} */ } /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index e5e959d9c7bd..3fd3a87e9f95 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -143,9 +143,10 @@ foreach mode, inout_files : controls_mode_files input_files = inout_files[0] output_file = inout_files[1] - template_file = files(output_file + '.in') + template_file = files('control_ids.cpp.in') ranges_file = files('control_ranges.yaml') - control_sources += custom_target(mode + '_cpp', + + control_sources += custom_target(mode + '_ids_cpp', input : input_files, output : output_file, command : [gen_controls, '-o', '@OUTPUT@', diff --git a/src/libcamera/property_ids.cpp.in b/src/libcamera/property_ids.cpp.in deleted file mode 100644 index 2d3f192eb6ef..000000000000 --- a/src/libcamera/property_ids.cpp.in +++ /dev/null @@ -1,48 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * Property ID list - * - * This file is auto-generated. Do not edit. - */ - -#include - -/** - * \file property_ids.h - * \brief Camera property identifiers - */ - -namespace libcamera { - -/** - * \brief Namespace for libcamera properties - */ -namespace properties { - -${controls_doc} - -${vendor_controls_doc} - -#ifndef __DOXYGEN__ -/* - * Keep the properties definitions hidden from doxygen as it incorrectly parses - * them as functions. - */ -${controls_def} - -${vendor_controls_def} - -#endif - -/** - * \brief List of all supported libcamera properties - */ -extern const ControlIdMap properties { -${controls_map} -}; - -} /* namespace properties */ - -} /* namespace libcamera */ diff --git a/utils/codegen/gen-controls.py b/utils/codegen/gen-controls.py index 56315f5089b4..685ef7a00d5f 100755 --- a/utils/codegen/gen-controls.py +++ b/utils/codegen/gen-controls.py @@ -7,12 +7,10 @@ # Generate control definitions from YAML import argparse -from functools import reduce -import operator -import string +import jinja2 +import os import sys import yaml -import os class ControlEnum(object): @@ -81,6 +79,13 @@ class Control(object): for enum in self.__enum_values: yield enum + @property + def enum_values_count(self): + """The number of enum values, if the control is an enumeration""" + if self.__enum_values is None: + return 0 + return len(self.__enum_values) + @property def is_enum(self): """Is the control an enumeration""" @@ -119,221 +124,23 @@ def snake_case(s): def format_description(description): description = description.strip('\n').split('\n') - description[0] = '\\brief ' + description[0] - return '\n'.join([(line and ' * ' or ' *') + line for line in description]) + for i in range(1, len(description)): + line = description[i] + description[i] = (line and ' * ' or ' *') + line + return '\n'.join(description) -def generate_cpp(controls): - enum_doc_start_template = string.Template('''/** - * \\enum ${name}Enum - * \\brief Supported ${name} values''') - enum_doc_value_template = string.Template(''' * \\var ${value} -${description}''') - doc_template = string.Template('''/** - * \\var ${name} -${description} - */''') - def_template = string.Template('extern const Control<${type}> ${name}(${id_name}, "${name}");') - enum_values_doc = string.Template('''/** - * \\var ${name}Values - * \\brief List of all $name supported values - */''') - enum_values_start = string.Template('''extern const std::array ${name}Values = {''') - enum_values_values = string.Template('''\tstatic_cast(${name}),''') - name_value_map_doc = string.Template('''/** - * \\var ${name}NameValueMap - * \\brief Map of all $name supported value names (in std::string format) to value - */''') - name_value_map_start = string.Template('''extern const std::map ${name}NameValueMap = {''') - name_value_values = string.Template('''\t{ "${name}", ${name} },''') +def extend_control(ctrl, id, ranges): + ctrl.id = ranges[ctrl.vendor] + id + 1 - ctrls_doc = {} - ctrls_def = {} - ctrls_map = [] + if ctrl.vendor != 'libcamera': + ctrl.namespace = f'{ctrl.vendor}::' + else: + ctrl.namespace = '' - for ctrl in controls: - id_name = snake_case(ctrl.name).upper() + ctrl.documentation = format_description(ctrl.description) - vendor = ctrl.vendor - if vendor not in ctrls_doc: - ctrls_doc[vendor] = [] - ctrls_def[vendor] = [] - - info = { - 'name': ctrl.name, - 'type': ctrl.type, - 'description': format_description(ctrl.description), - 'id_name': id_name, - } - - target_doc = ctrls_doc[vendor] - target_def = ctrls_def[vendor] - - if ctrl.is_enum: - enum_doc = [] - enum_doc.append(enum_doc_start_template.substitute(info)) - - num_entries = 0 - for enum in ctrl.enum_values: - value_info = { - 'name': ctrl.name, - 'value': enum.name, - 'description': format_description(enum.description), - } - enum_doc.append(enum_doc_value_template.substitute(value_info)) - num_entries += 1 - - enum_doc = '\n *\n'.join(enum_doc) - enum_doc += '\n */' - target_doc.append(enum_doc) - - values_info = { - 'name': info['name'], - 'type': ctrl.type, - 'size': num_entries, - } - target_doc.append(enum_values_doc.substitute(values_info)) - target_def.append(enum_values_start.substitute(values_info)) - for enum in ctrl.enum_values: - value_info = { - 'name': enum.name - } - target_def.append(enum_values_values.substitute(value_info)) - target_def.append("};") - - target_doc.append(name_value_map_doc.substitute(values_info)) - target_def.append(name_value_map_start.substitute(values_info)) - for enum in ctrl.enum_values: - value_info = { - 'name': enum.name - } - target_def.append(name_value_values.substitute(value_info)) - target_def.append("};") - - target_doc.append(doc_template.substitute(info)) - target_def.append(def_template.substitute(info)) - - vendor_ns = vendor + '::' if vendor != "libcamera" else '' - ctrls_map.append('\t{ ' + vendor_ns + id_name + ', &' + vendor_ns + ctrl.name + ' },') - - vendor_ctrl_doc_sub = [] - vendor_ctrl_template = string.Template(''' -/** - * \\brief Namespace for ${vendor} controls - */ -namespace ${vendor} { - -${vendor_controls_str} - -} /* namespace ${vendor} */''') - - for vendor in [v for v in ctrls_doc.keys() if v not in ['libcamera']]: - vendor_ctrl_doc_sub.append(vendor_ctrl_template.substitute({'vendor': vendor, 'vendor_controls_str': '\n\n'.join(ctrls_doc[vendor])})) - - vendor_ctrl_def_sub = [] - for vendor in [v for v in ctrls_def.keys() if v not in ['libcamera']]: - vendor_ctrl_def_sub.append(vendor_ctrl_template.substitute({'vendor': vendor, 'vendor_controls_str': '\n'.join(ctrls_def[vendor])})) - - return { - 'controls_doc': '\n\n'.join(ctrls_doc['libcamera']), - 'controls_def': '\n'.join(ctrls_def['libcamera']), - 'controls_map': '\n'.join(ctrls_map), - 'vendor_controls_doc': '\n'.join(vendor_ctrl_doc_sub), - 'vendor_controls_def': '\n'.join(vendor_ctrl_def_sub), - } - - -def generate_h(controls, mode, ranges): - enum_template_start = string.Template('''enum ${name}Enum {''') - enum_value_template = string.Template('''\t${name} = ${value},''') - enum_values_template = string.Template('''extern const std::array ${name}Values;''') - name_value_map_template = string.Template('''extern const std::map ${name}NameValueMap;''') - template = string.Template('''extern const Control<${type}> ${name};''') - - ctrls = {} - ids = {} - id_value = {} - - for ctrl in controls: - id_name = snake_case(ctrl.name).upper() - - vendor = ctrl.vendor - if vendor not in ctrls: - if vendor not in ranges.keys(): - raise RuntimeError(f'Control id range is not defined for vendor {vendor}') - id_value[vendor] = ranges[vendor] + 1 - ids[vendor] = [] - ctrls[vendor] = [] - - target_ids = ids[vendor] - target_ids.append('\t' + id_name + ' = ' + str(id_value[vendor]) + ',') - - info = { - 'name': ctrl.name, - 'type': ctrl.type, - } - - target_ctrls = ctrls[vendor] - - if ctrl.is_enum: - target_ctrls.append(enum_template_start.substitute(info)) - - num_entries = 0 - for enum in ctrl.enum_values: - value_info = { - 'name': enum.name, - 'value': enum.value, - } - target_ctrls.append(enum_value_template.substitute(value_info)) - num_entries += 1 - target_ctrls.append("};") - - values_info = { - 'name': info['name'], - 'type': ctrl.type, - 'size': num_entries, - } - target_ctrls.append(enum_values_template.substitute(values_info)) - target_ctrls.append(name_value_map_template.substitute(values_info)) - - target_ctrls.append(template.substitute(info)) - id_value[vendor] += 1 - - vendor_template = string.Template(''' -namespace ${vendor} { - -#define LIBCAMERA_HAS_${vendor_def}_VENDOR_${mode} - -enum { -${vendor_enums} -}; - -${vendor_controls} - -} /* namespace ${vendor} */ -''') - - vendor_sub = [] - for vendor in [v for v in ctrls.keys() if v != 'libcamera']: - vendor_sub.append(vendor_template.substitute({'mode': mode.upper(), - 'vendor': vendor, - 'vendor_def': vendor.upper(), - 'vendor_enums': '\n'.join(ids[vendor]), - 'vendor_controls': '\n'.join(ctrls[vendor])})) - - return { - 'ids': '\n'.join(ids['libcamera']), - 'controls': '\n'.join(ctrls['libcamera']), - 'vendor_controls': '\n'.join(vendor_sub) - } - - -def fill_template(template, data): - - template = open(template, 'rb').read() - template = template.decode('utf-8') - template = string.Template(template) - return template.substitute(data) + return ctrl def main(argv): @@ -358,29 +165,47 @@ def main(argv): data = open(args.ranges, 'rb').read() ranges = yaml.safe_load(data)['ranges'] - controls = [] + controls = {} for input in args.input: - with open(input, 'rb') as f: - data = f.read() - vendor = yaml.safe_load(data)['vendor'] - ctrls = yaml.safe_load(data)['controls'] - controls = controls + [Control(*ctrl.popitem(), vendor) for ctrl in ctrls] + data = yaml.safe_load(open(input, 'rb').read()) - if args.template.endswith('.cpp.in'): - data = generate_cpp(controls) - elif args.template.endswith('.h.in'): - data = generate_h(controls, args.mode, ranges) - else: - raise RuntimeError('Unknown template type') + vendor = data['vendor'] + if vendor not in ranges.keys(): + raise RuntimeError(f'Control id range is not defined for vendor {vendor}') - data = fill_template(args.template, data) + ctrls = controls.setdefault(vendor, []) + + for i, ctrl in enumerate(data['controls']): + ctrl = Control(*ctrl.popitem(), vendor) + ctrls.append(extend_control(ctrl, i, ranges)) + + # Sort the vendors by range numerical value + controls = [[vendor, ctrls] for vendor, ctrls in controls.items()] + controls.sort(key=lambda item: ranges[item[0]]) + + filename = { + 'controls': 'control_ids', + 'properties': 'property_ids', + }[args.mode] + + data = { + 'filename': filename, + 'mode': args.mode, + 'controls': controls, + } + + env = jinja2.Environment() + env.filters['format_description'] = format_description + env.filters['snake_case'] = snake_case + template = env.from_string(open(args.template, 'r', encoding='utf-8').read()) + string = template.render(data) if args.output: - output = open(args.output, 'wb') - output.write(data.encode('utf-8')) + output = open(args.output, 'w', encoding='utf-8') + output.write(string) output.close() else: - sys.stdout.write(data) + sys.stdout.write(string) return 0 From patchwork Fri Aug 9 00:59:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20858 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 4FDEEBE173 for ; Fri, 9 Aug 2024 00:59:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D0F44633BF; Fri, 9 Aug 2024 02:59:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Gmjkn5QP"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ABE41633C0 for ; Fri, 9 Aug 2024 02:59:50 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B99C583F for ; Fri, 9 Aug 2024 02:58:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723165137; bh=QLOZcqushEoVrUTD8zs45EtV+xtVBVXO3eX7CZghrcg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Gmjkn5QPPvIQlOeIteGjdHUn9+bu8urAwd2P08pVDOrbnoGLyJ25culKECKmKGzWe 78iIRso9X6lOOXdTQ9JwhYuDmy6nS4SvwOnmwDS28+IghQOL5DqiRtp6ipha3Q1DcG J9Kb4Vm7cQ/UWPf6lSHmHbIJdjpKhnLON3iljjxc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 08/10] utils: codegen: gen-controls.py: Move helper classes to separate file Date: Fri, 9 Aug 2024 03:59:12 +0300 Message-ID: <20240809005914.20662-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> References: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The ControlEnum and Control helper classes defined in gen-controls.py are useful for other generator scripts. Move them to a separate file to make it possible to share them. Extend the Python build environment to add the path to the new Python module to PYTHONPATH, and use it when invoking the gen-controls.py script. Signed-off-by: Laurent Pinchart Reviewed-by: Daniel Scally --- include/libcamera/meson.build | 1 + src/libcamera/meson.build | 3 +- utils/codegen/controls.py | 112 ++++++++++++++++++++++++++++++++++ utils/codegen/gen-controls.py | 105 +------------------------------ 4 files changed, 116 insertions(+), 105 deletions(-) create mode 100644 utils/codegen/controls.py diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index d90a8615e52d..a969a95dbf7a 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -88,6 +88,7 @@ foreach mode, entry : controls_map command : [gen_controls, '-o', '@OUTPUT@', '--mode', mode, '-t', template_file, '-r', ranges_file, '@INPUT@'], + env : py_build_env, install : true, install_dir : libcamera_headers_install_dir) endforeach diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 3fd3a87e9f95..aa9ab0291854 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -151,7 +151,8 @@ foreach mode, inout_files : controls_mode_files output : output_file, command : [gen_controls, '-o', '@OUTPUT@', '--mode', mode, '-t', template_file, - '-r', ranges_file, '@INPUT@']) + '-r', ranges_file, '@INPUT@'], + env : py_build_env) endforeach libcamera_public_sources += control_sources diff --git a/utils/codegen/controls.py b/utils/codegen/controls.py new file mode 100644 index 000000000000..7bafee599c80 --- /dev/null +++ b/utils/codegen/controls.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2019, Google Inc. +# +# Author: Laurent Pinchart +# +# Helper classes to handle source code generation for libcamera controls + + +class ControlEnum(object): + def __init__(self, data): + self.__data = data + + @property + def description(self): + """The enum description""" + return self.__data.get('description') + + @property + def name(self): + """The enum name""" + return self.__data.get('name') + + @property + def value(self): + """The enum value""" + return self.__data.get('value') + + +class Control(object): + def __init__(self, name, data, vendor): + self.__name = name + self.__data = data + self.__enum_values = None + self.__size = None + self.__vendor = vendor + + enum_values = data.get('enum') + if enum_values is not None: + self.__enum_values = [ControlEnum(enum) for enum in enum_values] + + size = self.__data.get('size') + if size is not None: + if len(size) == 0: + raise RuntimeError(f'Control `{self.__name}` size must have at least one dimension') + + # Compute the total number of elements in the array. If any of the + # array dimension is a string, the array is variable-sized. + num_elems = 1 + for dim in size: + if type(dim) is str: + num_elems = 0 + break + + dim = int(dim) + if dim <= 0: + raise RuntimeError(f'Control `{self.__name}` size must have positive values only') + + num_elems *= dim + + self.__size = num_elems + + @property + def description(self): + """The control description""" + return self.__data.get('description') + + @property + def enum_values(self): + """The enum values, if the control is an enumeration""" + if self.__enum_values is None: + return + for enum in self.__enum_values: + yield enum + + @property + def enum_values_count(self): + """The number of enum values, if the control is an enumeration""" + if self.__enum_values is None: + return 0 + return len(self.__enum_values) + + @property + def is_enum(self): + """Is the control an enumeration""" + return self.__enum_values is not None + + @property + def vendor(self): + """The vendor string, or None""" + return self.__vendor + + @property + def name(self): + """The control name (CamelCase)""" + return self.__name + + @property + def type(self): + typ = self.__data.get('type') + size = self.__data.get('size') + + if typ == 'string': + return 'std::string' + + if self.__size is None: + return typ + + if self.__size: + return f"Span" + else: + return f"Span" diff --git a/utils/codegen/gen-controls.py b/utils/codegen/gen-controls.py index 685ef7a00d5f..2968eb9a5d4e 100755 --- a/utils/codegen/gen-controls.py +++ b/utils/codegen/gen-controls.py @@ -12,110 +12,7 @@ import os import sys import yaml - -class ControlEnum(object): - def __init__(self, data): - self.__data = data - - @property - def description(self): - """The enum description""" - return self.__data.get('description') - - @property - def name(self): - """The enum name""" - return self.__data.get('name') - - @property - def value(self): - """The enum value""" - return self.__data.get('value') - - -class Control(object): - def __init__(self, name, data, vendor): - self.__name = name - self.__data = data - self.__enum_values = None - self.__size = None - self.__vendor = vendor - - enum_values = data.get('enum') - if enum_values is not None: - self.__enum_values = [ControlEnum(enum) for enum in enum_values] - - size = self.__data.get('size') - if size is not None: - if len(size) == 0: - raise RuntimeError(f'Control `{self.__name}` size must have at least one dimension') - - # Compute the total number of elements in the array. If any of the - # array dimension is a string, the array is variable-sized. - num_elems = 1 - for dim in size: - if type(dim) is str: - num_elems = 0 - break - - dim = int(dim) - if dim <= 0: - raise RuntimeError(f'Control `{self.__name}` size must have positive values only') - - num_elems *= dim - - self.__size = num_elems - - @property - def description(self): - """The control description""" - return self.__data.get('description') - - @property - def enum_values(self): - """The enum values, if the control is an enumeration""" - if self.__enum_values is None: - return - for enum in self.__enum_values: - yield enum - - @property - def enum_values_count(self): - """The number of enum values, if the control is an enumeration""" - if self.__enum_values is None: - return 0 - return len(self.__enum_values) - - @property - def is_enum(self): - """Is the control an enumeration""" - return self.__enum_values is not None - - @property - def vendor(self): - """The vendor string, or None""" - return self.__vendor - - @property - def name(self): - """The control name (CamelCase)""" - return self.__name - - @property - def type(self): - typ = self.__data.get('type') - size = self.__data.get('size') - - if typ == 'string': - return 'std::string' - - if self.__size is None: - return typ - - if self.__size: - return f"Span" - else: - return f"Span" +from controls import Control def snake_case(s): From patchwork Fri Aug 9 00:59:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20859 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 77332C32D5 for ; Fri, 9 Aug 2024 00:59:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D2CE1633C9; Fri, 9 Aug 2024 02:59:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bTWLPzwM"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 234FD633CD for ; Fri, 9 Aug 2024 02:59:52 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2B5BC83F for ; Fri, 9 Aug 2024 02:58:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723165138; bh=7fKKDaIFyyJ5HbNkseLGDiGUEMMyrsKzO/H3tnbmhcU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bTWLPzwM4baMKs5sUh/dDJS+4Blz2YNfs+fFF/XnG5GjXPiKqUfretZxz6K6tPIbA YWU03IPvMCuRcI/+D4t1QRz824a657i0znjtK+JpQB3x67GFncAXrLE2eX8rFaRcZT ex6ZoRg7iOxoAsoaa5pgh8NNCCZRtk4FwU4dH7bE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 09/10] py: gen-py-controls: Use Control class Date: Fri, 9 Aug 2024 03:59:13 +0300 Message-ID: <20240809005914.20662-10-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> References: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace manual extraction of data from YAML with the Control helper class. This centralizes YAML parsing and avoids manual mistakes. In order to import the controls module, add the utils/codegen/ directory to the PYTHONPATH through the Python build environment. Signed-off-by: Laurent Pinchart Reviewed-by: Tomi Valkeinen Reviewed-by: Paul Elder --- src/py/libcamera/gen-py-controls.py | 32 ++++++++++++++--------------- src/py/libcamera/meson.build | 6 ++++-- utils/codegen/meson.build | 1 + 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/py/libcamera/gen-py-controls.py b/src/py/libcamera/gen-py-controls.py index 8efbf95b9433..a18dc5337090 100755 --- a/src/py/libcamera/gen-py-controls.py +++ b/src/py/libcamera/gen-py-controls.py @@ -8,6 +8,8 @@ import string import sys import yaml +from controls import Control + def find_common_prefix(strings): prefix = strings[0] @@ -28,9 +30,7 @@ def generate_py(controls, mode): vendor_defs = [] vendors = [] for vendor, ctrl_list in controls.items(): - for ctrls in ctrl_list: - name, ctrl = ctrls.popitem() - + for ctrl in ctrl_list: if vendor not in vendors and vendor != 'libcamera': vendor_mode_str = f'{vendor.capitalize()}{mode.capitalize()}' vendors_class_def.append('class Py{}\n{{\n}};\n'.format(vendor_mode_str)) @@ -44,29 +44,28 @@ def generate_py(controls, mode): ns = 'libcamera::{}::'.format(mode) container = 'controls' - out += f'\t{container}.def_readonly_static("{name}", static_cast(&{ns}{name}));\n\n' + out += f'\t{container}.def_readonly_static("{ctrl.name}", static_cast(&{ns}{ctrl.name}));\n\n' - enum = ctrl.get('enum') - if not enum: + if not ctrl.is_enum: continue - cpp_enum = name + 'Enum' + cpp_enum = ctrl.name + 'Enum' out += '\tpy::enum_<{}{}>({}, \"{}\")\n'.format(ns, cpp_enum, container, cpp_enum) if mode == 'controls': # Adjustments for controls - if name == 'LensShadingMapMode': + if ctrl.name == 'LensShadingMapMode': prefix = 'LensShadingMapMode' else: - prefix = find_common_prefix([e['name'] for e in enum]) + prefix = find_common_prefix([e.name for e in ctrl.enum_values]) else: # Adjustments for properties - prefix = find_common_prefix([e['name'] for e in enum]) + prefix = find_common_prefix([e.name for e in ctrl.enum_values]) - for entry in enum: - cpp_enum = entry['name'] - py_enum = entry['name'][len(prefix):] + for entry in ctrl.enum_values: + cpp_enum = entry.name + py_enum = entry.name[len(prefix):] out += '\t\t.value(\"{}\", {}{})\n'.format(py_enum, ns, cpp_enum) @@ -103,9 +102,10 @@ def main(argv): controls = {} for input in args.input: - data = open(input, 'rb').read() - vendor = yaml.safe_load(data)['vendor'] - controls[vendor] = yaml.safe_load(data)['controls'] + data = yaml.safe_load(open(input, 'rb').read()) + vendor = data['vendor'] + ctrls = data['controls'] + controls[vendor] = [Control(*ctrl.popitem(), vendor) for ctrl in ctrls] data = generate_py(controls, args.mode) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index 2e67407598db..6ad2d7713e4d 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -35,7 +35,8 @@ pycamera_sources += custom_target('py_gen_controls', input : controls_files, output : ['py_controls_generated.cpp'], command : [gen_py_controls, '--mode', 'controls', '-o', '@OUTPUT@', - '-t', gen_py_controls_template, '@INPUT@']) + '-t', gen_py_controls_template, '@INPUT@'], + env : py_build_env) # Generate properties @@ -45,7 +46,8 @@ pycamera_sources += custom_target('py_gen_properties', input : properties_files, output : ['py_properties_generated.cpp'], command : [gen_py_controls, '--mode', 'properties', '-o', '@OUTPUT@', - '-t', gen_py_properties_template, '@INPUT@']) + '-t', gen_py_properties_template, '@INPUT@'], + env : py_build_env) # Generate formats diff --git a/utils/codegen/meson.build b/utils/codegen/meson.build index fb2196ee0d20..adf33bbab9e1 100644 --- a/utils/codegen/meson.build +++ b/utils/codegen/meson.build @@ -5,6 +5,7 @@ py_build_env = environment() # \todo Investigate usage of PYTHONPYCACHEPREFIX for Python >= 3.8 py_build_env.set('PYTHONDONTWRITEBYTECODE', '1') +py_build_env.prepend('PYTHONPATH', meson.current_source_dir()) py_modules += ['jinja2', 'yaml'] From patchwork Fri Aug 9 00:59:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20860 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B1573C324E for ; Fri, 9 Aug 2024 00:59:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4BC9E633B9; Fri, 9 Aug 2024 02:59:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ssTniF5E"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 93A17633CF for ; Fri, 9 Aug 2024 02:59:53 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AB482B7E for ; Fri, 9 Aug 2024 02:58:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723165139; bh=tuKkHfuK0EwhaQlqsgtId1QaRGXsZiYe4uQdLq5do6Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ssTniF5Ei5VwbVD85ts04dRYlgrDZ/zlXEgcNkSmRxlZFd7SOOAgzUipeDIfyzM8i fD2NBoU6JdlgypUHJ2lrmsjZ05NPe4/ndJ/mwhwTCJ+8EEIvjCFPkgrY4xwdQNJq5f waj3vZzxCBsHHZ7sNzkDtz5i9kHz9bT861S+RX0E= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH 10/10] py: gen-py-controls: Convert to jinja2 templates Date: Fri, 9 Aug 2024 03:59:14 +0300 Message-ID: <20240809005914.20662-11-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> References: <20240809005914.20662-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Jinja2 templates help separating the logic related to the template from the generation of the data. The python code gets much clearer as a result. As an added bonus, we can use a single template file for both controls and properties. Signed-off-by: Laurent Pinchart Reviewed-by: Tomi Valkeinen Acked-by: Paul Elder --- src/py/libcamera/gen-py-controls.py | 114 ++++++++---------- src/py/libcamera/meson.build | 8 +- src/py/libcamera/py_controls_generated.cpp.in | 35 ++++-- .../libcamera/py_properties_generated.cpp.in | 30 ----- 4 files changed, 78 insertions(+), 109 deletions(-) delete mode 100644 src/py/libcamera/py_properties_generated.cpp.in diff --git a/src/py/libcamera/gen-py-controls.py b/src/py/libcamera/gen-py-controls.py index a18dc5337090..cf09c146084d 100755 --- a/src/py/libcamera/gen-py-controls.py +++ b/src/py/libcamera/gen-py-controls.py @@ -4,7 +4,7 @@ # Generate Python bindings controls from YAML import argparse -import string +import jinja2 import sys import yaml @@ -23,67 +23,39 @@ def find_common_prefix(strings): return prefix -def generate_py(controls, mode): - out = '' +def extend_control(ctrl, mode): + if ctrl.vendor != 'libcamera': + ctrl.klass = ctrl.vendor + ctrl.namespace = f'{ctrl.vendor}::' + else: + ctrl.klass = mode + ctrl.namespace = '' - vendors_class_def = [] - vendor_defs = [] - vendors = [] - for vendor, ctrl_list in controls.items(): - for ctrl in ctrl_list: - if vendor not in vendors and vendor != 'libcamera': - vendor_mode_str = f'{vendor.capitalize()}{mode.capitalize()}' - vendors_class_def.append('class Py{}\n{{\n}};\n'.format(vendor_mode_str)) - vendor_defs.append('\tauto {} = py::class_(controls, \"{}\");'.format(vendor, vendor_mode_str, vendor)) - vendors.append(vendor) + if not ctrl.is_enum: + return ctrl - if vendor != 'libcamera': - ns = 'libcamera::{}::{}::'.format(mode, vendor) - container = vendor - else: - ns = 'libcamera::{}::'.format(mode) - container = 'controls' + if mode == 'controls': + # Adjustments for controls + if ctrl.name == 'LensShadingMapMode': + prefix = 'LensShadingMapMode' + else: + prefix = find_common_prefix([e.name for e in ctrl.enum_values]) + else: + # Adjustments for properties + prefix = find_common_prefix([e.name for e in ctrl.enum_values]) - out += f'\t{container}.def_readonly_static("{ctrl.name}", static_cast(&{ns}{ctrl.name}));\n\n' + for enum in ctrl.enum_values: + enum.py_name = enum.name[len(prefix):] - if not ctrl.is_enum: - continue - - cpp_enum = ctrl.name + 'Enum' - - out += '\tpy::enum_<{}{}>({}, \"{}\")\n'.format(ns, cpp_enum, container, cpp_enum) - - if mode == 'controls': - # Adjustments for controls - if ctrl.name == 'LensShadingMapMode': - prefix = 'LensShadingMapMode' - else: - prefix = find_common_prefix([e.name for e in ctrl.enum_values]) - else: - # Adjustments for properties - prefix = find_common_prefix([e.name for e in ctrl.enum_values]) - - for entry in ctrl.enum_values: - cpp_enum = entry.name - py_enum = entry.name[len(prefix):] - - out += '\t\t.value(\"{}\", {}{})\n'.format(py_enum, ns, cpp_enum) - - out += '\t;\n\n' - - return {'controls': out, - 'vendors_class_def': '\n'.join(vendors_class_def), - 'vendors_defs': '\n'.join(vendor_defs)} - - -def fill_template(template, data): - template = open(template, 'rb').read() - template = template.decode('utf-8') - template = string.Template(template) - return template.substitute(data) + return ctrl def main(argv): + headers = { + 'controls': 'control_ids.h', + 'properties': 'property_ids.h', + } + # Parse command line arguments parser = argparse.ArgumentParser() parser.add_argument('--mode', '-m', type=str, required=True, @@ -96,27 +68,41 @@ def main(argv): help='Input file name.') args = parser.parse_args(argv[1:]) - if args.mode not in ['controls', 'properties']: + if not headers.get(args.mode): print(f'Invalid mode option "{args.mode}"', file=sys.stderr) return -1 - controls = {} + controls = [] + vendors = [] + for input in args.input: data = yaml.safe_load(open(input, 'rb').read()) + vendor = data['vendor'] - ctrls = data['controls'] - controls[vendor] = [Control(*ctrl.popitem(), vendor) for ctrl in ctrls] + if vendor != 'libcamera': + vendors.append(vendor) - data = generate_py(controls, args.mode) + for ctrl in data['controls']: + ctrl = Control(*ctrl.popitem(), vendor) + controls.append(extend_control(ctrl, args.mode)) - data = fill_template(args.template, data) + data = { + 'mode': args.mode, + 'header': headers[args.mode], + 'vendors': vendors, + 'controls': controls, + } + + env = jinja2.Environment() + template = env.from_string(open(args.template, 'r', encoding='utf-8').read()) + string = template.render(data) if args.output: - output = open(args.output, 'wb') - output.write(data.encode('utf-8')) + output = open(args.output, 'w', encoding='utf-8') + output.write(string) output.close() else: - sys.stdout.write(data) + sys.stdout.write(string) return 0 diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index 6ad2d7713e4d..596a203ca4cc 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -26,7 +26,7 @@ pycamera_sources = files([ 'py_transform.cpp', ]) -# Generate controls +# Generate controls and properties gen_py_controls_template = files('py_controls_generated.cpp.in') gen_py_controls = files('gen-py-controls.py') @@ -38,15 +38,11 @@ pycamera_sources += custom_target('py_gen_controls', '-t', gen_py_controls_template, '@INPUT@'], env : py_build_env) -# Generate properties - -gen_py_properties_template = files('py_properties_generated.cpp.in') - pycamera_sources += custom_target('py_gen_properties', input : properties_files, output : ['py_properties_generated.cpp'], command : [gen_py_controls, '--mode', 'properties', '-o', '@OUTPUT@', - '-t', gen_py_properties_template, '@INPUT@'], + '-t', gen_py_controls_template, '@INPUT@'], env : py_build_env) # Generate formats diff --git a/src/py/libcamera/py_controls_generated.cpp.in b/src/py/libcamera/py_controls_generated.cpp.in index 26d5a104f209..22a132d19ea9 100644 --- a/src/py/libcamera/py_controls_generated.cpp.in +++ b/src/py/libcamera/py_controls_generated.cpp.in @@ -2,12 +2,12 @@ /* * Copyright (C) 2022, Tomi Valkeinen * - * Python bindings - Auto-generated controls + * Python bindings - Auto-generated {{mode}} * * This file is auto-generated. Do not edit. */ -#include +#include #include @@ -15,16 +15,33 @@ namespace py = pybind11; -class PyControls +class Py{{mode|capitalize}} { }; -${vendors_class_def} - -void init_py_controls_generated(py::module& m) +{% for vendor in vendors -%} +class Py{{vendor|capitalize}}{{mode|capitalize}} { - auto controls = py::class_(m, "controls"); -${vendors_defs} +}; -${controls} +{% endfor -%} + +void init_py_{{mode}}_generated(py::module& m) +{ + auto {{mode}} = py::class_(m, "{{mode}}"); +{%- for vendor in vendors %} + auto {{vendor}} = py::class_({{mode}}, "{{vendor}}"); +{%- endfor %} + +{% for ctrl in controls %} + {{ctrl.klass}}.def_readonly_static("{{ctrl.name}}", static_cast(&libcamera::{{mode}}::{{ctrl.namespace}}{{ctrl.name}})); +{%- if ctrl.is_enum %} + + py::enum_({{ctrl.klass}}, "{{ctrl.name}}Enum") +{%- for enum in ctrl.enum_values %} + .value("{{enum.py_name}}", libcamera::{{mode}}::{{ctrl.namespace}}{{enum.name}}) +{%- endfor %} + ; +{%- endif %} +{% endfor -%} } diff --git a/src/py/libcamera/py_properties_generated.cpp.in b/src/py/libcamera/py_properties_generated.cpp.in deleted file mode 100644 index d28f1ab8b61a..000000000000 --- a/src/py/libcamera/py_properties_generated.cpp.in +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2022, Tomi Valkeinen - * - * Python bindings - Auto-generated properties - * - * This file is auto-generated. Do not edit. - */ - -#include - -#include - -#include "py_main.h" - -namespace py = pybind11; - -class PyProperties -{ -}; - -${vendors_class_def} - -void init_py_properties_generated(py::module& m) -{ - auto controls = py::class_(m, "properties"); -${vendors_defs} - -${controls} -}