Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mformat: try to detect meson.format in parent directories #14178

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading