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 <rikingcoding@gmail.com> Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
parent
19e874a985
commit
e09a6262d5
1 changed files with 18 additions and 0 deletions
|
@ -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) {}
|
||||
|
|
Loading…
Reference in a new issue