Skip to content

Commit

Permalink
Expose the build epoch via the Swift bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
jakepetroules committed Jan 16, 2021
1 parent 689b15c commit 063f81d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions products/libllbuild/BuildDB-C-API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> input) {
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions products/libllbuild/include/llbuild/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions products/llbuildSwift/BuildDBBindings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 063f81d

Please sign in to comment.