mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
06f6137004
Implement the `getComponentsHash` function which returns a hash string for all the components currently installed in revng.
41 lines
921 B
C++
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
|