wrappers: Handle tools named [<target>-]llvm-<tool>

Normally, we'd split the string at the last dash. However if the
tool name is "llvm-<tool>", make sure to include "llvm-" in the
tool name part when splitting the executable name.

In llvm-wrapper, don't add a duplicate "llvm-" prefix for the tool
name in these cases.
This commit is contained in:
Martin Storsjö committed 2022-10-01 13:28:41 +03:00
1 parent 2f8b90b583
commit 087255e28a
2 files changed
+20 -2

No files matched your search

+5 -2
View File
@@ -21,8 +21,11 @@
int _tmain(int argc, TCHAR* argv[]) {
const TCHAR *dir;
const TCHAR *exe;
split_argv(argv[0], &dir, NULL, NULL, &exe);
TCHAR *exe_path = concat(dir, concat(_T("llvm-"), exe));
const TCHAR *basename, *target;
split_argv(argv[0], &dir, &basename, &target, &exe);
if (_tcsncmp(exe, _T("llvm-"), 5))
exe = concat(_T("llvm-"), exe);
TCHAR *exe_path = concat(dir, exe);
return run_final(exe_path, (const TCHAR *const *) argv);
}
+15
View File
@@ -154,6 +154,21 @@ static inline void split_argv(const TCHAR *argv0, const TCHAR **dir_ptr, const T
if (dash) {
*dash = '\0';
exe = dash + 1;
// Handle [<target>-]llvm-<tool> as exe=llvm-<tool>
TCHAR *dash2 = _tcsrchr(target, '-');
if (dash2 && !_tcscmp(dash2, _T("-llvm"))) {
// Found <target>-llvm-<tool>; move the llvm- prefix to
// exe. Convert the original dash which we overwrite with '\0'
// back into a dash and split the string at the preceding dash.
*dash = '-';
*dash2 = '\0';
exe = dash2 + 1;
} else if (!_tcscmp(target, _T("llvm"))) {
// Found llvm-<tool>; don't treat "llvm" as target but move
// it to the exe part.
exe = basename;
target = NULL;
}
} else {
target = NULL;
}