summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.cpp9
-rw-r--r--clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.h7
-rw-r--r--clang-tools-extra/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp19
3 files changed, 20 insertions, 15 deletions
diff --git a/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.cpp b/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.cpp
index 8d81dd5e01e..2724197424e 100644
--- a/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.cpp
+++ b/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.cpp
@@ -97,16 +97,11 @@ bool SymbolInfo::operator<(const SymbolInfo &Symbol) const {
std::tie(Symbol.Name, Symbol.FilePath, Symbol.LineNumber);
}
-bool WriteSymboInfosToFile(llvm::StringRef FilePath,
- const std::set<SymbolInfo> &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 WriteSymbolInfosToStream(llvm::raw_ostream &OS,
+ const std::set<SymbolInfo> &Symbols) {
llvm::yaml::Output yout(OS);
for (auto Symbol : Symbols)
yout << Symbol;
- OS.close();
return true;
}
diff --git a/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.h b/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.h
index 9fa60201a69..e4fc1a6e84e 100644
--- a/clang-tools-extra/include-fixer/find-all-symbols/SymbolInfo.h
+++ b/clang-tools-extra/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 <set>
#include <string>
#include <vector>
@@ -87,9 +88,9 @@ struct SymbolInfo {
bool operator<(const SymbolInfo &Symbol) const;
};
-/// \brief Write SymbolInfos to a single file (YAML format).
-bool WriteSymboInfosToFile(llvm::StringRef FilePath,
- const std::set<SymbolInfo> &Symbols);
+/// \brief Write SymbolInfos to a stream (YAML format).
+bool WriteSymbolInfosToStream(llvm::raw_ostream &OS,
+ const std::set<SymbolInfo> &Symbols);
/// \brief Read SymbolInfos from a YAML document.
std::vector<SymbolInfo> ReadSymbolInfosFromYAML(llvm::StringRef Yaml);
diff --git a/clang-tools-extra/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp b/clang-tools-extra/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
index dec33d139b3..95cd630f220 100644
--- a/clang-tools-extra/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
+++ b/clang-tools-extra/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
@@ -59,10 +59,13 @@ public:
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);
+ WriteSymbolInfosToStream(OS, Symbol.second);
}
}
@@ -90,7 +93,13 @@ bool Merge(llvm::StringRef MergeDir, llvm::StringRef OutputFile) {
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;
+ }
+ WriteSymbolInfosToStream(OS, UniqueSymbols);
return true;
}
OpenPOWER on IntegriCloud