From 1022231482395a32d24dd3a2084c5474b0bbb0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 10 Mar 2023 16:35:50 +0200 Subject: [PATCH] wrappers: Try to resolve short form 8.3 file names into long form This allows the wrappers to invoke the right tool with the right options, even when the wrapper was invoked with an obfuscated short form file name. This happens e.g. when CMake/Ninja invokes the tools from a path that contains spaces. --- wrappers/native-wrapper.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wrappers/native-wrapper.h b/wrappers/native-wrapper.h index 0af9519..72bbcf9 100644 --- a/wrappers/native-wrapper.h +++ b/wrappers/native-wrapper.h @@ -138,6 +138,20 @@ static inline void split_argv(const TCHAR *argv0, const TCHAR **dir_ptr, const T #ifdef _WIN32 TCHAR module_path[8192]; GetModuleFileName(NULL, module_path, sizeof(module_path)/sizeof(module_path[0])); + // Try to resolve the given tool name into its long form. If the caller + // called us with a short form executable name, e.g. C__~1.EXE instead of + // c++.exe, we need to resolve the original name, so that the wrapper + // can invoke the right tool with the right arguments. + // + // CMake/Ninja generates such tool names when the tools are located in + // a path with spaces. + TCHAR long_path[8192]; + int long_path_ret = GetLongPathName(module_path, long_path, sizeof(long_path)/sizeof(long_path[0])); + if (long_path_ret > 0 && long_path_ret < sizeof(long_path)/sizeof(long_path[0])) { + sep = _tcsrchrs(long_path, '/', '\\'); + if (sep) + basename = _tcsdup(sep + 1); + } TCHAR *sep2 = _tcsrchr(module_path, '\\'); if (sep2) { sep2[1] = '\0';