Make CL mode detection fool-proof (#528)

This commit is contained in:
Boris Staletic 2018-03-18 22:52:01 +00:00 committed by Fangrui Song
parent 2d1c990f1a
commit 193d42ea78

View File

@ -160,9 +160,22 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
if (args.empty())
return result;
bool clang_cl = strstr(args[0].c_str(), "clang-cl") ||
strstr(args[0].c_str(), "cl.exe") ||
AnyStartsWith(args, "--driver-mode=cl");
std::string first_arg = args[0];
// Windows' filesystem is not case sensitive, so we compare only
// the lower case variant.
std::transform(first_arg.begin(), first_arg.end(), first_arg.begin(),
tolower);
bool clang_cl = strstr(first_arg.c_str(), "clang-cl") ||
strstr(first_arg.c_str(), "cl.exe");
// Clang only cares about the last --driver-mode flag, so the loop
// iterates in reverse to find the last one as soon as possible
// in case of multiple --driver-mode flags.
for (int i = args.size() - 1; i >= 0; --i) {
if (strstr(args[i].c_str(), "--dirver-mode=")) {
clang_cl = clang_cl || strstr(args[i].c_str(), "--driver-mode=cl");
break;
}
}
size_t i = 1;
// If |compilationDatabaseCommand| is specified, the external command provides