From 830d53c5a7484be007daac5bc93ba5e78f351e8a Mon Sep 17 00:00:00 2001 From: Charles Brunet Date: Thu, 16 Jan 2025 10:45:22 -0500 Subject: [PATCH] Detect files with trailing space On Windows, if you accidently add a space at the end of a file name, like `files('myfile.txt ')`, the file is not reported as missing, because of the normalization performed by the OS. However, ninja will reference it with the trailing space, and will fail because the file does not exist. See https://github.com/python/cpython/issues/115104 for reference. --- mesonbuild/interpreter/interpreter.py | 2 ++ mesonbuild/utils/universal.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 02a59e3986d5..d9de500ec90f 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -3179,6 +3179,8 @@ def source_strings_to_files(self, sources: T.List['SourceInputs'], strict: bool results: T.List['SourceOutputs'] = [] for s in sources: if isinstance(s, str): + if s.endswith(' '): + raise MesonException(f'{s!r} ends with a space. This is probably an error.') if not strict and s.startswith(self.environment.get_build_dir()): results.append(s) mlog.warning(f'Source item {s!r} cannot be converted to File object, because it is a generated file. ' diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py index 3ec23e1056d0..edc7e3a243be 100644 --- a/mesonbuild/utils/universal.py +++ b/mesonbuild/utils/universal.py @@ -398,7 +398,7 @@ def __repr__(self) -> str: @staticmethod @lru_cache(maxsize=None) - def from_source_file(source_root: str, subdir: str, fname: str) -> 'File': + def from_source_file(source_root: str, subdir: str, fname: str) -> File: if not os.path.isfile(os.path.join(source_root, subdir, fname)): raise MesonException(f'File {fname} does not exist.') return File(False, subdir, fname)