From 389db16c63eec6ecfa9b235155252d8da766e94e Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 3 Nov 2010 22:45:23 +0000 Subject: Implement -working-directory. When -working-directory is passed in command line, file paths are resolved relative to the specified directory. This helps both when using libclang (where we can't require the user to actually change the working directory) and to help reproduce test cases when the reproduction work comes along. --FileSystemOptions is introduced which controls how file system operations are performed (currently it just contains the working directory value if set). --FileSystemOptions are passed around to various interfaces that perform file operations. --Opening & reading the content of files should be done only through FileManager. This is useful in general since file operations will be abstracted in the future for the reproduction mechanism. FileSystemOptions is independent of FileManager so that we can have multiple translation units sharing the same FileManager but with different FileSystemOptions. Addresses rdar://8583824. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118203 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/libclang/CIndex.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tools/libclang/CIndex.cpp') diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index ac57a6941c..3afe3007ea 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1977,9 +1977,11 @@ CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx, return 0; CIndexer *CXXIdx = static_cast(CIdx); + FileSystemOptions FileSystemOpts; + FileSystemOpts.WorkingDir = CXXIdx->getWorkingDirectory(); llvm::IntrusiveRefCntPtr Diags; - return ASTUnit::LoadFromASTFile(ast_filename, Diags, + return ASTUnit::LoadFromASTFile(ast_filename, Diags, FileSystemOpts, CXXIdx->getOnlyLocalDecls(), 0, 0, true); } @@ -2405,7 +2407,8 @@ CXFile clang_getFile(CXTranslationUnit tu, const char *file_name) { ASTUnit *CXXUnit = static_cast(tu); FileManager &FMgr = CXXUnit->getFileManager(); - const FileEntry *File = FMgr.getFile(file_name, file_name+strlen(file_name)); + const FileEntry *File = FMgr.getFile(file_name, file_name+strlen(file_name), + CXXUnit->getFileSystemOpts()); return const_cast(File); } -- cgit v1.2.3-18-g5258