From 0b087421a732199fca4bde9ac08ee185730db22f Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Sun, 18 Mar 2018 22:52:01 +0000 Subject: [PATCH] Make CL mode detection fool-proof (#528) --- src/project.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/project.cc b/src/project.cc index a95efdf8..f8c21ccb 100644 --- a/src/project.cc +++ b/src/project.cc @@ -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