-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcompilationDatabase.cxx
39 lines (32 loc) · 1.16 KB
/
compilationDatabase.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "application.hxx"
#include "json/json.h"
#include <fstream>
void Application::compilationDatabase (CompilationDatabaseArgs & args,
std::ostream & cout) {
// Change back to the original WD (in case `index` or `update` would have
// changed it)
chdir (cwd_);
Json::Value root;
Json::Reader reader;
std::ifstream json (args.fileName);
bool ret = reader.parse (json, root);
if ( !ret ) {
cout << "Failed to parse compilation database `" << args.fileName << "'\n"
<< reader.getFormattedErrorMessages();
}
auto transaction(storage_.beginTransaction());
for (unsigned int i=0 ; i<root.size() ; ++i) {
std::string fileName = root[i]["file"].asString();
std::string directory = root[i]["directory"].asString();
std::vector<std::string> clArgs;
std::istringstream command (root[i]["command"].asString());
std::string arg;
std::getline (command, arg, ' ');
do {
std::getline (command, arg, ' ');
clArgs.push_back (arg);
} while (! command.eof());
cout << " " << fileName << std::endl;
storage_.setCompileCommand (fileName, directory, clArgs);
}
}