================ @@ -305,8 +307,46 @@ int main(int argc, const char **argv) { } } - clang::tooling::ClangTool Tool(OptionsParser->getCompilations(), - OptionsParser->getSourcePathList()); + auto VFS = llvm::vfs::getRealFileSystem(); + auto &CDB = OptionsParser->getCompilations(); + // CDBToAbsPaths is a map from the path in the compilation database to the + // writable absolute path of the file. + std::map<std::string, std::string> CDBToAbsPaths; + // if Edit is enabled, `Factory.editedFiles()` will contain the final code, + // along with the path given in the compilation database. That path can be + // absolute or relative, and if it is relative, it is relative to the + // "Directory" field in the compilation database. We need to make it + // absolute to write the final code to the correct path. + for (auto &Source : OptionsParser->getSourcePathList()) { + llvm::SmallString<256> AbsPath(Source); + if (auto Err = VFS->makeAbsolute(AbsPath)) { + llvm::errs() << "Failed to get absolute path for " << Source << " : " + << Err.message() << '\n'; + return 1; + } + std::vector<clang::tooling::CompileCommand> Cmds = + CDB.getCompileCommands(AbsPath); + if (Cmds.empty()) { + // Try with the original path. + Cmds = CDB.getCompileCommands(Source); ---------------- kadircet wrote:
this fallback is still not needed. if we can't find the flags with absolute path, it's fine to bail out. https://github.com/llvm/llvm-project/pull/111375 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits