diff options
author | Griffin Smith <grfn@gws.fyi> | 2020-08-20T01·42+0100 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2020-08-20T11·48+0000 |
commit | e09a6262d55ebffbd6e2973e7fe8ced6f1a45d83 (patch) | |
tree | 6ba2d37ca0e4ddab53df5c91190a6e212d2627bc /third_party | |
parent | 19e874a9854c0d7f49d79fa98177a84b6997ce9a (diff) |
feat(tvix): Implement std::streambuf for a build log -> gRPC sink r/1686
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 <rikingcoding@gmail.com> Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/nix/src/nix-daemon/nix-daemon-proto.cc | 18 |
1 files changed, 18 insertions, 0 deletions
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 <filesystem> +#include <ostream> #include <sstream> +#include <streambuf> #include <string> #include <absl/strings/str_cat.h> @@ -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<nix::proto::BuildEvent>; + 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) {} |