Skip to content

Commit

Permalink
mformat: try to detect meson.format in parent directories
Browse files Browse the repository at this point in the history
  • Loading branch information
wrvsrx committed Jan 23, 2025
1 parent 0b9baf5 commit 243f8e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions mesonbuild/mformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,12 @@ def run(options: argparse.Namespace) -> int:

sources: T.List[Path] = options.sources.copy() or [Path(build_filename)]
if not options.configuration:
default_config_path = sources[0].parent / 'meson.format'
if default_config_path.exists():
options.configuration = default_config_path
current_path = Path.cwd()
for parent in [current_path] + list(current_path.parents):
target = parent / 'meson.format'
if target.exists() and target.is_file():
options.configuration = target

formatter = Formatter(options.configuration, options.editor_config, options.recursive)

while sources:
Expand Down
3 changes: 2 additions & 1 deletion test cases/format/4 config/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
project('default format')

meson_cmd = find_program('meson')
meson_format = files('meson.format')
meson_files = {
'self' : files('meson.build'),
'comments' : files('crazy_comments.meson'),
Expand All @@ -14,6 +15,6 @@ foreach name, f : meson_files
test(
name,
meson_cmd,
args : [ 'format', '--check-only', f ],
args : [ 'format', '--check-only', f, '--configuration', meson_format ],
)
endforeach

0 comments on commit 243f8e4

Please sign in to comment.