39 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/CAS/BuiltinUnifiedCASDatabases.h"10#include "BuiltinCAS.h"11#include "llvm/CAS/ActionCache.h"12#include "llvm/CAS/UnifiedOnDiskCache.h"13 14using namespace llvm;15using namespace llvm::cas;16 17Expected<std::pair<std::unique_ptr<ObjectStore>, std::unique_ptr<ActionCache>>>18cas::createOnDiskUnifiedCASDatabases(StringRef Path) {19 std::shared_ptr<ondisk::UnifiedOnDiskCache> UniDB;20 if (Error E = builtin::createBuiltinUnifiedOnDiskCache(Path).moveInto(UniDB))21 return std::move(E);22 auto CAS = builtin::createObjectStoreFromUnifiedOnDiskCache(UniDB);23 auto AC = builtin::createActionCacheFromUnifiedOnDiskCache(std::move(UniDB));24 return std::make_pair(std::move(CAS), std::move(AC));25}26 27Expected<ValidationResult> cas::validateOnDiskUnifiedCASDatabasesIfNeeded(28 StringRef Path, bool CheckHash, bool AllowRecovery, bool ForceValidation,29 std::optional<StringRef> LLVMCasBinary) {30#if LLVM_ENABLE_ONDISK_CAS31 return ondisk::UnifiedOnDiskCache::validateIfNeeded(32 Path, builtin::BuiltinCASContext::getHashName(),33 sizeof(builtin::HashType), CheckHash, AllowRecovery, ForceValidation,34 LLVMCasBinary);35#else36 return createStringError(inconvertibleErrorCode(), "OnDiskCache is disabled");37#endif38}39