[libcamera-devel,04/23] utils: ipc: add generator script

Message ID 20200915142038.28757-5-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • IPA isolation implementation
Related show

Commit Message

Paul Elder Sept. 15, 2020, 2:20 p.m. UTC
We want to avoid changing our copy of mojo to make updates easier. Some
parameters in the mojo generator script needs to be changed though; add
a wrapper script that sets these parameters.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 utils/ipc/generate.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100755 utils/ipc/generate.py

Comments

Laurent Pinchart Sept. 16, 2020, 12:16 a.m. UTC | #1
Hi Paul,

Thank you for the patch.

On Tue, Sep 15, 2020 at 11:20:19PM +0900, Paul Elder wrote:
> We want to avoid changing our copy of mojo to make updates easier. Some
> parameters in the mojo generator script needs to be changed though; add
> a wrapper script that sets these parameters.
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> ---
>  utils/ipc/generate.py | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>  create mode 100755 utils/ipc/generate.py
> 
> diff --git a/utils/ipc/generate.py b/utils/ipc/generate.py
> new file mode 100755
> index 00000000..39160aa2
> --- /dev/null
> +++ b/utils/ipc/generate.py
> @@ -0,0 +1,17 @@
> +#!/usr/bin/env python3
> +
> +import argparse

This doesn't seem needed.

> +import os
> +import sys
> +import mojo.public.tools.bindings.mojom_bindings_generator as generator
> +
> +def _GetModulePath(path, output_dir):
> +  return os.path.join(output_dir, path.relative_path())
> +

Comments to explain what's going on with the next three lines would be useful.

> +generator._BUILTIN_GENERATORS = {'libcamera': 'mojom_libcamera_generator'}
> +generator._GetModulePath = _GetModulePath
> +sys.path.append(os.path.join(os.path.dirname(__file__), 'utils/ipc'))
> +
> +generator.main()
> +
> +#./bindings/mojom_bindings_generator.py generate -g libcamera --bytecode_path . ./raspberrypi.mojom

Is this line a leftover ?
Laurent Pinchart Sept. 16, 2020, 1:49 a.m. UTC | #2
On Wed, Sep 16, 2020 at 03:16:15AM +0300, Laurent Pinchart wrote:
> Hi Paul,
> 
> Thank you for the patch.
> 
> On Tue, Sep 15, 2020 at 11:20:19PM +0900, Paul Elder wrote:
> > We want to avoid changing our copy of mojo to make updates easier. Some
> > parameters in the mojo generator script needs to be changed though; add
> > a wrapper script that sets these parameters.
> > 
> > Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> > ---
> >  utils/ipc/generate.py | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> >  create mode 100755 utils/ipc/generate.py
> > 
> > diff --git a/utils/ipc/generate.py b/utils/ipc/generate.py
> > new file mode 100755
> > index 00000000..39160aa2
> > --- /dev/null
> > +++ b/utils/ipc/generate.py
> > @@ -0,0 +1,17 @@
> > +#!/usr/bin/env python3
> > +
> > +import argparse
> 
> This doesn't seem needed.
> 
> > +import os
> > +import sys
> > +import mojo.public.tools.bindings.mojom_bindings_generator as generator

This results in a __pycache__ directory being created in the source
tree, that will be an issue when building on Chrome OS. Python 3.8
supports an option PYTHONPYCACHEPREFIX ([1]) to store the .pyc files in
a mirror directory tree, which we should set to point to the build
directory. For earlier versions of Python, the best workaround is
possibly to set PYTHONDONTWRITEBYTECODE ([2]) to avoid generation of
.pyc files in the first place.

[1] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPYCACHEPREFIX
[2] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE

> > +
> > +def _GetModulePath(path, output_dir):
> > +  return os.path.join(output_dir, path.relative_path())
> > +
> 
> Comments to explain what's going on with the next three lines would be useful.
> 
> > +generator._BUILTIN_GENERATORS = {'libcamera': 'mojom_libcamera_generator'}
> > +generator._GetModulePath = _GetModulePath
> > +sys.path.append(os.path.join(os.path.dirname(__file__), 'utils/ipc'))
> > +
> > +generator.main()
> > +
> > +#./bindings/mojom_bindings_generator.py generate -g libcamera --bytecode_path . ./raspberrypi.mojom
> 
> Is this line a leftover ?

Patch

diff --git a/utils/ipc/generate.py b/utils/ipc/generate.py
new file mode 100755
index 00000000..39160aa2
--- /dev/null
+++ b/utils/ipc/generate.py
@@ -0,0 +1,17 @@ 
+#!/usr/bin/env python3
+
+import argparse
+import os
+import sys
+import mojo.public.tools.bindings.mojom_bindings_generator as generator
+
+def _GetModulePath(path, output_dir):
+  return os.path.join(output_dir, path.relative_path())
+
+generator._BUILTIN_GENERATORS = {'libcamera': 'mojom_libcamera_generator'}
+generator._GetModulePath = _GetModulePath
+sys.path.append(os.path.join(os.path.dirname(__file__), 'utils/ipc'))
+
+generator.main()
+
+#./bindings/mojom_bindings_generator.py generate -g libcamera --bytecode_path . ./raspberrypi.mojom