From e09a6262d55ebffbd6e2973e7fe8ced6f1a45d83 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Thu, 20 Aug 2020 02:42:29 +0100 Subject: feat(tvix): Implement std::streambuf for a build log -> gRPC sink Introduces a class which implements std::streambuf by sending build log lines to the provided gRPC stream writer as individual messages. This can be used in the implementations of calls which trigger builds to forward logs back to the clients. Change-Id: I3cecba2219cc24d56692056079c7d7e4e0fc1e2c Reviewed-on: https://cl.tvl.fyi/c/depot/+/1794 Tested-by: BuildkiteCI Reviewed-by: kanepyork Reviewed-by: glittershark --- third_party/nix/src/nix-daemon/nix-daemon-proto.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'third_party/nix/src') diff --git a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc index b7d5836091af..cbc5452a7177 100644 --- a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc +++ b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc @@ -1,7 +1,9 @@ #include "nix-daemon-proto.hh" #include +#include #include +#include #include #include @@ -92,6 +94,22 @@ struct RetrieveRegularNARSink : ParseSink { absl::StrFormat("path '%s' is not in the Nix store", path)); \ } +class BuildLogStreambuf final : public std::streambuf { + public: + using Writer = grpc::ServerWriter; + explicit BuildLogStreambuf(Writer* writer) : writer_(writer) {} + + std::streamsize xsputn(const char_type* s, std::streamsize n) override { + nix::proto::BuildEvent event; + event.mutable_build_log()->set_line(s, n); + writer_->Write(event); + return n; + } + + private: + Writer* writer_{}; +}; + class WorkerServiceImpl final : public WorkerService::Service { public: WorkerServiceImpl(nix::Store& store) : store_(&store) {} -- cgit 1.4.1