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.
This commit is contained in:
Martin Storsjö committed 2023-03-12 00:08:13 +02:00
1 parent b592dd734e
commit 1022231482
1 file changed
+14
+14
View File
@@ -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';