about summary refs log tree commit diff
path: root/third_party/nix/src/libstore
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-11-27T23·12-0500
committerglittershark <grfn@gws.fyi>2020-11-28T00·47+0000
commit49024be05644d4fac252e2191e9de74e0ffd4fe3 (patch)
tree73658943ab7a8230215a59e5ec9288882463bc2e /third_party/nix/src/libstore
parent1d22874ab29f696c38146750bdd26645d4d75ccc (diff)
feat(tvix): Thread a log sink through calls to buildDerivation r/1946
Similarly to how we did for buildPaths, add a std::ostream& log_sink
parameter to the build_derivation method on Store, and pass it std::cerr
when called at the top level by nix commands - most notably, the
build-remote hook binary, so that we get build logs when using tvix as a
remote builder.

Change-Id: I0f8f729ba8429d4838a0a135a5c2ac1e1a95d575
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2176
Tested-by: BuildkiteCI
Reviewed-by: andi <andi@notmuch.email>
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Diffstat (limited to 'third_party/nix/src/libstore')
-rw-r--r--third_party/nix/src/libstore/binary-cache-store.hh3
-rw-r--r--third_party/nix/src/libstore/build.cc6
-rw-r--r--third_party/nix/src/libstore/legacy-ssh-store.cc3
-rw-r--r--third_party/nix/src/libstore/local-store.hh3
-rw-r--r--third_party/nix/src/libstore/remote-store.cc3
-rw-r--r--third_party/nix/src/libstore/remote-store.hh3
-rw-r--r--third_party/nix/src/libstore/rpc-store.cc5
-rw-r--r--third_party/nix/src/libstore/rpc-store.hh3
-rw-r--r--third_party/nix/src/libstore/store-api.hh8
9 files changed, 23 insertions, 14 deletions
diff --git a/third_party/nix/src/libstore/binary-cache-store.hh b/third_party/nix/src/libstore/binary-cache-store.hh
index 0b788152f0bc..40c636f60ac2 100644
--- a/third_party/nix/src/libstore/binary-cache-store.hh
+++ b/third_party/nix/src/libstore/binary-cache-store.hh
@@ -93,7 +93,8 @@ class BinaryCacheStore : public Store {
 
   void narFromPath(const Path& path, Sink& sink) override;
 
-  BuildResult buildDerivation(const Path& drvPath, const BasicDerivation& drv,
+  BuildResult buildDerivation(std::ostream& /*log_sink*/, const Path& drvPath,
+                              const BasicDerivation& drv,
                               BuildMode buildMode) override {
     unsupported("buildDerivation");
   }
diff --git a/third_party/nix/src/libstore/build.cc b/third_party/nix/src/libstore/build.cc
index 15ed3b05146c..1f5752a168c8 100644
--- a/third_party/nix/src/libstore/build.cc
+++ b/third_party/nix/src/libstore/build.cc
@@ -4754,11 +4754,11 @@ absl::Status LocalStore::buildPaths(std::ostream& log_sink,
   return absl::OkStatus();
 }
 
-BuildResult LocalStore::buildDerivation(const Path& drvPath,
+BuildResult LocalStore::buildDerivation(std::ostream& log_sink,
+                                        const Path& drvPath,
                                         const BasicDerivation& drv,
                                         BuildMode buildMode) {
-  auto discard_logs = DiscardLogsSink();
-  Worker worker(*this, discard_logs);
+  Worker worker(*this, log_sink);
   auto goal = worker.makeBasicDerivationGoal(drvPath, drv, buildMode);
 
   BuildResult result;
diff --git a/third_party/nix/src/libstore/legacy-ssh-store.cc b/third_party/nix/src/libstore/legacy-ssh-store.cc
index 19603115a81c..8163258179a1 100644
--- a/third_party/nix/src/libstore/legacy-ssh-store.cc
+++ b/third_party/nix/src/libstore/legacy-ssh-store.cc
@@ -199,7 +199,8 @@ struct LegacySSHStore : public Store {
     unsupported("addTextToStore");
   }
 
-  BuildResult buildDerivation(const Path& drvPath, const BasicDerivation& drv,
+  BuildResult buildDerivation(std::ostream& /*log_sink*/, const Path& drvPath,
+                              const BasicDerivation& drv,
                               BuildMode buildMode) override {
     auto conn(connections->get());
 
diff --git a/third_party/nix/src/libstore/local-store.hh b/third_party/nix/src/libstore/local-store.hh
index cfcfb35cc3cc..a7c49079d22f 100644
--- a/third_party/nix/src/libstore/local-store.hh
+++ b/third_party/nix/src/libstore/local-store.hh
@@ -160,7 +160,8 @@ class LocalStore : public LocalFSStore {
   absl::Status buildPaths(std::ostream& log_sink, const PathSet& paths,
                           BuildMode build_mode) override;
 
-  BuildResult buildDerivation(const Path& drvPath, const BasicDerivation& drv,
+  BuildResult buildDerivation(std::ostream& log_sink, const Path& drvPath,
+                              const BasicDerivation& drv,
                               BuildMode buildMode) override;
 
   void ensurePath(const Path& path) override;
diff --git a/third_party/nix/src/libstore/remote-store.cc b/third_party/nix/src/libstore/remote-store.cc
index c4fd856a2cb0..cb6cc808c610 100644
--- a/third_party/nix/src/libstore/remote-store.cc
+++ b/third_party/nix/src/libstore/remote-store.cc
@@ -492,7 +492,8 @@ absl::Status RemoteStore::buildPaths(std::ostream& /* log_sink */,
   return absl::OkStatus();
 }
 
-BuildResult RemoteStore::buildDerivation(const Path& drvPath,
+BuildResult RemoteStore::buildDerivation(std::ostream& /*log_sink*/,
+                                         const Path& drvPath,
                                          const BasicDerivation& drv,
                                          BuildMode buildMode) {
   auto conn(getConnection());
diff --git a/third_party/nix/src/libstore/remote-store.hh b/third_party/nix/src/libstore/remote-store.hh
index 60da6045a81a..c360055b6e6b 100644
--- a/third_party/nix/src/libstore/remote-store.hh
+++ b/third_party/nix/src/libstore/remote-store.hh
@@ -74,7 +74,8 @@ class RemoteStore : public virtual Store {
   absl::Status buildPaths(std::ostream& log_sink, const PathSet& paths,
                           BuildMode build_mode) override;
 
-  BuildResult buildDerivation(const Path& drvPath, const BasicDerivation& drv,
+  BuildResult buildDerivation(std::ostream& log_sink, const Path& drvPath,
+                              const BasicDerivation& drv,
                               BuildMode buildMode) override;
 
   void ensurePath(const Path& path) override;
diff --git a/third_party/nix/src/libstore/rpc-store.cc b/third_party/nix/src/libstore/rpc-store.cc
index afaeca4a660e..c29bd059de9b 100644
--- a/third_party/nix/src/libstore/rpc-store.cc
+++ b/third_party/nix/src/libstore/rpc-store.cc
@@ -374,7 +374,8 @@ absl::Status RpcStore::buildPaths(std::ostream& log_sink, const PathSet& paths,
   return nix::util::proto::GRPCStatusToAbsl(reader->Finish());
 }
 
-BuildResult RpcStore::buildDerivation(const Path& drvPath,
+BuildResult RpcStore::buildDerivation(std::ostream& log_sink,
+                                      const Path& drvPath,
                                       const BasicDerivation& drv,
                                       BuildMode buildMode) {
   ClientContext ctx;
@@ -392,7 +393,7 @@ BuildResult RpcStore::buildDerivation(const Path& drvPath,
   proto::BuildEvent event;
   while (reader->Read(&event)) {
     if (event.has_build_log()) {
-      LOG(INFO) << event.build_log().line();
+      log_sink << event.build_log().line();
     } else if (event.has_result()) {
       result = BuildResult::FromProto(event.result());
     }
diff --git a/third_party/nix/src/libstore/rpc-store.hh b/third_party/nix/src/libstore/rpc-store.hh
index 3a156e9e1afe..679ceac7af9c 100644
--- a/third_party/nix/src/libstore/rpc-store.hh
+++ b/third_party/nix/src/libstore/rpc-store.hh
@@ -70,7 +70,8 @@ class RpcStore : public LocalFSStore, public virtual Store {
   absl::Status buildPaths(std::ostream& log_sink, const PathSet& paths,
                           BuildMode build_mode) override;
 
-  virtual BuildResult buildDerivation(const Path& drvPath,
+  virtual BuildResult buildDerivation(std::ostream& log_sink,
+                                      const Path& drvPath,
                                       const BasicDerivation& drv,
                                       BuildMode buildMode) override;
 
diff --git a/third_party/nix/src/libstore/store-api.hh b/third_party/nix/src/libstore/store-api.hh
index 76c757bd6939..eb18511e60df 100644
--- a/third_party/nix/src/libstore/store-api.hh
+++ b/third_party/nix/src/libstore/store-api.hh
@@ -468,12 +468,14 @@ class Store : public std::enable_shared_from_this<Store>, public Config {
      on-disk .drv file). Note that ‘drvPath’ is only used for
      informational purposes. */
   // TODO(tazjin): Thread std::ostream through here, too.
-  virtual BuildResult buildDerivation(const Path& drvPath,
+  virtual BuildResult buildDerivation(std::ostream& log_sink,
+                                      const Path& drvPath,
                                       const BasicDerivation& drv,
                                       BuildMode buildMode) = 0;
 
-  BuildResult buildDerivation(const Path& drvPath, const BasicDerivation& drv) {
-    return buildDerivation(drvPath, drv, bmNormal);
+  BuildResult buildDerivation(std::ostream& log_sink, const Path& drvPath,
+                              const BasicDerivation& drv) {
+    return buildDerivation(log_sink, drvPath, drv, bmNormal);
   }
 
   /* Ensure that a path is valid.  If it is not currently valid, it