12
12
#include " lib/Support/Debug.hpp"
13
13
#include " lib/Support/Path.hpp"
14
14
#include " lib/Lib/ConfigImpl.hpp"
15
- #include " lib/Lib/AbsoluteCompilationDatabase .hpp"
15
+ #include " lib/Lib/MrDocsCompilationDatabase .hpp"
16
16
#include < fmt/format.h>
17
17
#include < clang/Basic/LangStandard.h>
18
18
#include < clang/Driver/Driver.h>
@@ -51,14 +51,20 @@ static
51
51
std::vector<std::string>
52
52
adjustCommandLine (
53
53
const std::vector<std::string>& cmdline,
54
- const std::vector<std::string>& additional_defines)
54
+ const std::vector<std::string>& additional_defines,
55
+ std::unordered_map<std::string, std::vector<std::string>> const & implicitIncludeDirectories)
55
56
{
56
57
std::vector<std::string> new_cmdline;
57
- std::vector<std::string> discarded_cmdline;
58
58
llvm::opt::InputArgList args;
59
59
StringRef driver_mode;
60
+ std::vector<std::string> systemIncludePaths;
61
+
60
62
if (! cmdline.empty ())
61
63
{
64
+ if (auto it = implicitIncludeDirectories.find (cmdline[0 ]); it != implicitIncludeDirectories.end ()) {
65
+ systemIncludePaths = it->second ;
66
+ }
67
+
62
68
std::vector<const char *> raw_cmdline;
63
69
raw_cmdline.reserve (cmdline.size ());
64
70
for (const auto & s : cmdline)
@@ -85,6 +91,9 @@ adjustCommandLine(
85
91
for (const auto & def : additional_defines)
86
92
new_cmdline.emplace_back (fmt::format (" -D{}" , def));
87
93
94
+ for (auto const & inc : systemIncludePaths)
95
+ new_cmdline.emplace_back (fmt::format (" -I{}" , inc));
96
+
88
97
for (unsigned idx = 1 ; idx < cmdline.size ();)
89
98
{
90
99
const unsigned old_idx = idx;
@@ -93,10 +102,6 @@ adjustCommandLine(
93
102
94
103
if (! arg)
95
104
{
96
- discarded_cmdline.insert (
97
- discarded_cmdline.end (),
98
- cmdline.begin () + old_idx,
99
- cmdline.begin () + idx);
100
105
continue ;
101
106
}
102
107
@@ -148,10 +153,6 @@ adjustCommandLine(
148
153
// driver::options::OPT__SLASH_Tc
149
154
))
150
155
{
151
- discarded_cmdline.insert (
152
- discarded_cmdline.end (),
153
- cmdline.begin () + old_idx,
154
- cmdline.begin () + idx);
155
156
continue ;
156
157
}
157
158
@@ -164,11 +165,12 @@ adjustCommandLine(
164
165
return new_cmdline;
165
166
}
166
167
167
- AbsoluteCompilationDatabase ::
168
- AbsoluteCompilationDatabase (
168
+ MrDocsCompilationDatabase ::
169
+ MrDocsCompilationDatabase (
169
170
llvm::StringRef workingDir,
170
171
CompilationDatabase const & inner,
171
- std::shared_ptr<const Config> config)
172
+ std::shared_ptr<const Config> config,
173
+ std::unordered_map<std::string, std::vector<std::string>> const & implicitIncludeDirectories)
172
174
{
173
175
namespace fs = llvm::sys::fs;
174
176
namespace path = llvm::sys::path;
@@ -187,7 +189,8 @@ AbsoluteCompilationDatabase(
187
189
cmd.Output = cmd0.Output ;
188
190
cmd.CommandLine = adjustCommandLine (
189
191
cmd0.CommandLine ,
190
- (*config_impl)->defines );
192
+ (*config_impl)->defines ,
193
+ implicitIncludeDirectories);
191
194
192
195
if (path::is_absolute (cmd0.Directory ))
193
196
{
@@ -227,7 +230,7 @@ AbsoluteCompilationDatabase(
227
230
}
228
231
229
232
std::vector<tooling::CompileCommand>
230
- AbsoluteCompilationDatabase ::
233
+ MrDocsCompilationDatabase ::
231
234
getCompileCommands (
232
235
llvm::StringRef FilePath) const
233
236
{
@@ -243,7 +246,7 @@ getCompileCommands(
243
246
}
244
247
245
248
std::vector<std::string>
246
- AbsoluteCompilationDatabase ::
249
+ MrDocsCompilationDatabase ::
247
250
getAllFiles () const
248
251
{
249
252
std::vector<std::string> allFiles;
@@ -254,7 +257,7 @@ getAllFiles() const
254
257
}
255
258
256
259
std::vector<tooling::CompileCommand>
257
- AbsoluteCompilationDatabase ::
260
+ MrDocsCompilationDatabase ::
258
261
getAllCompileCommands () const
259
262
{
260
263
return AllCommands_;
0 commit comments