summaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorCharles Brunet <charles.brunet@optelgroup.com>2025-04-30 15:37:04 -0400
committerJussi Pakkanen <jussi.pakkanen@mailbox.org>2025-08-01 16:28:09 +0300
commit550cf5ebcc395dfa78bfc31ee2abc1550a9ed349 (patch)
treeef328adc2e2697e54549c9302d516f8abb35aa10 /mesonbuild
parentb2a266b5d9fe8dca1cdace5fddeba618fc5cace0 (diff)
downloadmeson-550cf5ebcc395dfa78bfc31ee2abc1550a9ed349.tar.gz
format: add --source-file-path argument for stdin
Fixes #14539. Otherwise, .editorconfig is read from current working directory, and there is no way to know what file name to filter to choose the right section of editor config.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/mformat.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/mesonbuild/mformat.py b/mesonbuild/mformat.py
index b9cdeb30c..2131ff7b3 100644
--- a/mesonbuild/mformat.py
+++ b/mesonbuild/mformat.py
@@ -837,7 +837,15 @@ class Formatter:
# See https://editorconfig.org/
config = EditorConfig()
- for p in source_file.resolve().parents:
+ if source_file == Path('STDIN'):
+ raise MesonException('Using editorconfig with stdin requires --source-file-path argument')
+
+ try:
+ source_file_path = source_file.resolve()
+ except FileNotFoundError:
+ raise MesonException(f'Unable to resolve path for "{source_file}"')
+
+ for p in source_file_path.parents:
editorconfig_file = p / '.editorconfig'
if not editorconfig_file.exists():
continue
@@ -956,6 +964,11 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
help='output file (implies having exactly one input)'
)
parser.add_argument(
+ '--source-file-path',
+ type=Path,
+ help='path to use, when reading from stdin'
+ )
+ parser.add_argument(
'sources',
nargs='*',
type=Path,
@@ -981,6 +994,10 @@ def run(options: argparse.Namespace) -> int:
raise MesonException('--recursive argument is not compatible with stdin input')
if options.inplace and from_stdin:
raise MesonException('--inplace argument is not compatible with stdin input')
+ if options.source_file_path and not from_stdin:
+ raise MesonException('--source-file-path argument is only compatible with stdin input')
+ if from_stdin and options.editor_config and not options.source_file_path:
+ raise MesonException('using --editor-config with stdin input requires --source-file-path argument')
sources: T.List[Path] = options.sources.copy() or [Path(build_filename)]
@@ -996,7 +1013,7 @@ def run(options: argparse.Namespace) -> int:
try:
if from_stdin:
- src_file = Path('STDIN') # used for error messages and introspection
+ src_file = options.source_file_path or Path('STDIN') # used for error messages and introspection
code = sys.stdin.read()
else:
code = src_file.read_text(encoding='utf-8')