diff options
| author | wrvsrx <wrvsrx@outlook.com> | 2025-01-23 12:46:27 +0800 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-01-31 08:53:35 -0800 |
| commit | c0da4a5a7430a84d677d64b17747a27ee838f58b (patch) | |
| tree | ddd7003f9f19f104198775e4ab38d8321ba2b9b1 | |
| parent | cb4ac15993db67084ab3b7f0ed8a3edb7a866bba (diff) | |
| download | meson-c0da4a5a7430a84d677d64b17747a27ee838f58b.tar.gz | |
mformat: try to detect meson.format in source files' parent directories
| -rw-r--r-- | mesonbuild/mformat.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/mesonbuild/mformat.py b/mesonbuild/mformat.py index bda89bf3f..92729a02c 100644 --- a/mesonbuild/mformat.py +++ b/mesonbuild/mformat.py @@ -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') @@ -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: |
