Skip to content

Commit

Permalink
mformat: try to detect meson.format in source files' parent directories
Browse files Browse the repository at this point in the history
  • Loading branch information
wrvsrx authored and dcbaker committed Jan 31, 2025
1 parent cb4ac15 commit c0da4a5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions mesonbuild/mformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,14 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
help='meson source files'
)

def get_meson_format(sources: T.List[Path]) -> T.Optional[Path]:
for src_file in sources:
for parent in src_file.resolve().parents:
target = parent / 'meson.format'
if target.is_file():
return target
return None

def run(options: argparse.Namespace) -> int:
if options.output and len(options.sources) != 1:
raise MesonException('--output argument implies having exactly one source file')
Expand All @@ -974,10 +982,10 @@ def run(options: argparse.Namespace) -> int:
raise MesonException('--inplace argument is not compatible with stdin input')

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
options.configuration = get_meson_format(sources)

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

while sources:
Expand Down

0 comments on commit c0da4a5

Please sign in to comment.