Skip to content

Commit 1022231

Browse files
committed
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.
1 parent b592dd7 commit 1022231

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

wrappers/native-wrapper.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ static inline void split_argv(const TCHAR *argv0, const TCHAR **dir_ptr, const T
138138
#ifdef _WIN32
139139
TCHAR module_path[8192];
140140
GetModuleFileName(NULL, module_path, sizeof(module_path)/sizeof(module_path[0]));
141+
// Try to resolve the given tool name into its long form. If the caller
142+
// called us with a short form executable name, e.g. C__~1.EXE instead of
143+
// c++.exe, we need to resolve the original name, so that the wrapper
144+
// can invoke the right tool with the right arguments.
145+
//
146+
// CMake/Ninja generates such tool names when the tools are located in
147+
// a path with spaces.
148+
TCHAR long_path[8192];
149+
int long_path_ret = GetLongPathName(module_path, long_path, sizeof(long_path)/sizeof(long_path[0]));
150+
if (long_path_ret > 0 && long_path_ret < sizeof(long_path)/sizeof(long_path[0])) {
151+
sep = _tcsrchrs(long_path, '/', '\\');
152+
if (sep)
153+
basename = _tcsdup(sep + 1);
154+
}
141155
TCHAR *sep2 = _tcsrchr(module_path, '\\');
142156
if (sep2) {
143157
sep2[1] = '\0';

0 commit comments

Comments
 (0)