Index: include-fixer/find-all-symbols/SymbolInfo.h =================================================================== --- include-fixer/find-all-symbols/SymbolInfo.h +++ include-fixer/find-all-symbols/SymbolInfo.h @@ -12,6 +12,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" #include #include #include @@ -87,9 +88,9 @@ bool operator<(const SymbolInfo &Symbol) const; }; -/// \brief Write SymbolInfos to a single file (YAML format). -bool WriteSymboInfosToFile(llvm::StringRef FilePath, - const std::set &Symbols); +/// \brief Write SymbolInfos to a stream (YAML format). +bool WriteSymbolInfosToFile(llvm::raw_ostream &OS, + const std::set &Symbols); /// \brief Read SymbolInfos from a YAML document. std::vector ReadSymbolInfosFromYAML(llvm::StringRef Yaml); Index: include-fixer/find-all-symbols/SymbolInfo.cpp =================================================================== --- include-fixer/find-all-symbols/SymbolInfo.cpp +++ include-fixer/find-all-symbols/SymbolInfo.cpp @@ -97,16 +97,11 @@ std::tie(Symbol.Name, Symbol.FilePath, Symbol.LineNumber); } -bool WriteSymboInfosToFile(llvm::StringRef FilePath, - const std::set &Symbols) { - int FD = 0; - if (llvm::sys::fs::openFileForWrite(FilePath, FD, llvm::sys::fs::F_None)) - return false; - llvm::raw_fd_ostream OS(FD, true); +bool WriteSymbolInfosToFile(llvm::raw_ostream &OS, + const std::set &Symbols) { llvm::yaml::Output yout(OS); for (auto Symbol : Symbols) yout << Symbol; - OS.close(); return true; } Index: include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp =================================================================== --- include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp +++ include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp @@ -59,10 +59,13 @@ void Write(const std::string &Dir) { for (const auto &Symbol : Symbols) { - SmallString<256> FilePath(Dir); - llvm::sys::path::append( - FilePath, llvm::sys::path::filename(Symbol.first) + ".yaml"); - WriteSymboInfosToFile(FilePath, Symbol.second); + int FD; + SmallString<128> ResultPath; + llvm::sys::fs::createUniqueFile( + Dir + "/" + llvm::sys::path::filename(Symbol.first) + "-%%%%%%.yaml", + FD, ResultPath); + llvm::raw_fd_ostream OS(FD, /*shouldClose=*/true); + WriteSymbolInfosToFile(OS, Symbol.second); } } @@ -90,7 +93,13 @@ UniqueSymbols.insert(Symbol); } - WriteSymboInfosToFile(OutputFile, UniqueSymbols); + llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_None); + if (EC) { + llvm::errs() << "Cann't open '" << OutputFile << "': " << EC.message() + << '\n'; + return false; + } + WriteSymbolInfosToFile(OS, UniqueSymbols); return true; }