diff options
author | Joerg Sonnenberger <joerg@bec.de> | 2016-12-01 23:37:45 +0000 |
---|---|---|
committer | Joerg Sonnenberger <joerg@bec.de> | 2016-12-01 23:37:45 +0000 |
commit | 5ca7f4286d20192dff833f91865b10be0debd76d (patch) | |
tree | 0de09621560e788db5ce1b214a8d70f7a24088b4 /lib/Tooling | |
parent | bef1cdf7e4d1e313f0f8b4acff0b0ad4c1e03d6c (diff) |
Extend CompilationDatabase by a field for the output filename
In bigger projects like an Operating System, the same source code is
often compiled in slightly different ways. This could be the difference
between PIC and non-PIC code for static vs dynamic libraries, it could
also be the difference between size optimised versions of tools for
ramdisk images. At the moment, the compilation database has no way to
distinguish such cases. As first step, add a field in the JSON format
for it and process it accordingly.
Differential Revision: https://reviews.llvm.org/D27138
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288436 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling')
-rw-r--r-- | lib/Tooling/CompilationDatabase.cpp | 3 | ||||
-rw-r--r-- | lib/Tooling/JSONCompilationDatabase.cpp | 10 |
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/Tooling/CompilationDatabase.cpp b/lib/Tooling/CompilationDatabase.cpp index 01f62616fb..8ca0b2df70 100644 --- a/lib/Tooling/CompilationDatabase.cpp +++ b/lib/Tooling/CompilationDatabase.cpp @@ -300,7 +300,8 @@ FixedCompilationDatabase(Twine Directory, ArrayRef<std::string> CommandLine) { ToolCommandLine.insert(ToolCommandLine.end(), CommandLine.begin(), CommandLine.end()); CompileCommands.emplace_back(Directory, StringRef(), - std::move(ToolCommandLine)); + std::move(ToolCommandLine), + StringRef()); } std::vector<CompileCommand> diff --git a/lib/Tooling/JSONCompilationDatabase.cpp b/lib/Tooling/JSONCompilationDatabase.cpp index 152508fb7d..738e610ed9 100644 --- a/lib/Tooling/JSONCompilationDatabase.cpp +++ b/lib/Tooling/JSONCompilationDatabase.cpp @@ -257,10 +257,13 @@ void JSONCompilationDatabase::getCommands( for (int I = 0, E = CommandsRef.size(); I != E; ++I) { SmallString<8> DirectoryStorage; SmallString<32> FilenameStorage; + SmallString<32> OutputStorage; + auto Output = std::get<3>(CommandsRef[I]); Commands.emplace_back( std::get<0>(CommandsRef[I])->getValue(DirectoryStorage), std::get<1>(CommandsRef[I])->getValue(FilenameStorage), - nodeToCommandLine(Syntax, std::get<2>(CommandsRef[I]))); + nodeToCommandLine(Syntax, std::get<2>(CommandsRef[I])), + Output ? Output->getValue(OutputStorage) : ""); } } @@ -289,6 +292,7 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { llvm::yaml::ScalarNode *Directory = nullptr; llvm::Optional<std::vector<llvm::yaml::ScalarNode *>> Command; llvm::yaml::ScalarNode *File = nullptr; + llvm::yaml::ScalarNode *Output = nullptr; for (auto& NextKeyValue : *Object) { llvm::yaml::ScalarNode *KeyString = dyn_cast<llvm::yaml::ScalarNode>(NextKeyValue.getKey()); @@ -331,6 +335,8 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { Command = std::vector<llvm::yaml::ScalarNode *>(1, ValueString); } else if (KeyValue == "file") { File = ValueString; + } else if (KeyValue == "output") { + Output = ValueString; } else { ErrorMessage = ("Unknown key: \"" + KeyString->getRawValue() + "\"").str(); @@ -361,7 +367,7 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { } else { llvm::sys::path::native(FileName, NativeFilePath); } - auto Cmd = CompileCommandRef(Directory, File, *Command); + auto Cmd = CompileCommandRef(Directory, File, *Command, Output); IndexByFile[NativeFilePath].push_back(Cmd); AllCommands.push_back(Cmd); MatchTrie.insert(NativeFilePath); |