diff options
Diffstat (limited to 'tools/libclang/CIndexer.cpp')
-rw-r--r-- | tools/libclang/CIndexer.cpp | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/tools/libclang/CIndexer.cpp b/tools/libclang/CIndexer.cpp index cdf6c61..992d76a 100644 --- a/tools/libclang/CIndexer.cpp +++ b/tools/libclang/CIndexer.cpp @@ -25,12 +25,17 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/System/Program.h" +#include "llvm/Support/Program.h" #include <cstdio> #include <vector> #include <sstream> +#ifdef __CYGWIN__ +#include <sys/cygwin.h> +#define LLVM_ON_WIN32 1 +#endif + #ifdef LLVM_ON_WIN32 #include <windows.h> #else @@ -39,12 +44,12 @@ using namespace clang; -const llvm::sys::Path& CIndexer::getClangPath() { +std::string CIndexer::getClangResourcesPath() { // Did we already compute the path? - if (!ClangPath.empty()) - return ClangPath; - - // Find the location where this library lives (libCIndex.dylib). + if (!ResourcesPath.empty()) + return ResourcesPath.str(); + + // Find the location where this library lives (libclang.dylib). #ifdef LLVM_ON_WIN32 MEMORY_BASIC_INFORMATION mbi; char path[MAX_PATH]; @@ -52,46 +57,32 @@ const llvm::sys::Path& CIndexer::getClangPath() { sizeof(mbi)); GetModuleFileNameA((HINSTANCE)mbi.AllocationBase, path, MAX_PATH); - llvm::sys::Path CIndexPath(path); +#ifdef __CYGWIN__ + char w32path[MAX_PATH]; + strcpy(w32path, path); + cygwin_conv_to_full_posix_path(w32path, path); +#endif - CIndexPath.eraseComponent(); - CIndexPath.appendComponent("clang"); - CIndexPath.appendSuffix("exe"); - CIndexPath.makeAbsolute(); + llvm::sys::Path LibClangPath(path); + LibClangPath.eraseComponent(); #else // This silly cast below avoids a C++ warning. Dl_info info; if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) == 0) assert(0 && "Call to dladdr() failed"); - - llvm::sys::Path CIndexPath(info.dli_fname); - + + llvm::sys::Path LibClangPath(info.dli_fname); + // We now have the CIndex directory, locate clang relative to it. - CIndexPath.eraseComponent(); - CIndexPath.appendComponent(".."); - CIndexPath.appendComponent("bin"); - CIndexPath.appendComponent("clang"); + LibClangPath.eraseComponent(); #endif + + LibClangPath.appendComponent("clang"); + LibClangPath.appendComponent(CLANG_VERSION_STRING); // Cache our result. - ClangPath = CIndexPath; - 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(); + ResourcesPath = LibClangPath; + return LibClangPath.str(); } static llvm::sys::Path GetTemporaryPath() { @@ -127,7 +118,8 @@ bool clang::RemapFiles(unsigned num_unsaved_files, return true; std::string ErrorInfo; - llvm::raw_fd_ostream OS(SavedFile.c_str(), ErrorInfo); + llvm::raw_fd_ostream OS(SavedFile.c_str(), ErrorInfo, + llvm::raw_fd_ostream::F_Binary); if (!ErrorInfo.empty()) return true; |