diff --git a/src/project.cc b/src/project.cc index cc590b99..5502ba67 100644 --- a/src/project.cc +++ b/src/project.cc @@ -86,6 +86,15 @@ bool IsCFile(const std::string& path) { Project::Entry GetCompilationEntryFromCompileCommandEntry( ProjectConfig* config, const CompileCommandsEntry& entry) { + auto cleanup_maybe_relative_path = [&](const std::string& path) { + // TODO/FIXME: Normalization will fail for paths that do not exist. Should + // it return an optional? + assert(!path.empty()); + if (path[0] == '/' || entry.directory.empty()) + return NormalizePathWithTestOptOut(path); + return NormalizePathWithTestOptOut(entry.directory + "/" + path); + }; + Project::Entry result; result.filename = NormalizePathWithTestOptOut(entry.file); @@ -108,15 +117,6 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry( for (; i < entry.args.size(); ++i) { std::string arg = entry.args[i]; - auto cleanup_maybe_relative_path = [&](const std::string& path) { - // TODO/FIXME: Normalization will fail for paths that do not exist. Should - // it return an optional? - assert(!path.empty()); - if (path[0] == '/' || entry.directory.empty()) - return NormalizePathWithTestOptOut(path); - return NormalizePathWithTestOptOut(entry.directory + "/" + path); - }; - // Do not include path. if (result.filename == cleanup_maybe_relative_path(arg)) continue;