diff --git a/products/libllbuild/BuildDB-C-API.cpp b/products/libllbuild/BuildDB-C-API.cpp index b423303f..22c90d18 100644 --- a/products/libllbuild/BuildDB-C-API.cpp +++ b/products/libllbuild/BuildDB-C-API.cpp @@ -162,6 +162,10 @@ class CAPIBuildDB: public BuildDBDelegate { buildUpKeyCache(keys_out); return success; } + + Epoch getCurrentEpoch(bool *success_out, std::string *error_out) { + return _db.get()->getCurrentEpoch(success_out, error_out); + } }; const llb_data_t mapData(std::vector input) { @@ -372,3 +376,14 @@ bool llb_database_get_keys_and_results(llb_database_t *database, llb_database_fe return success; } +uint64_t llb_database_get_epoch(llb_database_t *database, llb_data_t *_Nullable error_out) { + auto db = (CAPIBuildDB *)database; + bool success; + std::string error; + auto epoch = db->getCurrentEpoch(&success, &error); + if (!success && error_out) { + error_out->length = error.size(); + error_out->data = (const uint8_t *)strdup(error.c_str()); + } + return epoch; +} diff --git a/products/libllbuild/include/llbuild/db.h b/products/libllbuild/include/llbuild/db.h index e5b25731..75babb84 100644 --- a/products/libllbuild/include/llbuild/db.h +++ b/products/libllbuild/include/llbuild/db.h @@ -105,6 +105,8 @@ llb_database_get_keys(llb_database_t *database, llb_database_fetch_result_t *_Nu LLBUILD_EXPORT bool llb_database_get_keys_and_results(llb_database_t *database, llb_database_fetch_result_t *_Nullable *_Nonnull keysAndResults_out, llb_data_t *_Nullable error_out); +LLBUILD_EXPORT uint64_t llb_database_get_epoch(llb_database_t *database, llb_data_t *_Nullable error_out); + LLBUILD_ASSUME_NONNULL_END #endif diff --git a/products/llbuildSwift/BuildDBBindings.swift b/products/llbuildSwift/BuildDBBindings.swift index cc3a001d..7658f458 100644 --- a/products/llbuildSwift/BuildDBBindings.swift +++ b/products/llbuildSwift/BuildDBBindings.swift @@ -309,4 +309,15 @@ public final class BuildDB { llb_database_destroy_result(&result) return mappedResult } + + public func currentBuildEpoch() throws -> UInt64 { + let errorPtr = MutableStringPointer() + let epoch = llb_database_get_epoch(_database, &errorPtr.ptr) + + if let error = errorPtr.msg { + throw Error.operationDidFail(error: error) + } + + return epoch + } }