From 399aea300f220ee3715cb22b32ac90bb57eca30d Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Thu, 1 Dec 2016 23:37:45 +0000 Subject: 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 llvm-svn: 288436 --- clang/lib/Tooling/JSONCompilationDatabase.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'clang/lib/Tooling/JSONCompilationDatabase.cpp') diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp b/clang/lib/Tooling/JSONCompilationDatabase.cpp index 152508f..738e610 100644 --- a/clang/lib/Tooling/JSONCompilationDatabase.cpp +++ b/clang/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> Command; llvm::yaml::ScalarNode *File = nullptr; + llvm::yaml::ScalarNode *Output = nullptr; for (auto& NextKeyValue : *Object) { llvm::yaml::ScalarNode *KeyString = dyn_cast(NextKeyValue.getKey()); @@ -331,6 +335,8 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { Command = std::vector(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); -- cgit v1.1