feat(tvix): Thread a log sink through calls to buildDerivation

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>
This commit is contained in:
Griffin Smith 2020-11-27 18:12:44 -05:00 committed by glittershark
parent 1d22874ab2
commit 49024be056
13 changed files with 31 additions and 18 deletions

View file

@ -246,7 +246,7 @@ static int _main(int argc, char* argv[]) {
readDerivation(store->realStoreDir + "/" + baseNameOf(drvPath)));
drv.inputSrcs = inputs;
auto result = sshStore->buildDerivation(drvPath, drv);
auto result = sshStore->buildDerivation(std::cerr, drvPath, drv);
if (!result.success()) {
throw Error("build of '%s' on '%s' failed: %s", drvPath, storeUri,

View file

@ -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");
}

View file

@ -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;

View file

@ -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());

View file

@ -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;

View file

@ -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());

View file

@ -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;

View file

@ -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());
}

View file

@ -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;

View file

@ -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

View file

@ -687,7 +687,10 @@ class WorkerServiceImpl final : public WorkerService::Service {
return Status(grpc::StatusCode::INTERNAL, "Invalid build mode");
}
BuildResult res = store_->buildDerivation(drv_path, drv, *build_mode);
BuildLogStreambuf log_buffer(writer);
std::ostream log_sink(&log_buffer);
BuildResult res =
store_->buildDerivation(log_sink, drv_path, drv, *build_mode);
proto::BuildResult proto_res{};
proto_res.set_status(res.status_to_proto());

View file

@ -1088,7 +1088,7 @@ static void opServe(Strings opFlags, Strings opArgs) {
getBuildSettings();
MonitorFdHup monitor(in.fd);
auto status = store->buildDerivation(drvPath, drv);
auto status = store->buildDerivation(std::cerr, drvPath, drv);
out << status.status << status.errorMsg;

View file

@ -36,7 +36,8 @@ class DummyStore final : public Store {
void narFromPath(const Path& path, Sink& sink) {}
BuildResult buildDerivation(const Path& drvPath, const BasicDerivation& drv,
BuildResult buildDerivation(std::ostream& log_sink, const Path& drvPath,
const BasicDerivation& drv,
BuildMode buildMode = bmNormal) {
return BuildResult{};
}