Lift builtin-include-path logic out of ASTUnit::LoadFromCommandLine and fix CIndex to pass in the right directory (previously it was using the path to the main executable, which generally is wrong).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91238 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 16d2ea9..f6cb170 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -287,8 +287,7 @@
ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
const char **ArgEnd,
Diagnostic &Diags,
- const char *Argv0,
- void *MainAddr,
+ llvm::StringRef ResourceFilesPath,
bool OnlyLocalDecls,
bool UseBumpAllocator) {
llvm::SmallVector<const char *, 16> Args;
@@ -299,9 +298,8 @@
// also want to force it to use clang.
Args.push_back("-fsyntax-only");
- llvm::sys::Path Path = llvm::sys::Path::GetMainExecutable(Argv0, MainAddr);
- driver::Driver TheDriver(Path.getBasename(), Path.getDirname(),
- llvm::sys::getHostTriple(),
+ // FIXME: We shouldn't have to pass in the path info.
+ driver::Driver TheDriver("clang", "/", llvm::sys::getHostTriple(),
"a.out", false, Diags);
llvm::OwningPtr<driver::Compilation> C(
TheDriver.BuildCompilation(Args.size(), Args.data()));
@@ -329,11 +327,10 @@
(const char**) CCArgs.data()+CCArgs.size(),
Diags);
- // Infer the builtin include path if unspecified.
- if (CI.getHeaderSearchOpts().UseBuiltinIncludes &&
- CI.getHeaderSearchOpts().BuiltinIncludePath.empty())
- CI.getHeaderSearchOpts().BuiltinIncludePath =
- CompilerInvocation::GetBuiltinIncludePath(Argv0, MainAddr);
+ // Set the builtin include path.
+ llvm::sys::Path P(ResourceFilesPath);
+ P.appendComponent("include");
+ CI.getHeaderSearchOpts().BuiltinIncludePath = P.str();
CI.getFrontendOpts().DisableFree = UseBumpAllocator;
return LoadFromCompilerInvocation(CI, Diags, OnlyLocalDecls);