diff options
author | Griffin Smith <grfn@gws.fyi> | 2020-08-08T20·44-0400 |
---|---|---|
committer | glittershark <grfn@gws.fyi> | 2020-08-09T02·22+0000 |
commit | e440f60b6c74c6e2f406b4f187e6c20ee6d315dd (patch) | |
tree | de04c21c18bfa2f80f75144f3403a804a10ff477 /third_party/nix/src/libstore/rpc-store.cc | |
parent | 747dc6515410913aa8eec33d7e84f80e84b8773b (diff) |
feat(tvix): Implement all remaining RPC calls r/1622
Implement all remaining RPC calls on the RpcSstore client, remove a few stub methods we had added that weren't actually present in the old RemoteStore implementation, and add one more RPC call for getBuildLog that is present in the store API, but that we hadn't added as a stub *or* to the proto. Fixes: #29 Change-Id: Id827f51a393ece4bc7bbecaf38aee9eb4b329770 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1692 Reviewed-by: kanepyork <rikingcoding@gmail.com> Tested-by: BuildkiteCI
Diffstat (limited to 'third_party/nix/src/libstore/rpc-store.cc')
-rw-r--r-- | third_party/nix/src/libstore/rpc-store.cc | 97 |
1 files changed, 62 insertions, 35 deletions
diff --git a/third_party/nix/src/libstore/rpc-store.cc b/third_party/nix/src/libstore/rpc-store.cc index 05f4f7968ed3..a0b1ef9cfa2e 100644 --- a/third_party/nix/src/libstore/rpc-store.cc +++ b/third_party/nix/src/libstore/rpc-store.cc @@ -22,7 +22,9 @@ #include "libproto/worker.grpc.pb.h" #include "libproto/worker.pb.h" +#include "libstore/derivations.hh" #include "libstore/store-api.hh" +#include "libstore/worker-protocol.hh" #include "libutil/archive.hh" #include "libutil/hash.hh" #include "libutil/proto.hh" @@ -315,10 +317,6 @@ Path RpcStore::addTextToStore(const std::string& name, return result.path(); } -void RpcStore::narFromPath(const Path& path, Sink& sink) { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); -} - void RpcStore::buildPaths(const PathSet& paths, BuildMode buildMode) { ClientContext ctx; proto::BuildPathsRequest request; @@ -333,11 +331,29 @@ void RpcStore::buildPaths(const PathSet& paths, BuildMode buildMode) { BuildResult RpcStore::buildDerivation(const Path& drvPath, const BasicDerivation& drv, BuildMode buildMode) { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); + ClientContext ctx; + proto::BuildDerivationRequest request; + request.mutable_drv_path()->set_path(drvPath); + auto proto_drv = drv.to_proto(); + request.set_allocated_derivation(&proto_drv); + request.set_build_mode(BuildModeToProto(buildMode)); + proto::BuildDerivationResponse response; + SuccessOrThrow(stub_->BuildDerivation(&ctx, request, &response), + __FUNCTION__); + + const auto result = BuildResult::FromProto(response); + if (!result.has_value()) { + throw Error("Invalid response from daemon for buildDerivation"); + } + return result.value(); } void RpcStore::ensurePath(const Path& path) { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); + ClientContext ctx; + google::protobuf::Empty response; + SuccessOrThrow( + stub_->EnsurePath(&ctx, util::proto::StorePath(path), &response), + __FUNCTION__); } void RpcStore::addTempRoot(const Path& path) { @@ -397,53 +413,64 @@ void RpcStore::collectGarbage(const GCOptions& options, GCResults& results) { } void RpcStore::optimiseStore() { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); + ClientContext ctx; + google::protobuf::Empty response; + SuccessOrThrow(stub_->OptimiseStore(&ctx, kEmpty, &response), __FUNCTION__); } bool RpcStore::verifyStore(bool checkContents, RepairFlag repair) { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); + ClientContext ctx; + proto::VerifyStoreRequest request; + request.set_check_contents(checkContents); + request.set_repair(repair); + proto::VerifyStoreResponse response; + SuccessOrThrow(stub_->VerifyStore(&ctx, request, &response), __FUNCTION__); + return response.errors(); } void RpcStore::addSignatures(const Path& storePath, const StringSet& sigs) { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); -} - -void RpcStore::computeFSClosure(const PathSet& paths, PathSet& paths_, - bool flipDirection, bool includeOutputs, - bool includeDerivers) { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); + ClientContext ctx; + proto::AddSignaturesRequest request; + request.mutable_path()->set_path(storePath); + for (const auto& sig : sigs) { + request.mutable_sigs()->add_sigs(sig); + } + google::protobuf::Empty response; + SuccessOrThrow(stub_->AddSignatures(&ctx, request, &response), __FUNCTION__); } void RpcStore::queryMissing(const PathSet& targets, PathSet& willBuild, PathSet& willSubstitute, PathSet& unknown, unsigned long long& downloadSize, unsigned long long& narSize) { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); -} - -std::shared_ptr<std::string> RpcStore::getBuildLog(const Path& path) { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); -} - -void RpcStore::connect() { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); -} + ClientContext ctx; + proto::QueryMissingResponse response; + SuccessOrThrow( + stub_->QueryMissing(&ctx, util::proto::StorePaths(targets), &response), + __FUNCTION__); -unsigned int RpcStore::getProtocol() { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); + willBuild = util::proto::FillFrom<PathSet>(response.will_build()); + willSubstitute = util::proto::FillFrom<PathSet>(response.will_substitute()); + unknown = util::proto::FillFrom<PathSet>(response.unknown()); + downloadSize = response.download_size(); + narSize = response.nar_size(); } -int RpcStore::getPriority() { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); -} +std::shared_ptr<std::string> RpcStore::getBuildLog(const Path& path) { + ClientContext ctx; + proto::BuildLog response; + SuccessOrThrow( + stub_->GetBuildLog(&ctx, util::proto::StorePath(path), &response), + __FUNCTION__); -Path RpcStore::toRealPath(const Path& storePath) { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); + auto build_log = response.build_log(); + if (build_log.empty()) { + return nullptr; + } + return std::make_shared<std::string>(build_log); } -void RpcStore::createUser(const std::string& userName, uid_t userId) { - throw Unsupported(absl::StrCat("Not implemented ", __func__)); -} +unsigned int RpcStore::getProtocol() { return PROTOCOL_VERSION; } } // namespace store |