From af600d4b905e2112f978a005b77f84b013e81703 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 5 Jan 2018 11:10:58 -0800 Subject: [PATCH] Recognize clang-4.0 as commands --- src/project.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/project.cc b/src/project.cc index c96c427f..f6057cff 100644 --- a/src/project.cc +++ b/src/project.cc @@ -109,17 +109,18 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( // as there may be non-compiler related commands beforehand, // ie, compiler schedular such as goma. This allows correct parsing for // command lines like "goma clang -c foo". + std::string::size_type dot; while (i < entry.args.size() && entry.args[i][0] != '-' && // Do not skip over main source filename NormalizePathWithTestOptOut(entry.args[i]) != result.filename && // There may be other filenames (e.g. more than one source filenames) - // preceding main source filename. - // We use a heuristic here. `.` may occur in both command names and - // source filenames. If `.` occurs in the last 4 bytes of - // entry.args[i], e.g. .c .cpp, We take it as a source filename. Others - // (like ./a/b/goma) are seen as commands. - (entry.args[i].rfind('.') == std::string::npos || - entry.args[i].rfind('.') + 4 < entry.args[i].size())) + // preceding main source filename. We use a heuristic here. `.` may + // occur in both command names and source filenames. If `.` occurs in + // the last 4 bytes of entry.args[i] and not followed by a digit, e.g. + // .c .cpp, We take it as a source filename. Others (like ./a/b/goma + // clang-4.0) are seen as commands. + ((dot = entry.args[i].rfind('.')) == std::string::npos || + dot + 4 < entry.args[i].size() || isdigit(entry.args[i][dot+1]))) ++i; // Include the compiler in the args. if (i > 0)