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 830d53c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. '
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 830d53c

Please sign in to comment.