[cfe-commits] r91238 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp tools/CIndex/CIndex.cpp tools/index-test/index-test.cpp
Daniel Dunbar
daniel at zuster.org
Sat Dec 12 19:46:13 PST 2009
Author: ddunbar
Date: Sat Dec 12 21:46:13 2009
New Revision: 91238
URL: http://llvm.org/viewvc/llvm-project?rev=91238&view=rev
Log:
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).
Modified:
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/tools/CIndex/CIndex.cpp
cfe/trunk/tools/index-test/index-test.cpp
Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=91238&r1=91237&r2=91238&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Sat Dec 12 21:46:13 2009
@@ -149,19 +149,14 @@
/// \param Diags - The diagnostics engine to use for reporting errors; its
/// lifetime is expected to extend past that of the returned ASTUnit.
///
- /// \param Argv0 - The program path (from argv[0]), for finding the builtin
- /// compiler path.
- ///
- /// \param MainAddr - The address of main (or some other function in the main
- /// executable), for finding the builtin compiler path.
+ /// \param ResourceFilesPath - The path to the compiler resource files.
//
// FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
// shouldn't need to specify them at construction time.
static ASTUnit *LoadFromCommandLine(const char **ArgBegin,
const char **ArgEnd,
Diagnostic &Diags,
- const char *Arg0,
- void *MainAddr,
+ llvm::StringRef ResourceFilesPath,
bool OnlyLocalDecls = false,
bool UseBumpAllocator = false);
};
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=91238&r1=91237&r2=91238&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Sat Dec 12 21:46:13 2009
@@ -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);
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=91238&r1=91237&r2=91238&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Sat Dec 12 21:46:13 2009
@@ -12,25 +12,26 @@
//===----------------------------------------------------------------------===//
#include "clang-c/Index.h"
-#include "clang/Index/Program.h"
-#include "clang/Index/Indexer.h"
-#include "clang/Index/ASTLocation.h"
-#include "clang/Index/Utils.h"
-#include "clang/Sema/CodeCompleteConsumer.h"
+#include "clang/AST/Decl.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/StmtVisitor.h"
-#include "clang/AST/Decl.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/Version.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Index/ASTLocation.h"
+#include "clang/Index/Indexer.h"
+#include "clang/Index/Program.h"
+#include "clang/Index/Utils.h"
+#include "clang/Sema/CodeCompleteConsumer.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/config.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
#include "llvm/System/Program.h"
-#include "llvm/Support/raw_ostream.h"
#include <cstdio>
#include <vector>
@@ -336,6 +337,9 @@
/// \brief Get the path of the clang binary.
const llvm::sys::Path& getClangPath();
+
+ /// \brief Get the path of the clang resource files.
+ std::string getClangResourcesPath();
};
const llvm::sys::Path& CIndexer::getClangPath() {
@@ -377,6 +381,22 @@
return ClangPath;
}
+std::string CIndexer::getClangResourcesPath() {
+ llvm::sys::Path P = getClangPath();
+
+ if (!P.empty()) {
+ P.eraseComponent(); // Remove /clang from foo/bin/clang
+ P.eraseComponent(); // Remove /bin from foo/bin
+
+ // Get foo/lib/clang/<version>/include
+ P.appendComponent("lib");
+ P.appendComponent("clang");
+ P.appendComponent(CLANG_VERSION_STRING);
+ }
+
+ return P.str();
+}
+
}
static SourceLocation getLocationFromCursor(CXCursor C,
@@ -508,12 +528,11 @@
Args.insert(Args.end(), command_line_args,
command_line_args + num_command_line_args);
- void *MainAddr = (void *)(uintptr_t)clang_createTranslationUnit;
-
unsigned NumErrors = CXXIdx->getDiags().getNumErrors();
llvm::OwningPtr<ASTUnit> Unit(
ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
- CXXIdx->getDiags(), "<clang>", MainAddr,
+ CXXIdx->getDiags(),
+ CXXIdx->getClangResourcesPath(),
CXXIdx->getOnlyLocalDecls(),
/* UseBumpAllocator = */ true));
Modified: cfe/trunk/tools/index-test/index-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/index-test/index-test.cpp?rev=91238&r1=91237&r2=91238&view=diff
==============================================================================
--- cfe/trunk/tools/index-test/index-test.cpp (original)
+++ cfe/trunk/tools/index-test/index-test.cpp Sat Dec 12 21:46:13 2009
@@ -223,9 +223,12 @@
for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i)
Args.push_back(CompilerArgs[i].c_str());
+ void *MainAddr = (void*) (intptr_t) CreateFromSource;
+ llvm::sys::Path ResourcesPath(
+ CompilerInvocation::GetBuiltinIncludePath(Argv0, MainAddr));
+ ResourcesPath.eraseComponent();
return ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
- Diags, Argv0,
- (void*) (intptr_t) CreateFromSource);
+ Diags, ResourcesPath.str());
}
int main(int argc, char **argv) {
More information about the cfe-commits
mailing list