Skip to content
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

ExternalProgram: Ensure that the path has no forward slashes on Windows #13924

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion mesonbuild/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,14 @@ def _search(self, name: str, search_dirs: T.List[T.Optional[str]], exclude_paths
paths = OrderedSet(path.split(os.pathsep)).difference(exclude_paths)
path = os.pathsep.join(paths)
command = shutil.which(name, path=path)
if mesonlib.is_windows():
if command is not None and mesonlib.is_windows():
# Some programs like cmd.exe do not expect forward slashes in the first part
# of GetCommandLineW() (the part corresponding to argv[0]) and confuse the
# slash for a command-line switch.
#
# Example: "C:\Windows\System32/cmd.exe /C echo hello world" fails with
# "syntax error".
command = command.replace('/', '\\')
return self._search_windows_special_cases(name, command, exclude_paths)
# On UNIX-like platforms, shutil.which() is enough to find
# all executables whether in PATH or with an absolute path
Expand Down
Loading