Skip to content

Commit 728cf42

Browse files
KarthikNayakgitster
authored andcommitted
meson: add rule to run 'git clang-format'
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bfbac98 commit 728cf42

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

meson.build

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,18 @@ if headers_to_check.length() != 0 and compiler.get_argument_syntax() == 'gcc'
21322132
alias_target('check-headers', hdr_check)
21332133
endif
21342134

2135+
clang_format = find_program('clang-format', required: false)
2136+
if clang_format.found()
2137+
run_target('style',
2138+
command: [
2139+
'git', 'clang-format',
2140+
'--style', 'file',
2141+
'--diff',
2142+
'--extensions', 'c,h'
2143+
]
2144+
)
2145+
endif
2146+
21352147
foreach key, value : {
21362148
'DIFF': diff.full_path(),
21372149
'GIT_SOURCE_DIR': meson.project_source_root(),

0 commit comments

Comments
 (0)