Skip to content

Commit 063f81d

Browse files
committed
Expose the build epoch via the Swift bindings
1 parent 689b15c commit 063f81d

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

products/libllbuild/BuildDB-C-API.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ class CAPIBuildDB: public BuildDBDelegate {
162162
buildUpKeyCache(keys_out);
163163
return success;
164164
}
165+
166+
Epoch getCurrentEpoch(bool *success_out, std::string *error_out) {
167+
return _db.get()->getCurrentEpoch(success_out, error_out);
168+
}
165169
};
166170

167171
const llb_data_t mapData(std::vector<uint8_t> input) {
@@ -372,3 +376,14 @@ bool llb_database_get_keys_and_results(llb_database_t *database, llb_database_fe
372376
return success;
373377
}
374378

379+
uint64_t llb_database_get_epoch(llb_database_t *database, llb_data_t *_Nullable error_out) {
380+
auto db = (CAPIBuildDB *)database;
381+
bool success;
382+
std::string error;
383+
auto epoch = db->getCurrentEpoch(&success, &error);
384+
if (!success && error_out) {
385+
error_out->length = error.size();
386+
error_out->data = (const uint8_t *)strdup(error.c_str());
387+
}
388+
return epoch;
389+
}

products/libllbuild/include/llbuild/db.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ llb_database_get_keys(llb_database_t *database, llb_database_fetch_result_t *_Nu
105105

106106
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);
107107

108+
LLBUILD_EXPORT uint64_t llb_database_get_epoch(llb_database_t *database, llb_data_t *_Nullable error_out);
109+
108110
LLBUILD_ASSUME_NONNULL_END
109111

110112
#endif

products/llbuildSwift/BuildDBBindings.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,15 @@ public final class BuildDB {
309309
llb_database_destroy_result(&result)
310310
return mappedResult
311311
}
312+
313+
public func currentBuildEpoch() throws -> UInt64 {
314+
let errorPtr = MutableStringPointer()
315+
let epoch = llb_database_get_epoch(_database, &errorPtr.ptr)
316+
317+
if let error = errorPtr.msg {
318+
throw Error.operationDidFail(error: error)
319+
}
320+
321+
return epoch
322+
}
312323
}

0 commit comments

Comments
 (0)