Re: [PATCH v2 3/3] meson: add rule to run 'git clang-format'
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Jul 1, 2025, 15:12 UTC
- Message-ID
- <CAOLa=ZT6-Ea9iaNgYymmT6s5mjWk4i4RxZjcr+7G6HUbg4GdHw@mail.gmail.com>
- In-Reply-To
- <87bjq4qbxi.fsf@iotcl.com>
Toon Claes <toon@iotcl.com> writes:
Show 29 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> The Makefile has a 'style' rule to run 'git clang-format'. While Meson
>> intrinsically supports a 'clang-format' target, which can be run when
>> using the ninja backend by running 'ninja clang-format', this runs the
>> formatting on all existing files.
>>
>> Our Meson build doesn't yet support a way to run 'git clang-format',
>> which runs the formatter between the working directory and commit
>> provided. Add a new 'style' target to Meson to mimic the target in the
>> Makefile.
>>
>> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
>> ---
>> meson.build | 12 ++++++++++++
>> 1 file changed, 12 insertions(+)
>>
>> diff --git a/meson.build b/meson.build
>> index 7fea4a34d6..20ce0525a1 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -2144,6 +2144,18 @@ if headers_to_check.length() != 0 and compiler.get_argument_syntax() == 'gcc'
>> alias_target('check-headers', hdr_check)
>> endif
>>
>> +git_clang_format = find_program('git-clang-format', required: false)
>
> I think we should include `native: true` as well.
>Does it really matter here? I must admit I don't understand the repercussions here.
Show 8 quoted lines
>> +if git_clang_format.found()
>> + run_target('style',
>> + command: [
>> + 'git', 'clang-format',
>
> We should be using the `git_clang_format` variable here to ensure we
> call the tool we've found.
>Good point, let me add that.
Show 19 quoted lines
>> + '--style', 'file',
>> + '--diff',
>> + '--extensions', 'c,h'
>> + ]
>> + )
>> +endif
>> +
>> foreach key, value : {
>> 'DIFF': diff.full_path(),
>> 'GIT_SOURCE_DIR': meson.project_source_root(),
>>
>> --
>> 2.49.0
>>
>>
>
> --
> Cheers,
> Toon