llvm-project/llvm/lib/CAS/BuiltinUnifiedCASDatabases.cpp
Steven Wu 6747ea050d
[CAS] Add UnifiedOnDiskCache and OnDiskCAS (#114103)
Add a new abstraction layer UnifiedOnDiskCache that adds new functions
of disk space management and data validation that builds on top of
OnDiskGraphDB and OnDiskKeyValueDB.

Build upon UnifiedOnDiskCache, it is OnDiskCAS that implements
ObjectStore and ActionCache interface for LLVM tools to interact with
CAS storage.
2025-11-03 09:50:28 -08:00

39 lines
1.6 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/CAS/BuiltinUnifiedCASDatabases.h"
#include "BuiltinCAS.h"
#include "llvm/CAS/ActionCache.h"
#include "llvm/CAS/UnifiedOnDiskCache.h"
using namespace llvm;
using namespace llvm::cas;
Expected<std::pair<std::unique_ptr<ObjectStore>, std::unique_ptr<ActionCache>>>
cas::createOnDiskUnifiedCASDatabases(StringRef Path) {
std::shared_ptr<ondisk::UnifiedOnDiskCache> UniDB;
if (Error E = builtin::createBuiltinUnifiedOnDiskCache(Path).moveInto(UniDB))
return std::move(E);
auto CAS = builtin::createObjectStoreFromUnifiedOnDiskCache(UniDB);
auto AC = builtin::createActionCacheFromUnifiedOnDiskCache(std::move(UniDB));
return std::make_pair(std::move(CAS), std::move(AC));
}
Expected<ValidationResult> cas::validateOnDiskUnifiedCASDatabasesIfNeeded(
StringRef Path, bool CheckHash, bool AllowRecovery, bool ForceValidation,
std::optional<StringRef> LLVMCasBinary) {
#if LLVM_ENABLE_ONDISK_CAS
return ondisk::UnifiedOnDiskCache::validateIfNeeded(
Path, builtin::BuiltinCASContext::getHashName(),
sizeof(builtin::HashType), CheckHash, AllowRecovery, ForceValidation,
LLVMCasBinary);
#else
return createStringError(inconvertibleErrorCode(), "OnDiskCache is disabled");
#endif
}