Skip to content

Commit 20d974c

Browse files
committed
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 python/cpython#115104 for reference.
1 parent 0564300 commit 20d974c

File tree

5 files changed

+7
-4
lines changed

5 files changed

+7
-4
lines changed

mesonbuild/interpreter/interpreter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,9 @@ def func_import(self, node: mparser.BaseNode, args: T.Tuple[str],
664664
@typed_pos_args('files', varargs=str)
665665
@noKwargs
666666
def func_files(self, node: mparser.FunctionNode, args: T.Tuple[T.List[str]], kwargs: 'TYPE_kwargs') -> T.List[mesonlib.File]:
667+
for filename in args[0]:
668+
if filename.endswith(' '):
669+
raise MesonException(f'{filename!r} ends with a space. This is probably an error.', file=node.filename, lineno=node.lineno, colno=node.colno)
667670
return self.source_strings_to_files(args[0])
668671

669672
@noPosargs

mesonbuild/utils/universal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def __repr__(self) -> str:
398398

399399
@staticmethod
400400
@lru_cache(maxsize=None)
401-
def from_source_file(source_root: str, subdir: str, fname: str) -> 'File':
401+
def from_source_file(source_root: str, subdir: str, fname: str) -> File:
402402
if not os.path.isfile(os.path.join(source_root, subdir, fname)):
403403
raise MesonException(f'File {fname} does not exist.')
404404
return File(False, subdir, fname)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stdout": [
33
{
4-
"line": "test cases/failing/2 missing file/meson.build:3:0: ERROR: File missing.c does not exist."
4+
"line": "test cases/failing/2 missing file/meson.build:3:0: ERROR: File 'missing.c' does not exist."
55
}
66
]
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stdout": [
33
{
4-
"line": "test cases/failing/65 skip only subdir/meson.build:8:0: ERROR: File main.cpp does not exist."
4+
"line": "test cases/failing/65 skip only subdir/meson.build:8:0: ERROR: File 'main.cpp' does not exist."
55
}
66
]
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stdout": [
33
{
4-
"line": "test cases/failing/9 missing extra file/meson.build:3:0: ERROR: File missing.txt does not exist."
4+
"line": "test cases/failing/9 missing extra file/meson.build:3:0: ERROR: File 'missing.txt' does not exist."
55
}
66
]
77
}

0 commit comments

Comments
 (0)