-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect missing files with trailing space on Windows #14145
Detect missing files with trailing space on Windows #14145
Conversation
78dcdaf
to
fd201e8
Compare
Is there ever a case where we would need to support spaces at the end of paths? IOW could we just check for it and error out if a file name ends in a space (as it is almost certainly a bug)? |
fd201e8
to
20d974c
Compare
Good idea. All my other attempts failed. This is probably simpler and safer to just detect trailing spaces. |
20d974c
to
4d8677b
Compare
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we mention why it's an error, e.g. that it breaks on Windows?
Are we worried about files passed as strings to a function that internally calls source_strings_to_files, but isn't the meson.build DSL function files()
itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure how many details should be put in the error message. Having a file name ending with a space will always be confusing, anyway.
Yes, that's probably a good idea to move the check to source_strings_to_files
, and it prevents adding a loop, which is a good thing.
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.
4d8677b
to
830d53c
Compare
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.One solution is to prepend the file name with
\\?\
to prevent the normalization of the name.See python/cpython#115104 for reference.