Skip to content

Commit

Permalink
Detect files with trailing space
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bruchar1 committed Jan 20, 2025
1 parent 0564300 commit 4d8677b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,9 @@ def func_import(self, node: mparser.BaseNode, args: T.Tuple[str],
@typed_pos_args('files', varargs=str)
@noKwargs
def func_files(self, node: mparser.FunctionNode, args: T.Tuple[T.List[str]], kwargs: 'TYPE_kwargs') -> T.List[mesonlib.File]:
for filename in args[0]:
if filename.endswith(' '):
raise MesonException(f'{filename!r} ends with a space. This is probably an error.', file=node.filename, lineno=node.lineno, colno=node.colno)
return self.source_strings_to_files(args[0])

@noPosargs
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/utils/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4d8677b

Please sign in to comment.