forked from OSchip/llvm-project
[Introspection] Dont emit json if unchanged.
Saves running the generate inc script in the, somewhat common, case where the json file doesn't need changing. Reviewed By: steveire Differential Revision: https://reviews.llvm.org/D100719
This commit is contained in:
parent
3d1d7156e9
commit
db75db85f2
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "clang/Frontend/CompilerInstance.h"
|
||||
#include "llvm/Support/JSON.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
using namespace clang::tooling;
|
||||
using namespace llvm;
|
||||
|
@ -105,13 +106,27 @@ void WriteJSON(StringRef JsonPath, llvm::json::Object &&ClassInheritance,
|
|||
JsonObj["classesInClade"] = std::move(ClassesInClade);
|
||||
JsonObj["classEntries"] = std::move(ClassEntries);
|
||||
|
||||
llvm::json::Value JsonVal(std::move(JsonObj));
|
||||
|
||||
bool WriteChange = false;
|
||||
std::string OutString;
|
||||
if (auto ExistingOrErr = MemoryBuffer::getFile(JsonPath, /*IsText=*/true)) {
|
||||
raw_string_ostream Out(OutString);
|
||||
Out << formatv("{0:2}", JsonVal);
|
||||
if (ExistingOrErr.get()->getBuffer() == Out.str())
|
||||
return;
|
||||
WriteChange = true;
|
||||
}
|
||||
|
||||
std::error_code EC;
|
||||
llvm::raw_fd_ostream JsonOut(JsonPath, EC, llvm::sys::fs::F_Text);
|
||||
if (EC)
|
||||
return;
|
||||
|
||||
llvm::json::Value JsonVal(std::move(JsonObj));
|
||||
JsonOut << formatv("{0:2}", JsonVal);
|
||||
if (WriteChange)
|
||||
JsonOut << OutString;
|
||||
else
|
||||
JsonOut << formatv("{0:2}", JsonVal);
|
||||
}
|
||||
|
||||
void ASTSrcLocProcessor::generate() {
|
||||
|
|
Loading…
Reference in New Issue