diff options
author | Sam McCall <sam.mccall@gmail.com> | 2018-09-14 12:24:09 +0000 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2018-09-14 12:24:09 +0000 |
commit | 9d3530bd4ebaa7dc02494db440026f87f2bb8bc4 (patch) | |
tree | 20f4c360c26fe3d07dfb5da30bac7f54764ac3fb /clang/lib/Tooling/JSONCompilationDatabase.cpp | |
parent | 2fcdf76eef8705d5813e1529bf97ca62805aeb39 (diff) | |
download | bcm5719-llvm-9d3530bd4ebaa7dc02494db440026f87f2bb8bc4.tar.gz bcm5719-llvm-9d3530bd4ebaa7dc02494db440026f87f2bb8bc4.zip |
[Tooling] JSONCompilationDatabasePlugin infers compile commands for missing files
Summary:
See the existing InterpolatingCompilationDatabase for details on how this works.
We've been using this in clangd for a while, the heuristics seem to work well.
Reviewers: bkramer
Subscribers: ilya-biryukov, ioeric, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51729
llvm-svn: 342228
Diffstat (limited to 'clang/lib/Tooling/JSONCompilationDatabase.cpp')
-rw-r--r-- | clang/lib/Tooling/JSONCompilationDatabase.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp b/clang/lib/Tooling/JSONCompilationDatabase.cpp index 2fa5fce279d..b0feaa229c1 100644 --- a/clang/lib/Tooling/JSONCompilationDatabase.cpp +++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp @@ -157,13 +157,16 @@ std::vector<std::string> unescapeCommandLine(JSONCommandLineSyntax Syntax, return parser.parse(); } +// This plugin locates a nearby compile_command.json file, and also infers +// compile commands for files not present in the database. class JSONCompilationDatabasePlugin : public CompilationDatabasePlugin { std::unique_ptr<CompilationDatabase> loadFromDirectory(StringRef Directory, std::string &ErrorMessage) override { SmallString<1024> JSONDatabasePath(Directory); llvm::sys::path::append(JSONDatabasePath, "compile_commands.json"); - return JSONCompilationDatabase::loadFromFile( + auto Base = JSONCompilationDatabase::loadFromFile( JSONDatabasePath, ErrorMessage, JSONCommandLineSyntax::AutoDetect); + return Base ? inferMissingCompileCommands(std::move(Base)) : nullptr; } }; |