|
30 | 30 | // in the paths that are explicitly included by the user. |
31 | 31 |
|
32 | 32 | #include "CompileCommands.h" |
| 33 | +#include "Config.h" |
33 | 34 | #include "GlobalCompilationDatabase.h" |
34 | 35 | #include "support/Logger.h" |
35 | 36 | #include "support/Threading.h" |
@@ -401,22 +402,30 @@ extractSystemIncludesAndTarget(const DriverArgs &InputArgs, |
401 | 402 | if (!Info) |
402 | 403 | return std::nullopt; |
403 | 404 |
|
404 | | - // The built-in headers are tightly coupled to parser builtins. |
405 | | - // (These are clang's "resource dir", GCC's GCC_INCLUDE_DIR.) |
406 | | - // We should keep using clangd's versions, so exclude the queried builtins. |
407 | | - // They're not specially marked in the -v output, but we can get the path |
408 | | - // with `$DRIVER -print-file-name=include`. |
409 | | - if (auto BuiltinHeaders = |
410 | | - run({Driver, "-print-file-name=include"}, /*OutputIsStderr=*/false)) { |
411 | | - auto Path = llvm::StringRef(*BuiltinHeaders).trim(); |
412 | | - if (!Path.empty() && llvm::sys::path::is_absolute(Path)) { |
413 | | - auto Size = Info->SystemIncludes.size(); |
414 | | - llvm::erase(Info->SystemIncludes, Path); |
415 | | - vlog("System includes extractor: builtin headers {0} {1}", Path, |
416 | | - (Info->SystemIncludes.size() != Size) |
417 | | - ? "excluded" |
418 | | - : "not found in driver's response"); |
| 405 | + switch (Config::current().CompileFlags.BuiltinHeaders) { |
| 406 | + case Config::BuiltinHeaderPolicy::Clangd: { |
| 407 | + // The built-in headers are tightly coupled to parser builtins. |
| 408 | + // (These are clang's "resource dir", GCC's GCC_INCLUDE_DIR.) |
| 409 | + // We should keep using clangd's versions, so exclude the queried |
| 410 | + // builtins. They're not specially marked in the -v output, but we can |
| 411 | + // get the path with `$DRIVER -print-file-name=include`. |
| 412 | + if (auto BuiltinHeaders = run({Driver, "-print-file-name=include"}, |
| 413 | + /*OutputIsStderr=*/false)) { |
| 414 | + auto Path = llvm::StringRef(*BuiltinHeaders).trim(); |
| 415 | + if (!Path.empty() && llvm::sys::path::is_absolute(Path)) { |
| 416 | + auto Size = Info->SystemIncludes.size(); |
| 417 | + llvm::erase(Info->SystemIncludes, Path); |
| 418 | + vlog("System includes extractor: builtin headers {0} {1}", Path, |
| 419 | + (Info->SystemIncludes.size() != Size) |
| 420 | + ? "excluded" |
| 421 | + : "not found in driver's response"); |
| 422 | + } |
419 | 423 | } |
| 424 | + break; |
| 425 | + } |
| 426 | + case Config::BuiltinHeaderPolicy::QueryDriver: |
| 427 | + vlog("System includes extractor: Using builtin headers from query driver."); |
| 428 | + break; |
420 | 429 | } |
421 | 430 |
|
422 | 431 | log("System includes extractor: successfully executed {0}\n\tgot includes: " |
|
0 commit comments