Hi klimek,
If we actually change directory before processing a file, we need to
restore it afterwards. This was broken in r216620.
Added a comment for the changes in r216620.
http://reviews.llvm.org/D6162
Files:
lib/Tooling/Tooling.cpp
Index: lib/Tooling/Tooling.cpp
===================================================================
--- lib/Tooling/Tooling.cpp
+++ lib/Tooling/Tooling.cpp
@@ -301,10 +301,18 @@
std::string MainExecutable =
llvm::sys::fs::getMainExecutable("clang_tool", &StaticSymbol);
+ llvm::SmallString<128> InitialDirectory;
+ if (std::error_code EC = llvm::sys::fs::current_path(InitialDirectory))
+ llvm::report_fatal_error("Cannot detect current path: " +
+ Twine(EC.message()));
bool ProcessingFailed = false;
for (const auto &SourcePath : SourcePaths) {
std::string File(getAbsolutePath(SourcePath));
+ // FIXME: getCompileCommands can change the state of the file system (e.g.
+ // prepare generated headers), so it needs to run right before we invoke the
+ // tool, as the next file may require a different (incompatible) state of
+ // the file system.
std::vector<CompileCommand> CompileCommandsForFile =
Compilations.getCompileCommands(File);
if (CompileCommandsForFile.empty()) {
@@ -345,6 +353,11 @@
llvm::errs() << "Error while processing " << File << ".\n";
ProcessingFailed = true;
}
+ // Return to the initial directory to correctly resolve next file by
+ // relative path.
+ if (chdir(InitialDirectory.c_str()))
+ llvm::report_fatal_error("Cannot chdir into \"" +
+ Twine(InitialDirectory) + "\n!");
}
}
return ProcessingFailed ? 1 : 0;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits