Files
revng-revng/lib/Support/ResourceFinder.cpp
Giacomo Vercesi 06f6137004 ResourceFinder: implement getComponentsHash
Implement the `getComponentsHash` function which returns a hash string
for all the components currently installed in revng.
2024-01-26 17:46:21 +01:00

41 lines
921 B
C++

//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "revng/Support/Assert.h"
#include "revng/Support/ResourceFinder.h"
namespace revng {
PathList ResourceFinder({
getCurrentRoot().str(),
#ifdef INSTALL_PATH
INSTALL_PATH,
#endif
});
std::string getComponentsHash() {
std::string Directory = "share/revng/component-hashes";
std::vector<std::string> Files = ResourceFinder.list(Directory, "");
llvm::sort(Files);
std::string Result;
for (std::string &File : Files) {
auto MaybeBuffer = llvm::MemoryBuffer::getFile(File);
revng_assert(MaybeBuffer);
llvm::StringRef Contents = MaybeBuffer->get()->getBuffer().trim();
Result.append(Contents.begin(), Contents.end());
}
return Result;
}
} // namespace revng