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 --- lib/Frontend/InitPreprocessor.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib/Frontend/InitPreprocessor.cpp') diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 181f671025..7275733bbb 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -478,6 +478,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI, static void InitializeFileRemapping(Diagnostic &Diags, SourceManager &SourceMgr, FileManager &FileMgr, + const FileSystemOptions &FSOpts, const PreprocessorOptions &InitOpts) { // Remap files in the source manager (with buffers). for (PreprocessorOptions::const_remapped_file_buffer_iterator @@ -488,7 +489,7 @@ static void InitializeFileRemapping(Diagnostic &Diags, // Create the file entry for the file that we're mapping from. const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first, Remap->second->getBufferSize(), - 0); + 0, FSOpts); if (!FromFile) { Diags.Report(diag::err_fe_remap_missing_from_file) << Remap->first; @@ -510,7 +511,7 @@ static void InitializeFileRemapping(Diagnostic &Diags, Remap != RemapEnd; ++Remap) { // Find the file that we're mapping to. - const FileEntry *ToFile = FileMgr.getFile(Remap->second); + const FileEntry *ToFile = FileMgr.getFile(Remap->second, FSOpts); if (!ToFile) { Diags.Report(diag::err_fe_remap_missing_to_file) << Remap->first << Remap->second; @@ -520,7 +521,7 @@ static void InitializeFileRemapping(Diagnostic &Diags, // Create the file entry for the file that we're mapping from. const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first, ToFile->getSize(), - 0); + 0, FSOpts); if (!FromFile) { Diags.Report(diag::err_fe_remap_missing_from_file) << Remap->first; @@ -530,7 +531,7 @@ static void InitializeFileRemapping(Diagnostic &Diags, // Load the contents of the file we're mapping to. std::string ErrorStr; const llvm::MemoryBuffer *Buffer - = llvm::MemoryBuffer::getFile(ToFile->getName(), &ErrorStr); + = FileMgr.getBufferForFile(ToFile->getName(), FSOpts, &ErrorStr); if (!Buffer) { Diags.Report(diag::err_fe_error_opening) << Remap->second << ErrorStr; @@ -547,6 +548,7 @@ static void InitializeFileRemapping(Diagnostic &Diags, /// environment ready to process a single file. This returns true on error. /// void clang::InitializePreprocessor(Preprocessor &PP, + const FileSystemOptions &FSOpts, const PreprocessorOptions &InitOpts, const HeaderSearchOptions &HSOpts, const FrontendOptions &FEOpts) { @@ -556,7 +558,7 @@ void clang::InitializePreprocessor(Preprocessor &PP, MacroBuilder Builder(Predefines); InitializeFileRemapping(PP.getDiagnostics(), PP.getSourceManager(), - PP.getFileManager(), InitOpts); + PP.getFileManager(), FSOpts, InitOpts); // Emit line markers for various builtin sections of the file. We don't do // this in asm preprocessor mode, because "# 4" is not a line marker directive -- cgit v1.2.3-18-g5258