2018-03-15 05:05:51 +08:00
|
|
|
//===- JSONCompilationDatabase.cpp ----------------------------------------===//
|
2012-08-24 13:50:27 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the implementation of the JSONCompilationDatabase.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Tooling/JSONCompilationDatabase.h"
|
2018-03-15 05:05:51 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
2012-08-24 13:50:27 +08:00
|
|
|
#include "clang/Tooling/CompilationDatabase.h"
|
|
|
|
#include "clang/Tooling/CompilationDatabasePluginRegistry.h"
|
2018-03-15 05:05:51 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2012-08-24 13:50:27 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2018-03-15 05:05:51 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/Triple.h"
|
2016-08-19 03:31:48 +08:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2018-03-15 05:05:51 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
2016-08-19 03:31:48 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2018-03-15 05:05:51 +08:00
|
|
|
#include "llvm/Support/ErrorOr.h"
|
|
|
|
#include "llvm/Support/Host.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2012-08-24 13:50:27 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2016-08-19 03:31:48 +08:00
|
|
|
#include "llvm/Support/StringSaver.h"
|
2018-03-15 05:05:51 +08:00
|
|
|
#include "llvm/Support/YAMLParser.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2014-06-13 01:19:42 +08:00
|
|
|
#include <system_error>
|
2018-03-15 05:05:51 +08:00
|
|
|
#include <tuple>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2012-08-24 13:50:27 +08:00
|
|
|
|
2018-03-15 05:05:51 +08:00
|
|
|
using namespace clang;
|
|
|
|
using namespace tooling;
|
2012-08-24 13:50:27 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// \brief A parser for escaped strings of command line arguments.
|
|
|
|
///
|
|
|
|
/// Assumes \-escaping for quoted arguments (see the documentation of
|
|
|
|
/// unescapeCommandLine(...)).
|
|
|
|
class CommandLineArgumentParser {
|
|
|
|
public:
|
|
|
|
CommandLineArgumentParser(StringRef CommandLine)
|
|
|
|
: Input(CommandLine), Position(Input.begin()-1) {}
|
|
|
|
|
|
|
|
std::vector<std::string> parse() {
|
|
|
|
bool HasMoreInput = true;
|
|
|
|
while (HasMoreInput && nextNonWhitespace()) {
|
|
|
|
std::string Argument;
|
|
|
|
HasMoreInput = parseStringInto(Argument);
|
|
|
|
CommandLine.push_back(Argument);
|
|
|
|
}
|
|
|
|
return CommandLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// All private methods return true if there is more input available.
|
|
|
|
|
|
|
|
bool parseStringInto(std::string &String) {
|
|
|
|
do {
|
|
|
|
if (*Position == '"') {
|
2013-03-02 14:00:16 +08:00
|
|
|
if (!parseDoubleQuotedStringInto(String)) return false;
|
|
|
|
} else if (*Position == '\'') {
|
|
|
|
if (!parseSingleQuotedStringInto(String)) return false;
|
2012-08-24 13:50:27 +08:00
|
|
|
} else {
|
|
|
|
if (!parseFreeStringInto(String)) return false;
|
|
|
|
}
|
|
|
|
} while (*Position != ' ');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-02 14:00:16 +08:00
|
|
|
bool parseDoubleQuotedStringInto(std::string &String) {
|
2012-08-24 13:50:27 +08:00
|
|
|
if (!next()) return false;
|
|
|
|
while (*Position != '"') {
|
|
|
|
if (!skipEscapeCharacter()) return false;
|
|
|
|
String.push_back(*Position);
|
|
|
|
if (!next()) return false;
|
|
|
|
}
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
2013-03-02 14:00:16 +08:00
|
|
|
bool parseSingleQuotedStringInto(std::string &String) {
|
|
|
|
if (!next()) return false;
|
|
|
|
while (*Position != '\'') {
|
|
|
|
String.push_back(*Position);
|
|
|
|
if (!next()) return false;
|
|
|
|
}
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
2012-08-24 13:50:27 +08:00
|
|
|
bool parseFreeStringInto(std::string &String) {
|
|
|
|
do {
|
|
|
|
if (!skipEscapeCharacter()) return false;
|
|
|
|
String.push_back(*Position);
|
|
|
|
if (!next()) return false;
|
2013-03-02 14:00:16 +08:00
|
|
|
} while (*Position != ' ' && *Position != '"' && *Position != '\'');
|
2012-08-24 13:50:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool skipEscapeCharacter() {
|
|
|
|
if (*Position == '\\') {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nextNonWhitespace() {
|
|
|
|
do {
|
|
|
|
if (!next()) return false;
|
|
|
|
} while (*Position == ' ');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool next() {
|
|
|
|
++Position;
|
|
|
|
return Position != Input.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
const StringRef Input;
|
|
|
|
StringRef::iterator Position;
|
|
|
|
std::vector<std::string> CommandLine;
|
|
|
|
};
|
|
|
|
|
2016-08-19 03:31:48 +08:00
|
|
|
std::vector<std::string> unescapeCommandLine(JSONCommandLineSyntax Syntax,
|
|
|
|
StringRef EscapedCommandLine) {
|
|
|
|
if (Syntax == JSONCommandLineSyntax::AutoDetect) {
|
2016-08-19 03:42:00 +08:00
|
|
|
Syntax = JSONCommandLineSyntax::Gnu;
|
2016-08-19 03:31:48 +08:00
|
|
|
llvm::Triple Triple(llvm::sys::getProcessTriple());
|
|
|
|
if (Triple.getOS() == llvm::Triple::OSType::Win32) {
|
|
|
|
// Assume Windows command line parsing on Win32 unless the triple
|
2016-08-19 03:42:00 +08:00
|
|
|
// explicitly tells us otherwise.
|
2016-08-19 03:31:48 +08:00
|
|
|
if (!Triple.hasEnvironment() ||
|
|
|
|
Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC)
|
|
|
|
Syntax = JSONCommandLineSyntax::Windows;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Syntax == JSONCommandLineSyntax::Windows) {
|
|
|
|
llvm::BumpPtrAllocator Alloc;
|
|
|
|
llvm::StringSaver Saver(Alloc);
|
|
|
|
llvm::SmallVector<const char *, 64> T;
|
|
|
|
llvm::cl::TokenizeWindowsCommandLine(EscapedCommandLine, Saver, T);
|
|
|
|
std::vector<std::string> Result(T.begin(), T.end());
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
assert(Syntax == JSONCommandLineSyntax::Gnu);
|
2012-08-24 13:50:27 +08:00
|
|
|
CommandLineArgumentParser parser(EscapedCommandLine);
|
|
|
|
return parser.parse();
|
|
|
|
}
|
|
|
|
|
|
|
|
class JSONCompilationDatabasePlugin : public CompilationDatabasePlugin {
|
2014-08-09 00:06:15 +08:00
|
|
|
std::unique_ptr<CompilationDatabase>
|
|
|
|
loadFromDirectory(StringRef Directory, std::string &ErrorMessage) override {
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallString<1024> JSONDatabasePath(Directory);
|
2012-08-24 13:50:27 +08:00
|
|
|
llvm::sys::path::append(JSONDatabasePath, "compile_commands.json");
|
2017-05-05 22:07:23 +08:00
|
|
|
return JSONCompilationDatabase::loadFromFile(
|
|
|
|
JSONDatabasePath, ErrorMessage, JSONCommandLineSyntax::AutoDetect);
|
2012-08-24 13:50:27 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-15 05:05:51 +08:00
|
|
|
} // namespace
|
2013-07-01 14:34:58 +08:00
|
|
|
|
2012-08-24 13:50:27 +08:00
|
|
|
// Register the JSONCompilationDatabasePlugin with the
|
|
|
|
// CompilationDatabasePluginRegistry using this statically initialized variable.
|
|
|
|
static CompilationDatabasePluginRegistry::Add<JSONCompilationDatabasePlugin>
|
|
|
|
X("json-compilation-database", "Reads JSON formatted compilation databases");
|
|
|
|
|
2018-03-15 05:05:51 +08:00
|
|
|
namespace clang {
|
|
|
|
namespace tooling {
|
|
|
|
|
2012-08-24 13:50:27 +08:00
|
|
|
// This anchor is used to force the linker to link in the generated object file
|
|
|
|
// and thus register the JSONCompilationDatabasePlugin.
|
2012-08-24 18:39:28 +08:00
|
|
|
volatile int JSONAnchorSource = 0;
|
2012-08-24 13:50:27 +08:00
|
|
|
|
2018-03-15 05:05:51 +08:00
|
|
|
} // namespace tooling
|
|
|
|
} // namespace clang
|
|
|
|
|
2014-08-09 00:06:15 +08:00
|
|
|
std::unique_ptr<JSONCompilationDatabase>
|
2012-08-24 13:50:27 +08:00
|
|
|
JSONCompilationDatabase::loadFromFile(StringRef FilePath,
|
2016-08-19 03:31:48 +08:00
|
|
|
std::string &ErrorMessage,
|
|
|
|
JSONCommandLineSyntax Syntax) {
|
2014-07-07 01:43:24 +08:00
|
|
|
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> DatabaseBuffer =
|
|
|
|
llvm::MemoryBuffer::getFile(FilePath);
|
|
|
|
if (std::error_code Result = DatabaseBuffer.getError()) {
|
2012-08-24 13:50:27 +08:00
|
|
|
ErrorMessage = "Error while opening JSON database: " + Result.message();
|
2014-05-20 12:51:16 +08:00
|
|
|
return nullptr;
|
2012-08-24 13:50:27 +08:00
|
|
|
}
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<JSONCompilationDatabase> Database(
|
2016-08-19 03:31:48 +08:00
|
|
|
new JSONCompilationDatabase(std::move(*DatabaseBuffer), Syntax));
|
2012-08-24 13:50:27 +08:00
|
|
|
if (!Database->parse(ErrorMessage))
|
2014-05-20 12:51:16 +08:00
|
|
|
return nullptr;
|
2014-08-09 00:06:15 +08:00
|
|
|
return Database;
|
2012-08-24 13:50:27 +08:00
|
|
|
}
|
|
|
|
|
2014-08-09 00:06:15 +08:00
|
|
|
std::unique_ptr<JSONCompilationDatabase>
|
2012-08-24 13:50:27 +08:00
|
|
|
JSONCompilationDatabase::loadFromBuffer(StringRef DatabaseString,
|
2016-08-19 03:31:48 +08:00
|
|
|
std::string &ErrorMessage,
|
|
|
|
JSONCommandLineSyntax Syntax) {
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<llvm::MemoryBuffer> DatabaseBuffer(
|
2012-08-24 13:50:27 +08:00
|
|
|
llvm::MemoryBuffer::getMemBuffer(DatabaseString));
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<JSONCompilationDatabase> Database(
|
2016-08-19 03:31:48 +08:00
|
|
|
new JSONCompilationDatabase(std::move(DatabaseBuffer), Syntax));
|
2012-08-24 13:50:27 +08:00
|
|
|
if (!Database->parse(ErrorMessage))
|
2014-05-20 12:51:16 +08:00
|
|
|
return nullptr;
|
2014-08-09 00:06:15 +08:00
|
|
|
return Database;
|
2012-08-24 13:50:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<CompileCommand>
|
|
|
|
JSONCompilationDatabase::getCompileCommands(StringRef FilePath) const {
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallString<128> NativeFilePath;
|
2012-08-24 13:50:27 +08:00
|
|
|
llvm::sys::path::native(FilePath, NativeFilePath);
|
2013-11-27 13:22:15 +08:00
|
|
|
|
2012-10-09 00:08:15 +08:00
|
|
|
std::string Error;
|
|
|
|
llvm::raw_string_ostream ES(Error);
|
2015-03-18 18:17:07 +08:00
|
|
|
StringRef Match = MatchTrie.findEquivalent(NativeFilePath, ES);
|
2013-01-13 02:37:52 +08:00
|
|
|
if (Match.empty())
|
2018-03-15 05:05:51 +08:00
|
|
|
return {};
|
|
|
|
const auto CommandsRefI = IndexByFile.find(Match);
|
2012-08-24 13:50:27 +08:00
|
|
|
if (CommandsRefI == IndexByFile.end())
|
2018-03-15 05:05:51 +08:00
|
|
|
return {};
|
2012-08-24 13:50:27 +08:00
|
|
|
std::vector<CompileCommand> Commands;
|
2012-12-04 15:26:44 +08:00
|
|
|
getCommands(CommandsRefI->getValue(), Commands);
|
2012-08-24 13:50:27 +08:00
|
|
|
return Commands;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string>
|
|
|
|
JSONCompilationDatabase::getAllFiles() const {
|
|
|
|
std::vector<std::string> Result;
|
2018-03-15 05:05:51 +08:00
|
|
|
for (const auto &CommandRef : IndexByFile)
|
|
|
|
Result.push_back(CommandRef.first().str());
|
2012-08-24 13:50:27 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2012-12-04 15:26:44 +08:00
|
|
|
std::vector<CompileCommand>
|
|
|
|
JSONCompilationDatabase::getAllCompileCommands() const {
|
|
|
|
std::vector<CompileCommand> Commands;
|
2015-09-23 01:22:33 +08:00
|
|
|
getCommands(AllCommands, Commands);
|
2012-12-04 15:26:44 +08:00
|
|
|
return Commands;
|
|
|
|
}
|
|
|
|
|
2015-09-08 23:14:06 +08:00
|
|
|
static std::vector<std::string>
|
2016-08-19 03:31:48 +08:00
|
|
|
nodeToCommandLine(JSONCommandLineSyntax Syntax,
|
|
|
|
const std::vector<llvm::yaml::ScalarNode *> &Nodes) {
|
2015-09-08 23:14:06 +08:00
|
|
|
SmallString<1024> Storage;
|
2018-03-15 05:05:51 +08:00
|
|
|
if (Nodes.size() == 1)
|
2016-08-19 03:31:48 +08:00
|
|
|
return unescapeCommandLine(Syntax, Nodes[0]->getValue(Storage));
|
2015-09-08 23:14:06 +08:00
|
|
|
std::vector<std::string> Arguments;
|
2018-03-15 05:05:51 +08:00
|
|
|
for (const auto *Node : Nodes)
|
2015-09-08 23:14:06 +08:00
|
|
|
Arguments.push_back(Node->getValue(Storage));
|
|
|
|
return Arguments;
|
|
|
|
}
|
|
|
|
|
2012-12-04 15:26:44 +08:00
|
|
|
void JSONCompilationDatabase::getCommands(
|
2015-09-08 23:14:06 +08:00
|
|
|
ArrayRef<CompileCommandRef> CommandsRef,
|
|
|
|
std::vector<CompileCommand> &Commands) const {
|
2018-03-15 05:05:51 +08:00
|
|
|
for (const auto &CommandRef : CommandsRef) {
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallString<8> DirectoryStorage;
|
2015-09-12 04:43:05 +08:00
|
|
|
SmallString<32> FilenameStorage;
|
2016-12-02 07:37:45 +08:00
|
|
|
SmallString<32> OutputStorage;
|
2018-03-15 05:05:51 +08:00
|
|
|
auto Output = std::get<3>(CommandRef);
|
2015-09-12 04:43:05 +08:00
|
|
|
Commands.emplace_back(
|
2018-03-15 05:05:51 +08:00
|
|
|
std::get<0>(CommandRef)->getValue(DirectoryStorage),
|
|
|
|
std::get<1>(CommandRef)->getValue(FilenameStorage),
|
|
|
|
nodeToCommandLine(Syntax, std::get<2>(CommandRef)),
|
2016-12-02 07:37:45 +08:00
|
|
|
Output ? Output->getValue(OutputStorage) : "");
|
2012-12-04 15:26:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-24 13:50:27 +08:00
|
|
|
bool JSONCompilationDatabase::parse(std::string &ErrorMessage) {
|
|
|
|
llvm::yaml::document_iterator I = YAMLStream.begin();
|
|
|
|
if (I == YAMLStream.end()) {
|
|
|
|
ErrorMessage = "Error while parsing YAML.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
llvm::yaml::Node *Root = I->getRoot();
|
2014-05-20 12:51:16 +08:00
|
|
|
if (!Root) {
|
2012-08-24 13:50:27 +08:00
|
|
|
ErrorMessage = "Error while parsing YAML.";
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-15 05:05:51 +08:00
|
|
|
auto *Array = dyn_cast<llvm::yaml::SequenceNode>(Root);
|
2014-05-20 12:51:16 +08:00
|
|
|
if (!Array) {
|
2012-08-24 13:50:27 +08:00
|
|
|
ErrorMessage = "Expected array.";
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-15 05:05:51 +08:00
|
|
|
for (auto &NextObject : *Array) {
|
|
|
|
auto *Object = dyn_cast<llvm::yaml::MappingNode>(&NextObject);
|
2014-05-20 12:51:16 +08:00
|
|
|
if (!Object) {
|
2012-08-24 13:50:27 +08:00
|
|
|
ErrorMessage = "Expected object.";
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-20 12:51:16 +08:00
|
|
|
llvm::yaml::ScalarNode *Directory = nullptr;
|
2015-09-08 23:14:06 +08:00
|
|
|
llvm::Optional<std::vector<llvm::yaml::ScalarNode *>> Command;
|
2014-05-20 12:51:16 +08:00
|
|
|
llvm::yaml::ScalarNode *File = nullptr;
|
2016-12-02 07:37:45 +08:00
|
|
|
llvm::yaml::ScalarNode *Output = nullptr;
|
2015-08-14 17:55:36 +08:00
|
|
|
for (auto& NextKeyValue : *Object) {
|
2018-03-15 05:05:51 +08:00
|
|
|
auto *KeyString = dyn_cast<llvm::yaml::ScalarNode>(NextKeyValue.getKey());
|
2015-08-14 17:55:36 +08:00
|
|
|
if (!KeyString) {
|
|
|
|
ErrorMessage = "Expected strings as key.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
SmallString<10> KeyStorage;
|
|
|
|
StringRef KeyValue = KeyString->getValue(KeyStorage);
|
|
|
|
llvm::yaml::Node *Value = NextKeyValue.getValue();
|
2014-05-20 12:51:16 +08:00
|
|
|
if (!Value) {
|
2012-08-24 13:50:27 +08:00
|
|
|
ErrorMessage = "Expected value.";
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-15 05:05:51 +08:00
|
|
|
auto *ValueString = dyn_cast<llvm::yaml::ScalarNode>(Value);
|
|
|
|
auto *SequenceString = dyn_cast<llvm::yaml::SequenceNode>(Value);
|
2015-08-14 17:55:36 +08:00
|
|
|
if (KeyValue == "arguments" && !SequenceString) {
|
|
|
|
ErrorMessage = "Expected sequence as value.";
|
2012-08-24 13:50:27 +08:00
|
|
|
return false;
|
2015-08-14 17:55:36 +08:00
|
|
|
} else if (KeyValue != "arguments" && !ValueString) {
|
|
|
|
ErrorMessage = "Expected string as value.";
|
2012-08-24 13:50:27 +08:00
|
|
|
return false;
|
|
|
|
}
|
2015-08-14 17:55:36 +08:00
|
|
|
if (KeyValue == "directory") {
|
2012-08-24 13:50:27 +08:00
|
|
|
Directory = ValueString;
|
2015-08-14 17:55:36 +08:00
|
|
|
} else if (KeyValue == "arguments") {
|
2015-09-08 23:14:06 +08:00
|
|
|
Command = std::vector<llvm::yaml::ScalarNode *>();
|
|
|
|
for (auto &Argument : *SequenceString) {
|
2018-03-15 05:05:51 +08:00
|
|
|
auto *Scalar = dyn_cast<llvm::yaml::ScalarNode>(&Argument);
|
2015-09-08 23:14:06 +08:00
|
|
|
if (!Scalar) {
|
|
|
|
ErrorMessage = "Only strings are allowed in 'arguments'.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Command->push_back(Scalar);
|
2015-08-14 17:55:36 +08:00
|
|
|
}
|
|
|
|
} else if (KeyValue == "command") {
|
2015-09-08 23:14:06 +08:00
|
|
|
if (!Command)
|
|
|
|
Command = std::vector<llvm::yaml::ScalarNode *>(1, ValueString);
|
2015-08-14 17:55:36 +08:00
|
|
|
} else if (KeyValue == "file") {
|
2012-08-24 13:50:27 +08:00
|
|
|
File = ValueString;
|
2016-12-02 07:37:45 +08:00
|
|
|
} else if (KeyValue == "output") {
|
|
|
|
Output = ValueString;
|
2012-08-24 13:50:27 +08:00
|
|
|
} else {
|
|
|
|
ErrorMessage = ("Unknown key: \"" +
|
|
|
|
KeyString->getRawValue() + "\"").str();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!File) {
|
|
|
|
ErrorMessage = "Missing key: \"file\".";
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-08 23:14:06 +08:00
|
|
|
if (!Command) {
|
2015-08-14 17:55:36 +08:00
|
|
|
ErrorMessage = "Missing key: \"command\" or \"arguments\".";
|
2012-08-24 13:50:27 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!Directory) {
|
|
|
|
ErrorMessage = "Missing key: \"directory\".";
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallString<8> FileStorage;
|
2012-10-09 00:08:15 +08:00
|
|
|
StringRef FileName = File->getValue(FileStorage);
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallString<128> NativeFilePath;
|
2012-10-09 00:08:15 +08:00
|
|
|
if (llvm::sys::path::is_relative(FileName)) {
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallString<8> DirectoryStorage;
|
|
|
|
SmallString<128> AbsolutePath(
|
2012-10-09 00:08:15 +08:00
|
|
|
Directory->getValue(DirectoryStorage));
|
|
|
|
llvm::sys::path::append(AbsolutePath, FileName);
|
2015-03-18 18:17:07 +08:00
|
|
|
llvm::sys::path::native(AbsolutePath, NativeFilePath);
|
2012-10-09 00:08:15 +08:00
|
|
|
} else {
|
|
|
|
llvm::sys::path::native(FileName, NativeFilePath);
|
|
|
|
}
|
2016-12-02 07:37:45 +08:00
|
|
|
auto Cmd = CompileCommandRef(Directory, File, *Command, Output);
|
2015-09-23 01:22:33 +08:00
|
|
|
IndexByFile[NativeFilePath].push_back(Cmd);
|
|
|
|
AllCommands.push_back(Cmd);
|
2015-03-18 18:17:07 +08:00
|
|
|
MatchTrie.insert(NativeFilePath);
|
2012-08-24 13:50:27 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|