Recognize clang-4.0 as commands

This commit is contained in:
Fangrui Song 2018-01-05 11:10:58 -08:00
parent 0657de7ef9
commit af600d4b90

View File

@ -109,17 +109,18 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
// as there may be non-compiler related commands beforehand, // as there may be non-compiler related commands beforehand,
// ie, compiler schedular such as goma. This allows correct parsing for // ie, compiler schedular such as goma. This allows correct parsing for
// command lines like "goma clang -c foo". // command lines like "goma clang -c foo".
std::string::size_type dot;
while (i < entry.args.size() && entry.args[i][0] != '-' && while (i < entry.args.size() && entry.args[i][0] != '-' &&
// Do not skip over main source filename // Do not skip over main source filename
NormalizePathWithTestOptOut(entry.args[i]) != result.filename && NormalizePathWithTestOptOut(entry.args[i]) != result.filename &&
// There may be other filenames (e.g. more than one source filenames) // There may be other filenames (e.g. more than one source filenames)
// preceding main source filename. // preceding main source filename. We use a heuristic here. `.` may
// We use a heuristic here. `.` may occur in both command names and // occur in both command names and source filenames. If `.` occurs in
// source filenames. If `.` occurs in the last 4 bytes of // the last 4 bytes of entry.args[i] and not followed by a digit, e.g.
// entry.args[i], e.g. .c .cpp, We take it as a source filename. Others // .c .cpp, We take it as a source filename. Others (like ./a/b/goma
// (like ./a/b/goma) are seen as commands. // clang-4.0) are seen as commands.
(entry.args[i].rfind('.') == std::string::npos || ((dot = entry.args[i].rfind('.')) == std::string::npos ||
entry.args[i].rfind('.') + 4 < entry.args[i].size())) dot + 4 < entry.args[i].size() || isdigit(entry.args[i][dot+1])))
++i; ++i;
// Include the compiler in the args. // Include the compiler in the args.
if (i > 0) if (i > 0)