aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-11-03 22:45:23 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-11-03 22:45:23 +0000
commit71731d6b05db0fd5ff6c2e0641b050599706ae02 (patch)
tree662dbb298a9ba35a0e003756388af16da7f753f6 /clang/lib/Frontend/CompilerInstance.cpp
parentef43990bb89741d779777bebd75e0bbb2c4172bf (diff)
downloadllvm-71731d6b05db0fd5ff6c2e0641b050599706ae02.zip
llvm-71731d6b05db0fd5ff6c2e0641b050599706ae02.tar.gz
llvm-71731d6b05db0fd5ff6c2e0641b050599706ae02.tar.bz2
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. llvm-svn: 118203
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 95d417f..c5e5d7f 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -148,8 +148,9 @@ void CompilerInstance::createFileManager() {
// Source Manager
-void CompilerInstance::createSourceManager() {
- SourceMgr.reset(new SourceManager(getDiagnostics()));
+void CompilerInstance::createSourceManager(FileManager &FileMgr,
+ const FileSystemOptions &FSOpts) {
+ SourceMgr.reset(new SourceManager(getDiagnostics(), FileMgr, FSOpts));
}
// Preprocessor
@@ -158,8 +159,8 @@ void CompilerInstance::createPreprocessor() {
PP.reset(createPreprocessor(getDiagnostics(), getLangOpts(),
getPreprocessorOpts(), getHeaderSearchOpts(),
getDependencyOutputOpts(), getTarget(),
- getFrontendOpts(), getSourceManager(),
- getFileManager()));
+ getFrontendOpts(), getFileSystemOpts(),
+ getSourceManager(), getFileManager()));
}
Preprocessor *
@@ -170,15 +171,16 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags,
const DependencyOutputOptions &DepOpts,
const TargetInfo &Target,
const FrontendOptions &FEOpts,
+ const FileSystemOptions &FSOpts,
SourceManager &SourceMgr,
FileManager &FileMgr) {
// Create a PTH manager if we are using some form of a token cache.
PTHManager *PTHMgr = 0;
if (!PPOpts.TokenCache.empty())
- PTHMgr = PTHManager::Create(PPOpts.TokenCache, Diags);
+ PTHMgr = PTHManager::Create(PPOpts.TokenCache, FileMgr, FSOpts, Diags);
// Create the Preprocessor.
- HeaderSearch *HeaderInfo = new HeaderSearch(FileMgr);
+ HeaderSearch *HeaderInfo = new HeaderSearch(FileMgr, FSOpts);
Preprocessor *PP = new Preprocessor(Diags, LangInfo, Target,
SourceMgr, *HeaderInfo, PTHMgr,
/*OwnsHeaderSearch=*/true);
@@ -194,7 +196,7 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags,
if (PPOpts.DetailedRecord)
PP->createPreprocessingRecord();
- InitializePreprocessor(*PP, PPOpts, HSOpts, FEOpts);
+ InitializePreprocessor(*PP, FSOpts, PPOpts, HSOpts, FEOpts);
// Handle generating dependencies, if requested.
if (!DepOpts.OutputFile.empty())
@@ -271,7 +273,8 @@ static bool EnableCodeCompletion(Preprocessor &PP,
unsigned Column) {
// Tell the source manager to chop off the given file at a specific
// line and column.
- const FileEntry *Entry = PP.getFileManager().getFile(Filename);
+ const FileEntry *Entry = PP.getFileManager().getFile(Filename,
+ PP.getFileSystemOpts());
if (!Entry) {
PP.getDiagnostics().Report(diag::err_fe_invalid_code_complete_file)
<< Filename;
@@ -352,7 +355,11 @@ void CompilerInstance::clearOutputFiles(bool EraseFiles) {
TempPath.eraseFromDisk();
else {
std::string Error;
- if (TempPath.renamePathOnDisk(llvm::sys::Path(it->Filename), &Error)) {
+ llvm::sys::Path NewOutFile(it->Filename);
+ // If '-working-directory' was passed, the output filename should be
+ // relative to that.
+ FileManager::FixupRelativePath(NewOutFile, getFileSystemOpts());
+ if (TempPath.renamePathOnDisk(NewOutFile, &Error)) {
getDiagnostics().Report(diag::err_fe_unable_to_rename_temp)
<< it->TempFilename << it->Filename << Error;
TempPath.eraseFromDisk();
@@ -457,17 +464,19 @@ CompilerInstance::createOutputFile(llvm::StringRef OutputPath,
bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile) {
return InitializeSourceManager(InputFile, getDiagnostics(), getFileManager(),
+ getFileSystemOpts(),
getSourceManager(), getFrontendOpts());
}
bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
Diagnostic &Diags,
FileManager &FileMgr,
+ const FileSystemOptions &FSOpts,
SourceManager &SourceMgr,
const FrontendOptions &Opts) {
// Figure out where to get and map in the main file.
if (InputFile != "-") {
- const FileEntry *File = FileMgr.getFile(InputFile);
+ const FileEntry *File = FileMgr.getFile(InputFile, FSOpts);
if (!File) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
@@ -480,7 +489,8 @@ bool CompilerInstance::InitializeSourceManager(llvm::StringRef InputFile,
return false;
}
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
- SB->getBufferSize(), 0);
+ SB->getBufferSize(), 0,
+ FSOpts);
SourceMgr.createMainFileID(File);
SourceMgr.overrideFileContents(File, SB);
}