[RFC,v1,0/3] meson: Add `meson.format` file
mbox series

Message ID 20260202112511.640320-1-barnabas.pocze@ideasonboard.com
Headers show
Series
  • meson: Add `meson.format` file
Related show

Message

Barnabás Pőcze Feb. 2, 2026, 11:25 a.m. UTC
Since 1.5.0 the `format` subcommand is provided by meson for formatting
build files. So I propose to find a suitable set of options, reformat all
files, and then add it to checkstyle.py.

The reformatting of everything is not done here, but it is somewhat significant
with the proposed settings:

  $ meson format --recursive --inplace
  $ git diff --stat
  [...]
   54 files changed, 1420 insertions(+), 936 deletions(-)

Barnabás Pőcze (3):
  meson: Add `meson.format` file
  utils: checkstyle.py: Make custom dependency checks possible
  utils: checkstyle.py: Add `MesonFormatter`

 meson.format        |  2 ++
 utils/checkstyle.py | 42 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 meson.format

--
2.52.0

Comments

Kieran Bingham Feb. 2, 2026, 7:49 p.m. UTC | #1
Quoting Barnabás Pőcze (2026-02-02 11:25:08)
> Since 1.5.0 the `format` subcommand is provided by meson for formatting
> build files. So I propose to find a suitable set of options, reformat all
> files, and then add it to checkstyle.py.
> 
> The reformatting of everything is not done here, but it is somewhat significant
> with the proposed settings:
> 
>   $ meson format --recursive --inplace
>   $ git diff --stat
>   [...]
>    54 files changed, 1420 insertions(+), 936 deletions(-)

Very cool:

kbingham@charm:~/iob/libcamera$ git commit -m "TEST"
---------------------------------------------
52efc35eafb1257dff2b0c4bada2a3d9fcf79f75 TEST
---------------------------------------------
Commit title is missing prefix
No 'Signed-off-by' trailer matching author 'Kieran Bingham <kieran.bingham@ideasonboard.com>', see Documentation/contributing.rst
--- meson.build
+++ meson.build
@@ -1,14 +1,18 @@
 # SPDX-License-Identifier: CC0-1.0

-project('libcamera', 'c', 'cpp',
+project(
+    'libcamera',
+    'c',
+    'cpp',
     meson_version : '>= 1.0.1',
-      version : '0.7.0',
+    version : '0.7.0',
     default_options : [
         'werror=true',
         'warning_level=2',
         'cpp_std=c++17',
     ],
-    license : 'LGPL 2.1+')
+    license : 'LGPL 2.1+',
+)

 # Generate version information. The libcamera_git_version variable contains the
 # full version with build metadata (patch count and SHA1, e.g.
---
3 potential issues detected, please review

[meson 52efc35eafb1] TEST
 1 file changed, 1 insertion(+), 1 deletion(-)



There's probably lots we'll want to adapt to fit the formatter as time
goes by - but I like having more consistency supported by the checkstyle
so I think this is a good addition.



> 
> Barnabás Pőcze (3):
>   meson: Add `meson.format` file
>   utils: checkstyle.py: Make custom dependency checks possible
>   utils: checkstyle.py: Add `MesonFormatter`
> 
>  meson.format        |  2 ++
>  utils/checkstyle.py | 42 +++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 43 insertions(+), 1 deletion(-)
>  create mode 100644 meson.format
> 
> --
> 2.52.0
Laurent Pinchart Feb. 5, 2026, 11:52 p.m. UTC | #2
On Mon, Feb 02, 2026 at 07:49:19PM +0000, Kieran Bingham wrote:
> Quoting Barnabás Pőcze (2026-02-02 11:25:08)
> > Since 1.5.0 the `format` subcommand is provided by meson for formatting
> > build files. So I propose to find a suitable set of options, reformat all
> > files, and then add it to checkstyle.py.
> > 
> > The reformatting of everything is not done here, but it is somewhat significant
> > with the proposed settings:
> > 
> >   $ meson format --recursive --inplace
> >   $ git diff --stat
> >   [...]
> >    54 files changed, 1420 insertions(+), 936 deletions(-)
> 
> Very cool:
> 
> kbingham@charm:~/iob/libcamera$ git commit -m "TEST"
> ---------------------------------------------
> 52efc35eafb1257dff2b0c4bada2a3d9fcf79f75 TEST
> ---------------------------------------------
> Commit title is missing prefix
> No 'Signed-off-by' trailer matching author 'Kieran Bingham <kieran.bingham@ideasonboard.com>', see Documentation/contributing.rst
> --- meson.build
> +++ meson.build
> @@ -1,14 +1,18 @@
>  # SPDX-License-Identifier: CC0-1.0
> 
> -project('libcamera', 'c', 'cpp',
> +project(
> +    'libcamera',
> +    'c',
> +    'cpp',
>      meson_version : '>= 1.0.1',
> -      version : '0.7.0',
> +    version : '0.7.0',
>      default_options : [
>          'werror=true',
>          'warning_level=2',
>          'cpp_std=c++17',
>      ],
> -    license : 'LGPL 2.1+')
> +    license : 'LGPL 2.1+',
> +)
> 
>  # Generate version information. The libcamera_git_version variable contains the
>  # full version with build metadata (patch count and SHA1, e.g.
> ---
> 3 potential issues detected, please review
> 
> [meson 52efc35eafb1] TEST
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> There's probably lots we'll want to adapt to fit the formatter as time
> goes by - but I like having more consistency supported by the checkstyle
> so I think this is a good addition.

I'm not a huge fan of all the changes, but I suppose it makes more sense
than maintaining the style manually.

For instance, meson format produces

    custom_target(
        'documentation',
        command : [
            sphinx,
            '-D',
            release,
            '-q',
            '-W',
            '-b',
            'html',
            '-c',
            sphinx_conf_dir,
            meson.current_source_dir(),
            '@OUTPUT@',
        ],
        input : docs_sources,
        output : 'html',
        build_by_default : true,
        depends : [doxygen_public, doxygen_internal],
        install : true,
        install_dir : doc_install_dir,
        install_tag : 'doc',
    )

and it would be great if we could have

    custom_target(
        'documentation',
        command : [
            sphinx,
            '-D', release,
            '-q',
            '-W',
            '-b', 'html',
            '-c', sphinx_conf_dir,
            meson.current_source_dir(),
            '@OUTPUT@',
        ],
        input : docs_sources,
        output : 'html',
        build_by_default : true,
        depends : [doxygen_public, doxygen_internal],
        install : true,
        install_dir : doc_install_dir,
        install_tag : 'doc',
    )

but there's no way meson can know what sphinx arguments to group
together. I'll give up any hope on that :-)

Still, if there are meson format options we can tweak to get a bit close
to our current style, it would be nice.

> > Barnabás Pőcze (3):
> >   meson: Add `meson.format` file
> >   utils: checkstyle.py: Make custom dependency checks possible
> >   utils: checkstyle.py: Add `MesonFormatter`
> > 
> >  meson.format        |  2 ++
> >  utils/checkstyle.py | 42 +++++++++++++++++++++++++++++++++++++++++-
> >  2 files changed, 43 insertions(+), 1 deletion(-)
> >  create mode 100644 meson.format
Barnabás Pőcze Feb. 6, 2026, 8:52 a.m. UTC | #3
2026. 02. 06. 0:52 keltezéssel, Laurent Pinchart írta:
> On Mon, Feb 02, 2026 at 07:49:19PM +0000, Kieran Bingham wrote:
>> Quoting Barnabás Pőcze (2026-02-02 11:25:08)
>>> Since 1.5.0 the `format` subcommand is provided by meson for formatting
>>> build files. So I propose to find a suitable set of options, reformat all
>>> files, and then add it to checkstyle.py.
>>>
>>> The reformatting of everything is not done here, but it is somewhat significant
>>> with the proposed settings:
>>>
>>>    $ meson format --recursive --inplace
>>>    $ git diff --stat
>>>    [...]
>>>     54 files changed, 1420 insertions(+), 936 deletions(-)
>>
>> Very cool:
>>
>> kbingham@charm:~/iob/libcamera$ git commit -m "TEST"
>> ---------------------------------------------
>> 52efc35eafb1257dff2b0c4bada2a3d9fcf79f75 TEST
>> ---------------------------------------------
>> Commit title is missing prefix
>> No 'Signed-off-by' trailer matching author 'Kieran Bingham <kieran.bingham@ideasonboard.com>', see Documentation/contributing.rst
>> --- meson.build
>> +++ meson.build
>> @@ -1,14 +1,18 @@
>>   # SPDX-License-Identifier: CC0-1.0
>>
>> -project('libcamera', 'c', 'cpp',
>> +project(
>> +    'libcamera',
>> +    'c',
>> +    'cpp',
>>       meson_version : '>= 1.0.1',
>> -      version : '0.7.0',
>> +    version : '0.7.0',
>>       default_options : [
>>           'werror=true',
>>           'warning_level=2',
>>           'cpp_std=c++17',
>>       ],
>> -    license : 'LGPL 2.1+')
>> +    license : 'LGPL 2.1+',
>> +)
>>
>>   # Generate version information. The libcamera_git_version variable contains the
>>   # full version with build metadata (patch count and SHA1, e.g.
>> ---
>> 3 potential issues detected, please review
>>
>> [meson 52efc35eafb1] TEST
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> There's probably lots we'll want to adapt to fit the formatter as time
>> goes by - but I like having more consistency supported by the checkstyle
>> so I think this is a good addition.
> 
> I'm not a huge fan of all the changes, but I suppose it makes more sense
> than maintaining the style manually.
> 
> For instance, meson format produces
> 
>      custom_target(
>          'documentation',
>          command : [
>              sphinx,
>              '-D',
>              release,
>              '-q',
>              '-W',
>              '-b',
>              'html',
>              '-c',
>              sphinx_conf_dir,
>              meson.current_source_dir(),
>              '@OUTPUT@',
>          ],
>          input : docs_sources,
>          output : 'html',
>          build_by_default : true,
>          depends : [doxygen_public, doxygen_internal],
>          install : true,
>          install_dir : doc_install_dir,
>          install_tag : 'doc',
>      )
> 
> and it would be great if we could have
> 
>      custom_target(
>          'documentation',
>          command : [
>              sphinx,
>              '-D', release,
>              '-q',
>              '-W',
>              '-b', 'html',
>              '-c', sphinx_conf_dir,
>              meson.current_source_dir(),
>              '@OUTPUT@',
>          ],
>          input : docs_sources,
>          output : 'html',
>          build_by_default : true,
>          depends : [doxygen_public, doxygen_internal],
>          install : true,
>          install_dir : doc_install_dir,
>          install_tag : 'doc',
>      )
> 
> but there's no way meson can know what sphinx arguments to group
> together. I'll give up any hope on that :-)
> 
> Still, if there are meson format options we can tweak to get a bit close
> to our current style, it would be nice.

There is `group_arg_value`, but that only works if the option starts with `--`
and it apparently requires a string literal after the option as well:
https://github.com/mesonbuild/meson/blob/3beb5d14363e09cbd5444a1e36d20fe8dd53cfd9/mesonbuild/mformat.py#L702-L714

I tried it but it had little effect on the end result. It seems to me
that further meson development is needed, possibly something as simple
as an option to keep the array elements in one line with the other
items that were in the same line of the input.


> 
>>> Barnabás Pőcze (3):
>>>    meson: Add `meson.format` file
>>>    utils: checkstyle.py: Make custom dependency checks possible
>>>    utils: checkstyle.py: Add `MesonFormatter`
>>>
>>>   meson.format        |  2 ++
>>>   utils/checkstyle.py | 42 +++++++++++++++++++++++++++++++++++++++++-
>>>   2 files changed, 43 insertions(+), 1 deletion(-)
>>>   create mode 100644 meson.format
>
Laurent Pinchart Feb. 8, 2026, 11:50 p.m. UTC | #4
On Mon, Feb 02, 2026 at 12:25:08PM +0100, Barnabás Pőcze wrote:
> Since 1.5.0 the `format` subcommand is provided by meson for formatting
> build files. So I propose to find a suitable set of options, reformat all
> files, and then add it to checkstyle.py.
> 
> The reformatting of everything is not done here, but it is somewhat significant
> with the proposed settings:
> 
>   $ meson format --recursive --inplace
>   $ git diff --stat
>   [...]
>    54 files changed, 1420 insertions(+), 936 deletions(-)

I gave this a try today, with meson 1.9.2.

$ meson compile -C build/arm64-gcc/
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/bin/ninja -C build/arm64-gcc
ninja: Entering directory `build/arm64-gcc'
[114/114] Linking target test/utils

$ meson format --recursive --inplace

$ meson compile -C build/arm64-gcc/
[snip]
[2/199] Generating include/libcamera/formats_h with a custom command
FAILED: [code=1] include/libcamera/formats.h
../../utils/codegen/gen-formats.py -o include/libcamera/formats.h ../../include/libcamera/../../src/libcamera/formats.yaml ../../include/libcamera/../linux/drm_fourcc.h ../../include/libcamera/formats.h.in
Traceback (most recent call last):
  File "../../utils/codegen/gen-formats.py", line 107, in <module>
    sys.exit(main(sys.argv))
             ~~~~^^^^^^^^^^
  File "../../utils/codegen/gen-formats.py", line 98, in main
    'formats': generate_formats(formats, drm_fourcc),
               ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "../../utils/codegen/gen-formats.py", line 59, in generate_formats
    fourcc = drm_fourcc.fourcc(format['fourcc'])
  File "../../utils/codegen/gen-formats.py", line 47, in fourcc
    return self.formats[name]
           ~~~~~~~~~~~~^^^^^^
KeyError: 'DRM_FORMAT_R8'


This is caused by the following change:

 # formats.h
-formats_h = custom_target('formats_h',
-                          input : files(
-                              '../../src/libcamera/formats.yaml',
-                              'formats.h.in',
-                              '../linux/drm_fourcc.h'
-                          ),
-                          output : 'formats.h',
-                          command : [gen_formats, '-o', '@OUTPUT@', '@INPUT@'],
-                          install : true,
-                          install_dir : libcamera_headers_install_dir)
+formats_h = custom_target(
+    'formats_h',
+    input : files(
+        '../../src/libcamera/formats.yaml',
+        '../linux/drm_fourcc.h',
+        'formats.h.in',
+    ),
+    output : 'formats.h',
+    command : [gen_formats, '-o', '@OUTPUT@', '@INPUT@'],
+    install : true,
+    install_dir : libcamera_headers_install_dir,
+)
 libcamera_public_headers += formats_h


'meson format' modifies the order of the input files. A bug was filed in
September last year, and doesn't seem to have been fixed yet. Quite
worryingly, an associated pull request ([1]) has comments that seem to
imply they don't consider this to be a bug.

[1] https://github.com/mesonbuild/meson/pull/15005

> Barnabás Pőcze (3):
>   meson: Add `meson.format` file
>   utils: checkstyle.py: Make custom dependency checks possible
>   utils: checkstyle.py: Add `MesonFormatter`
> 
>  meson.format        |  2 ++
>  utils/checkstyle.py | 42 +++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 43 insertions(+), 1 deletion(-)
>  create mode 100644 meson.format
Barnabás Pőcze Feb. 9, 2026, 8:11 a.m. UTC | #5
2026. 02. 09. 0:50 keltezéssel, Laurent Pinchart írta:
> On Mon, Feb 02, 2026 at 12:25:08PM +0100, Barnabás Pőcze wrote:
>> Since 1.5.0 the `format` subcommand is provided by meson for formatting
>> build files. So I propose to find a suitable set of options, reformat all
>> files, and then add it to checkstyle.py.
>>
>> The reformatting of everything is not done here, but it is somewhat significant
>> with the proposed settings:
>>
>>    $ meson format --recursive --inplace
>>    $ git diff --stat
>>    [...]
>>     54 files changed, 1420 insertions(+), 936 deletions(-)
> 
> I gave this a try today, with meson 1.9.2.
> 
> $ meson compile -C build/arm64-gcc/
> INFO: autodetecting backend as ninja
> INFO: calculating backend command to run: /usr/bin/ninja -C build/arm64-gcc
> ninja: Entering directory `build/arm64-gcc'
> [114/114] Linking target test/utils
> 
> $ meson format --recursive --inplace
> 
> $ meson compile -C build/arm64-gcc/
> [snip]
> [2/199] Generating include/libcamera/formats_h with a custom command
> FAILED: [code=1] include/libcamera/formats.h
> ../../utils/codegen/gen-formats.py -o include/libcamera/formats.h ../../include/libcamera/../../src/libcamera/formats.yaml ../../include/libcamera/../linux/drm_fourcc.h ../../include/libcamera/formats.h.in
> Traceback (most recent call last):
>    File "../../utils/codegen/gen-formats.py", line 107, in <module>
>      sys.exit(main(sys.argv))
>               ~~~~^^^^^^^^^^
>    File "../../utils/codegen/gen-formats.py", line 98, in main
>      'formats': generate_formats(formats, drm_fourcc),
>                 ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
>    File "../../utils/codegen/gen-formats.py", line 59, in generate_formats
>      fourcc = drm_fourcc.fourcc(format['fourcc'])
>    File "../../utils/codegen/gen-formats.py", line 47, in fourcc
>      return self.formats[name]
>             ~~~~~~~~~~~~^^^^^^
> KeyError: 'DRM_FORMAT_R8'
> 
> 
> This is caused by the following change:
> 
>   # formats.h
> -formats_h = custom_target('formats_h',
> -                          input : files(
> -                              '../../src/libcamera/formats.yaml',
> -                              'formats.h.in',
> -                              '../linux/drm_fourcc.h'
> -                          ),
> -                          output : 'formats.h',
> -                          command : [gen_formats, '-o', '@OUTPUT@', '@INPUT@'],
> -                          install : true,
> -                          install_dir : libcamera_headers_install_dir)
> +formats_h = custom_target(
> +    'formats_h',
> +    input : files(
> +        '../../src/libcamera/formats.yaml',
> +        '../linux/drm_fourcc.h',
> +        'formats.h.in',
> +    ),
> +    output : 'formats.h',
> +    command : [gen_formats, '-o', '@OUTPUT@', '@INPUT@'],
> +    install : true,
> +    install_dir : libcamera_headers_install_dir,
> +)
>   libcamera_public_headers += formats_h
> 
> 
> 'meson format' modifies the order of the input files. A bug was filed in
> September last year, and doesn't seem to have been fixed yet. Quite
> worryingly, an associated pull request ([1]) has comments that seem to
> imply they don't consider this to be a bug.
> 
> [1] https://github.com/mesonbuild/meson/pull/15005

That's unfortunate. I also should have clarified that I naively did not test
reformatting the whole thing and this scenario has completely eluded me.
I suppose in this case the `files()` call can be removed, and then I assume
the order wouldn't be changed. I guess every `files()` must be considered
unordered if `sort_files=true` (default) in `meson.format`.


Regards,
Barnabás Pőcze

> 
>> Barnabás Pőcze (3):
>>    meson: Add `meson.format` file
>>    utils: checkstyle.py: Make custom dependency checks possible
>>    utils: checkstyle.py: Add `MesonFormatter`
>>
>>   meson.format        |  2 ++
>>   utils/checkstyle.py | 42 +++++++++++++++++++++++++++++++++++++++++-
>>   2 files changed, 43 insertions(+), 1 deletion(-)
>>   create mode 100644 meson.format
>
Laurent Pinchart Feb. 9, 2026, 9:09 a.m. UTC | #6
On Mon, Feb 09, 2026 at 09:11:34AM +0100, Barnabás Pőcze wrote:
> 2026. 02. 09. 0:50 keltezéssel, Laurent Pinchart írta:
> > On Mon, Feb 02, 2026 at 12:25:08PM +0100, Barnabás Pőcze wrote:
> >> Since 1.5.0 the `format` subcommand is provided by meson for formatting
> >> build files. So I propose to find a suitable set of options, reformat all
> >> files, and then add it to checkstyle.py.
> >>
> >> The reformatting of everything is not done here, but it is somewhat significant
> >> with the proposed settings:
> >>
> >>    $ meson format --recursive --inplace
> >>    $ git diff --stat
> >>    [...]
> >>     54 files changed, 1420 insertions(+), 936 deletions(-)
> > 
> > I gave this a try today, with meson 1.9.2.
> > 
> > $ meson compile -C build/arm64-gcc/
> > INFO: autodetecting backend as ninja
> > INFO: calculating backend command to run: /usr/bin/ninja -C build/arm64-gcc
> > ninja: Entering directory `build/arm64-gcc'
> > [114/114] Linking target test/utils
> > 
> > $ meson format --recursive --inplace
> > 
> > $ meson compile -C build/arm64-gcc/
> > [snip]
> > [2/199] Generating include/libcamera/formats_h with a custom command
> > FAILED: [code=1] include/libcamera/formats.h
> > ../../utils/codegen/gen-formats.py -o include/libcamera/formats.h ../../include/libcamera/../../src/libcamera/formats.yaml ../../include/libcamera/../linux/drm_fourcc.h ../../include/libcamera/formats.h.in
> > Traceback (most recent call last):
> >    File "../../utils/codegen/gen-formats.py", line 107, in <module>
> >      sys.exit(main(sys.argv))
> >               ~~~~^^^^^^^^^^
> >    File "../../utils/codegen/gen-formats.py", line 98, in main
> >      'formats': generate_formats(formats, drm_fourcc),
> >                 ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
> >    File "../../utils/codegen/gen-formats.py", line 59, in generate_formats
> >      fourcc = drm_fourcc.fourcc(format['fourcc'])
> >    File "../../utils/codegen/gen-formats.py", line 47, in fourcc
> >      return self.formats[name]
> >             ~~~~~~~~~~~~^^^^^^
> > KeyError: 'DRM_FORMAT_R8'
> > 
> > 
> > This is caused by the following change:
> > 
> >   # formats.h
> > -formats_h = custom_target('formats_h',
> > -                          input : files(
> > -                              '../../src/libcamera/formats.yaml',
> > -                              'formats.h.in',
> > -                              '../linux/drm_fourcc.h'
> > -                          ),
> > -                          output : 'formats.h',
> > -                          command : [gen_formats, '-o', '@OUTPUT@', '@INPUT@'],
> > -                          install : true,
> > -                          install_dir : libcamera_headers_install_dir)
> > +formats_h = custom_target(
> > +    'formats_h',
> > +    input : files(
> > +        '../../src/libcamera/formats.yaml',
> > +        '../linux/drm_fourcc.h',
> > +        'formats.h.in',
> > +    ),
> > +    output : 'formats.h',
> > +    command : [gen_formats, '-o', '@OUTPUT@', '@INPUT@'],
> > +    install : true,
> > +    install_dir : libcamera_headers_install_dir,
> > +)
> >   libcamera_public_headers += formats_h
> > 
> > 
> > 'meson format' modifies the order of the input files. A bug was filed in
> > September last year, and doesn't seem to have been fixed yet. Quite
> > worryingly, an associated pull request ([1]) has comments that seem to
> > imply they don't consider this to be a bug.
> > 
> > [1] https://github.com/mesonbuild/meson/pull/15005
> 
> That's unfortunate. I also should have clarified that I naively did not test
> reformatting the whole thing and this scenario has completely eluded me.
> I suppose in this case the `files()` call can be removed, and then I assume
> the order wouldn't be changed. I guess every `files()` must be considered
> unordered if `sort_files=true` (default) in `meson.format`.

When the order matters, the pull request referenced above advises doing

input_files = files('../../src/libcamera/formats.yaml')
input_files += files('../linux/drm_fourcc.h')
input_files += files('formats.h.in')

formats_h = custom_target(
    'formats.h',
    input : input_files,
    output : 'formats.h',
    ...
)

Frankly I don't think this is reasonable. The files() function has
guaranteed ordering since day 1, and still does. It's a key part of the
meson ABI. meson format should honour that and not sort files,
especially not by default.

> >> Barnabás Pőcze (3):
> >>    meson: Add `meson.format` file
> >>    utils: checkstyle.py: Make custom dependency checks possible
> >>    utils: checkstyle.py: Add `MesonFormatter`
> >>
> >>   meson.format        |  2 ++
> >>   utils/checkstyle.py | 42 +++++++++++++++++++++++++++++++++++++++++-
> >>   2 files changed, 43 insertions(+), 1 deletion(-)
> >>   create mode 100644 meson.format
Barnabás Pőcze Feb. 9, 2026, 12:46 p.m. UTC | #7
2026. 02. 09. 10:09 keltezéssel, Laurent Pinchart írta:
> On Mon, Feb 09, 2026 at 09:11:34AM +0100, Barnabás Pőcze wrote:
>> 2026. 02. 09. 0:50 keltezéssel, Laurent Pinchart írta:
>>> On Mon, Feb 02, 2026 at 12:25:08PM +0100, Barnabás Pőcze wrote:
>>>> Since 1.5.0 the `format` subcommand is provided by meson for formatting
>>>> build files. So I propose to find a suitable set of options, reformat all
>>>> files, and then add it to checkstyle.py.
>>>>
>>>> The reformatting of everything is not done here, but it is somewhat significant
>>>> with the proposed settings:
>>>>
>>>>     $ meson format --recursive --inplace
>>>>     $ git diff --stat
>>>>     [...]
>>>>      54 files changed, 1420 insertions(+), 936 deletions(-)
>>>
>>> I gave this a try today, with meson 1.9.2.
>>>
>>> $ meson compile -C build/arm64-gcc/
>>> INFO: autodetecting backend as ninja
>>> INFO: calculating backend command to run: /usr/bin/ninja -C build/arm64-gcc
>>> ninja: Entering directory `build/arm64-gcc'
>>> [114/114] Linking target test/utils
>>>
>>> $ meson format --recursive --inplace
>>>
>>> $ meson compile -C build/arm64-gcc/
>>> [snip]
>>> [2/199] Generating include/libcamera/formats_h with a custom command
>>> FAILED: [code=1] include/libcamera/formats.h
>>> ../../utils/codegen/gen-formats.py -o include/libcamera/formats.h ../../include/libcamera/../../src/libcamera/formats.yaml ../../include/libcamera/../linux/drm_fourcc.h ../../include/libcamera/formats.h.in
>>> Traceback (most recent call last):
>>>     File "../../utils/codegen/gen-formats.py", line 107, in <module>
>>>       sys.exit(main(sys.argv))
>>>                ~~~~^^^^^^^^^^
>>>     File "../../utils/codegen/gen-formats.py", line 98, in main
>>>       'formats': generate_formats(formats, drm_fourcc),
>>>                  ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
>>>     File "../../utils/codegen/gen-formats.py", line 59, in generate_formats
>>>       fourcc = drm_fourcc.fourcc(format['fourcc'])
>>>     File "../../utils/codegen/gen-formats.py", line 47, in fourcc
>>>       return self.formats[name]
>>>              ~~~~~~~~~~~~^^^^^^
>>> KeyError: 'DRM_FORMAT_R8'
>>>
>>>
>>> This is caused by the following change:
>>>
>>>    # formats.h
>>> -formats_h = custom_target('formats_h',
>>> -                          input : files(
>>> -                              '../../src/libcamera/formats.yaml',
>>> -                              'formats.h.in',
>>> -                              '../linux/drm_fourcc.h'
>>> -                          ),
>>> -                          output : 'formats.h',
>>> -                          command : [gen_formats, '-o', '@OUTPUT@', '@INPUT@'],
>>> -                          install : true,
>>> -                          install_dir : libcamera_headers_install_dir)
>>> +formats_h = custom_target(
>>> +    'formats_h',
>>> +    input : files(
>>> +        '../../src/libcamera/formats.yaml',
>>> +        '../linux/drm_fourcc.h',
>>> +        'formats.h.in',
>>> +    ),
>>> +    output : 'formats.h',
>>> +    command : [gen_formats, '-o', '@OUTPUT@', '@INPUT@'],
>>> +    install : true,
>>> +    install_dir : libcamera_headers_install_dir,
>>> +)
>>>    libcamera_public_headers += formats_h
>>>
>>>
>>> 'meson format' modifies the order of the input files. A bug was filed in
>>> September last year, and doesn't seem to have been fixed yet. Quite
>>> worryingly, an associated pull request ([1]) has comments that seem to
>>> imply they don't consider this to be a bug.
>>>
>>> [1] https://github.com/mesonbuild/meson/pull/15005
>>
>> That's unfortunate. I also should have clarified that I naively did not test
>> reformatting the whole thing and this scenario has completely eluded me.
>> I suppose in this case the `files()` call can be removed, and then I assume
>> the order wouldn't be changed. I guess every `files()` must be considered
>> unordered if `sort_files=true` (default) in `meson.format`.
> 
> When the order matters, the pull request referenced above advises doing
> 
> input_files = files('../../src/libcamera/formats.yaml')
> input_files += files('../linux/drm_fourcc.h')
> input_files += files('formats.h.in')
> 
> formats_h = custom_target(
>      'formats.h',
>      input : input_files,
>      output : 'formats.h',
>      ...
> )
> 
> Frankly I don't think this is reasonable. The files() function has
> guaranteed ordering since day 1, and still does. It's a key part of the
> meson ABI. meson format should honour that and not sort files,
> especially not by default.

I think in this specific scenario the arguably correct thing to do
is to remove the `files()` call. If one is not collecting files from
multiple subdirectories, then (usually) there is no need for it.


> 
>>>> Barnabás Pőcze (3):
>>>>     meson: Add `meson.format` file
>>>>     utils: checkstyle.py: Make custom dependency checks possible
>>>>     utils: checkstyle.py: Add `MesonFormatter`
>>>>
>>>>    meson.format        |  2 ++
>>>>    utils/checkstyle.py | 42 +++++++++++++++++++++++++++++++++++++++++-
>>>>    2 files changed, 43 insertions(+), 1 deletion(-)
>>>>    create mode 100644 meson.format
> 
> --
> Regards,
> 
> Laurent Pinchart