| 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-exception |
| 6 | // |
| 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 | |
| 14 | using namespace llvm; |
| 15 | using namespace llvm::cas; |
| 16 | |
| 17 | Expected<std::pair<std::unique_ptr<ObjectStore>, std::unique_ptr<ActionCache>>> |
| 18 | cas::createOnDiskUnifiedCASDatabases(StringRef Path) { |
| 19 | std::shared_ptr<ondisk::UnifiedOnDiskCache> UniDB; |
| 20 | if (Error E = builtin::createBuiltinUnifiedOnDiskCache(Path).moveInto(Value&: UniDB)) |
| 21 | return std::move(E); |
| 22 | auto CAS = builtin::createObjectStoreFromUnifiedOnDiskCache(UniDB); |
| 23 | auto AC = builtin::createActionCacheFromUnifiedOnDiskCache(UniDB: std::move(UniDB)); |
| 24 | return std::make_pair(x: std::move(CAS), y: std::move(AC)); |
| 25 | } |
| 26 | |
| 27 | Expected<ValidationResult> cas::validateOnDiskUnifiedCASDatabasesIfNeeded( |
| 28 | StringRef Path, bool CheckHash, bool AllowRecovery, bool ForceValidation, |
| 29 | std::optional<StringRef> LLVMCasBinary) { |
| 30 | #if LLVM_ENABLE_ONDISK_CAS |
| 31 | return ondisk::UnifiedOnDiskCache::validateIfNeeded( |
| 32 | Path, HashName: builtin::BuiltinCASContext::getHashName(), |
| 33 | HashByteSize: sizeof(builtin::HashType), CheckHash, HashFn: builtin::hashingFunc, AllowRecovery, |
| 34 | ForceValidation, LLVMCasBinary); |
| 35 | #else |
| 36 | return createStringError(inconvertibleErrorCode(), "OnDiskCache is disabled" ); |
| 37 | #endif |
| 38 | } |
| 39 | |