Skip to content

Commit 2618a2e

Browse files
authored
Merge pull request #52 from jsonn/master
Improve command line handling
2 parents 51a889d + bd509b4 commit 2618a2e

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

generator/main.cpp

+23-7
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ static bool proceedCommand(std::vector<std::string> command, llvm::StringRef Dir
236236
// This code change all the paths to be absolute paths
237237
// FIXME: it is a bit fragile.
238238
bool previousIsDashI = false;
239+
bool previousNeedsMacro = false;
240+
bool hasNoStdInc = false;
239241
for(std::string &A : command) {
240242
if (previousIsDashI && !A.empty() && A[0] != '/') {
241243
A = Directory % "/" % A;
@@ -244,6 +246,16 @@ static bool proceedCommand(std::vector<std::string> command, llvm::StringRef Dir
244246
} else if (A == "-I") {
245247
previousIsDashI = true;
246248
continue;
249+
} else if (A == "-nostdinc") {
250+
hasNoStdInc = true;
251+
continue;
252+
} else if (A == "-U" || A == "-D") {
253+
previousNeedsMacro = true;
254+
continue;
255+
}
256+
if (previousNeedsMacro) {
257+
previousNeedsMacro = false;
258+
continue;
247259
}
248260
previousIsDashI = false;
249261
if (A.empty()) continue;
@@ -268,17 +280,21 @@ static bool proceedCommand(std::vector<std::string> command, llvm::StringRef Dir
268280
command = clang::tooling::getClangSyntaxOnlyAdjuster()(command, file);
269281
command = clang::tooling::getClangStripOutputAdjuster()(command, file);
270282
#endif
271-
command.push_back("-isystem");
272-
command.push_back("/builtins");
283+
if (!hasNoStdInc) {
284+
command.push_back("-isystem");
285+
command.push_back("/builtins");
286+
}
273287
command.push_back("-Qunused-arguments");
274288
command.push_back("-Wno-unknown-warning-option");
275289
clang::tooling::ToolInvocation Inv(command, new BrowserAction(WasInDatabase), FM);
276290

277-
// Map the builtins includes
278-
const EmbeddedFile *f = EmbeddedFiles;
279-
while (f->filename) {
280-
Inv.mapVirtualFile(f->filename, {f->content , f->size } );
281-
f++;
291+
if (!hasNoStdInc) {
292+
// Map the builtins includes
293+
const EmbeddedFile *f = EmbeddedFiles;
294+
while (f->filename) {
295+
Inv.mapVirtualFile(f->filename, {f->content , f->size } );
296+
f++;
297+
}
282298
}
283299
bool result = Inv.run();
284300
if (!result) {

0 commit comments

Comments
 (0)