mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-12 23:09:45 +03:00
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 .pyc files 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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
36 lines
1.3 KiB
Python
Executable file
36 lines
1.3 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
# Copyright (C) 2020, Google Inc.
|
|
#
|
|
# Author: Paul Elder <paul.elder@ideasonboard.com>
|
|
#
|
|
# Run mojo code generator for generating libcamera IPC files
|
|
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, f'{os.path.dirname(__file__)}/mojo/public/tools/bindings')
|
|
|
|
import mojo.public.tools.bindings.mojom_bindings_generator as generator
|
|
|
|
def _GetModulePath(path, output_dir):
|
|
return os.path.join(output_dir, path.relative_path())
|
|
|
|
|
|
# Disable the attribute checker to support our custom attributes. Ideally we
|
|
# should add the attributes to the list of allowed attributes in
|
|
# utils/ipc/mojo/public/tools/bindings/checks/mojom_attributes_check.py, but
|
|
# we're trying hard to use the upstream mojom as-is.
|
|
if hasattr(generator, '_BUILTIN_CHECKS'):
|
|
del generator._BUILTIN_CHECKS['attributes']
|
|
|
|
# Override the mojo code generator's generator list to only contain our
|
|
# libcamera generator
|
|
generator._BUILTIN_GENERATORS = {'libcamera': 'mojom_libcamera_generator'}
|
|
|
|
# Override the mojo code generator's _GetModulePath method to not add
|
|
# the '-module' suffix when searching for mojo modules, so that we can
|
|
# pass the path to the mojom module without having to trim the '-module' suffix
|
|
generator._GetModulePath = _GetModulePath
|
|
|
|
generator.main()
|