summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Brunet <charles.brunet@optelgroup.com>2025-01-16 10:45:22 -0500
committerJussi Pakkanen <jpakkane@gmail.com>2025-01-28 23:22:44 +0200
commit57c5d00dcdd70bed47c9990dfc6a59026bed03f6 (patch)
treeab4533a6b851531f281e3d300ad10fd91d17d2bd
parentb55cef0c3bf047591ee9a3e9503c530cf726deab (diff)
downloadmeson-57c5d00dcdd70bed47c9990dfc6a59026bed03f6.tar.gz
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.
-rw-r--r--mesonbuild/interpreter/interpreter.py2
-rw-r--r--mesonbuild/utils/universal.py2
2 files changed, 3 insertions, 1 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index 6fa569555..66ea24cf3 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -3204,6 +3204,8 @@ class Interpreter(InterpreterBase, HoldableObject):
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 3ec23e105..edc7e3a24 100644
--- a/mesonbuild/utils/universal.py
+++ b/mesonbuild/utils/universal.py
@@ -398,7 +398,7 @@ class File(HoldableObject):
@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)