[RFC,v1,3/3] utils: checkstyle.py: Add `MesonFormatter`
diff mbox series

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

Commit Message

Barnabás Pőcze Feb. 2, 2026, 11:25 a.m. UTC
Add support for diagnosing meson file style issues using `meson format`.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
This probably makes `MesonChecker` unnecessary.
---
 utils/checkstyle.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

--
2.52.0

Comments

Laurent Pinchart Feb. 5, 2026, 11:39 p.m. UTC | #1
On Mon, Feb 02, 2026 at 12:25:11PM +0100, Barnabás Pőcze wrote:
> Add support for diagnosing meson file style issues using `meson format`.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
> This probably makes `MesonChecker` unnecessary.

Ack.

> ---
>  utils/checkstyle.py | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 06b9f199a..2dfff0473 100755
> --- a/utils/checkstyle.py
> +++ b/utils/checkstyle.py
> @@ -919,6 +919,36 @@ class StripTrailingSpaceFormatter(Formatter):
>              lines[i] = lines[i].rstrip() + '\n'
>          return ''.join(lines)
> 
> +class MesonFormatter(Formatter):
> +    @staticmethod
> +    def _check_meson_version():
> +        # 1.5.0 for `meson format`
> +        # 1.7.0 for stdin input
> +        # 1.9.0 for `--source-file-path`
> +        VERSION_REQ = (1, 9, 0)
> +
> +        ret = subprocess.run(['meson', '--version'],
> +                             stdin=subprocess.DEVNULL,
> +                             stdout=subprocess.PIPE,
> +                             stderr=subprocess.PIPE)
> +
> +        ver = tuple(map(int, ret.stdout.decode('utf-8').split('.')))
> +        if ver < VERSION_REQ:
> +            return [
> +                CommitIssue(f'Missing meson {".".join(map(str, VERSION_REQ))} to run `meson format`')
> +            ]

1.9.0 is very recent. Won't this cause failures in CI ?

> +
> +
> +    dependencies = (('meson', _check_meson_version), )
> +    patterns = ('meson.build', )
> +
> +    @classmethod
> +    def format(cls, filename, data):
> +        ret = subprocess.run(['meson', 'format', '-',
> +                              '--source-file-path', filename],
> +                             input=data.encode('utf-8'), stdout=subprocess.PIPE)
> +        return ret.stdout.decode('utf-8')
> +
> 
>  # ------------------------------------------------------------------------------
>  # Style checking
Barnabás Pőcze Feb. 6, 2026, 8:55 a.m. UTC | #2
2026. 02. 06. 0:39 keltezéssel, Laurent Pinchart írta:
> On Mon, Feb 02, 2026 at 12:25:11PM +0100, Barnabás Pőcze wrote:
>> Add support for diagnosing meson file style issues using `meson format`.
>>
>> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
>> ---
>> This probably makes `MesonChecker` unnecessary.
> 
> Ack.
> 
>> ---
>>   utils/checkstyle.py | 30 ++++++++++++++++++++++++++++++
>>   1 file changed, 30 insertions(+)
>>
>> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
>> index 06b9f199a..2dfff0473 100755
>> --- a/utils/checkstyle.py
>> +++ b/utils/checkstyle.py
>> @@ -919,6 +919,36 @@ class StripTrailingSpaceFormatter(Formatter):
>>               lines[i] = lines[i].rstrip() + '\n'
>>           return ''.join(lines)
>>
>> +class MesonFormatter(Formatter):
>> +    @staticmethod
>> +    def _check_meson_version():
>> +        # 1.5.0 for `meson format`
>> +        # 1.7.0 for stdin input
>> +        # 1.9.0 for `--source-file-path`
>> +        VERSION_REQ = (1, 9, 0)
>> +
>> +        ret = subprocess.run(['meson', '--version'],
>> +                             stdin=subprocess.DEVNULL,
>> +                             stdout=subprocess.PIPE,
>> +                             stderr=subprocess.PIPE)
>> +
>> +        ver = tuple(map(int, ret.stdout.decode('utf-8').split('.')))
>> +        if ver < VERSION_REQ:
>> +            return [
>> +                CommitIssue(f'Missing meson {".".join(map(str, VERSION_REQ))} to run `meson format`')
>> +            ]
> 
> 1.9.0 is very recent. Won't this cause failures in CI ?

Yes indeed, debian 13 has 1.7.0. So this is very much a "very rfc".
I suppose `pip` could be used to get a newer version.


> 
>> +
>> +
>> +    dependencies = (('meson', _check_meson_version), )
>> +    patterns = ('meson.build', )
>> +
>> +    @classmethod
>> +    def format(cls, filename, data):
>> +        ret = subprocess.run(['meson', 'format', '-',
>> +                              '--source-file-path', filename],
>> +                             input=data.encode('utf-8'), stdout=subprocess.PIPE)
>> +        return ret.stdout.decode('utf-8')
>> +
>>
>>   # ------------------------------------------------------------------------------
>>   # Style checking
>
Laurent Pinchart Feb. 6, 2026, 9:51 a.m. UTC | #3
On Fri, Feb 06, 2026 at 09:55:20AM +0100, Barnabás Pőcze wrote:
> 2026. 02. 06. 0:39 keltezéssel, Laurent Pinchart írta:
> > On Mon, Feb 02, 2026 at 12:25:11PM +0100, Barnabás Pőcze wrote:
> >> Add support for diagnosing meson file style issues using `meson format`.
> >>
> >> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> >> ---
> >> This probably makes `MesonChecker` unnecessary.
> > 
> > Ack.
> > 
> >> ---
> >>   utils/checkstyle.py | 30 ++++++++++++++++++++++++++++++
> >>   1 file changed, 30 insertions(+)
> >>
> >> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> >> index 06b9f199a..2dfff0473 100755
> >> --- a/utils/checkstyle.py
> >> +++ b/utils/checkstyle.py
> >> @@ -919,6 +919,36 @@ class StripTrailingSpaceFormatter(Formatter):
> >>               lines[i] = lines[i].rstrip() + '\n'
> >>           return ''.join(lines)
> >>
> >> +class MesonFormatter(Formatter):
> >> +    @staticmethod
> >> +    def _check_meson_version():
> >> +        # 1.5.0 for `meson format`
> >> +        # 1.7.0 for stdin input
> >> +        # 1.9.0 for `--source-file-path`
> >> +        VERSION_REQ = (1, 9, 0)
> >> +
> >> +        ret = subprocess.run(['meson', '--version'],
> >> +                             stdin=subprocess.DEVNULL,
> >> +                             stdout=subprocess.PIPE,
> >> +                             stderr=subprocess.PIPE)
> >> +
> >> +        ver = tuple(map(int, ret.stdout.decode('utf-8').split('.')))
> >> +        if ver < VERSION_REQ:
> >> +            return [
> >> +                CommitIssue(f'Missing meson {".".join(map(str, VERSION_REQ))} to run `meson format`')
> >> +            ]
> > 
> > 1.9.0 is very recent. Won't this cause failures in CI ?
> 
> Yes indeed, debian 13 has 1.7.0. So this is very much a "very rfc".
> I suppose `pip` could be used to get a newer version.

Possibly, but I'm also a bit worried about the impact on developers.
Experience has shown that people who were forced to install a newer
meson version through pip because their distribution was lagging often
also kept the meson system package, resulting in problems and bug
reports.

We're not forcing users to support meson format, as far as I understand
this flags an issue but doesn't prevent checkstyle from running, so I
suppose this could be OK, but I wonder if we shouldn't start by
silently ignoring meson format if meson is too old, and only later flag
an issue once meson 1.9.0 will be more widely available ?

> >> +
> >> +
> >> +    dependencies = (('meson', _check_meson_version), )
> >> +    patterns = ('meson.build', )
> >> +
> >> +    @classmethod
> >> +    def format(cls, filename, data):
> >> +        ret = subprocess.run(['meson', 'format', '-',
> >> +                              '--source-file-path', filename],
> >> +                             input=data.encode('utf-8'), stdout=subprocess.PIPE)
> >> +        return ret.stdout.decode('utf-8')
> >> +
> >>
> >>   # ------------------------------------------------------------------------------
> >>   # Style checking

Patch
diff mbox series

diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 06b9f199a..2dfff0473 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -919,6 +919,36 @@  class StripTrailingSpaceFormatter(Formatter):
             lines[i] = lines[i].rstrip() + '\n'
         return ''.join(lines)

+class MesonFormatter(Formatter):
+    @staticmethod
+    def _check_meson_version():
+        # 1.5.0 for `meson format`
+        # 1.7.0 for stdin input
+        # 1.9.0 for `--source-file-path`
+        VERSION_REQ = (1, 9, 0)
+
+        ret = subprocess.run(['meson', '--version'],
+                             stdin=subprocess.DEVNULL,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE)
+
+        ver = tuple(map(int, ret.stdout.decode('utf-8').split('.')))
+        if ver < VERSION_REQ:
+            return [
+                CommitIssue(f'Missing meson {".".join(map(str, VERSION_REQ))} to run `meson format`')
+            ]
+
+
+    dependencies = (('meson', _check_meson_version), )
+    patterns = ('meson.build', )
+
+    @classmethod
+    def format(cls, filename, data):
+        ret = subprocess.run(['meson', 'format', '-',
+                              '--source-file-path', filename],
+                             input=data.encode('utf-8'), stdout=subprocess.PIPE)
+        return ret.stdout.decode('utf-8')
+

 # ------------------------------------------------------------------------------
 # Style checking