From 505b6b044b132b28e1501491bcfe6bd68ca1989e Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 19 May 2020 01:02:44 +0100 Subject: refactor(3p/nix/libstore): Replace logging.h with glog --- third_party/nix/src/libstore/remote-store.cc | 97 +++++++++++++++++++--------- 1 file changed, 65 insertions(+), 32 deletions(-) (limited to 'third_party/nix/src/libstore/remote-store.cc') diff --git a/third_party/nix/src/libstore/remote-store.cc b/third_party/nix/src/libstore/remote-store.cc index 802316dcf351..d041c452a860 100644 --- a/third_party/nix/src/libstore/remote-store.cc +++ b/third_party/nix/src/libstore/remote-store.cc @@ -1,6 +1,7 @@ #include "remote-store.hh" #include #include +#include #include #include #include @@ -13,6 +14,7 @@ #include "finally.hh" #include "globals.hh" #include "pool.hh" +#include "prefork-compat.hh" #include "serialise.hh" #include "util.hh" #include "worker-protocol.hh" @@ -150,10 +152,14 @@ void RemoteStore::initConnection(Connection& conn) { } void RemoteStore::setOptions(Connection& conn) { - conn.to << wopSetOptions << settings.keepFailed << settings.keepGoing - << settings.tryFallback << verbosity << settings.maxBuildJobs - << settings.maxSilentTime << true - << (settings.verboseBuild ? lvlError : lvlVomit) + conn.to << wopSetOptions << settings.keepFailed + << settings.keepGoing + // TODO(tazjin): Remove the verbosity stuff here. + << settings.tryFallback << compat::kInfo << settings.maxBuildJobs + << settings.maxSilentTime + << true + // TODO(tazjin): what behaviour does this toggle remotely? + << (settings.verboseBuild ? compat::kError : compat::kVomit) << 0 // obsolete log type << 0 /* obsolete print build trace */ << settings.buildCores << settings.useSubstitutes; @@ -194,7 +200,8 @@ struct ConnectionHandle { ~ConnectionHandle() { if (!daemonException && std::uncaught_exceptions()) { handle.markBad(); - debug("closing daemon connection because of an exception"); + // TODO(tazjin): are these types of things supposed to be DEBUG? + DLOG(INFO) << "closing daemon connection because of an exception"; } } @@ -625,19 +632,29 @@ RemoteStore::Connection::~Connection() { } } -static Logger::Fields readFields(Source& from) { - Logger::Fields fields; +// TODO(tazjin): these logger fields used to be passed to the JSON +// logger but I don't care about them, whatever sends them should +// also be fixed. +static void ignoreFields(Source& from) { size_t size = readInt(from); + + // This ignores the fields simply by reading the data into nowhere. for (size_t n = 0; n < size; n++) { - auto type = (decltype(Logger::Field::type))readInt(from); - if (type == Logger::Field::tInt) - fields.push_back(readNum(from)); - else if (type == Logger::Field::tString) - fields.push_back(readString(from)); - else - throw Error("got unsupported field type %x from Nix daemon", (int)type); + auto type_tag = readInt(from); + + switch (type_tag) { + case 0: // previously: 0 ~ Logger::Field::tInt + readNum(from); + break; + + case 1: // previously: 1 ~ Logger::Field::tString + readString(from); + break; + + default: + throw Error("got unsupported field type %x from Nix daemon", type_tag); + } } - return fields; } std::exception_ptr RemoteStore::Connection::processStderr(Sink* sink, @@ -667,36 +684,52 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink* sink, return std::make_exception_ptr(Error(status, error)); } - else if (msg == STDERR_NEXT) - printError(chomp(readString(from))); + else if (msg == STDERR_NEXT) { + LOG(ERROR) << chomp(readString(from)); + } else if (msg == STDERR_START_ACTIVITY) { - auto act = readNum(from); - auto lvl = (Verbosity)readInt(from); - auto type = (ActivityType)readInt(from); - auto s = readString(from); - auto fields = readFields(from); - auto parent = readNum(from); - logger->startActivity(act, lvl, type, s, fields, parent); + // Various fields need to be ignored in this case, as the + // activity stuff is being removed. + readNum(from); // used to be ActivityId + const auto verbosity = static_cast(readInt(from)); + readInt(from); // activity type + const auto msg = readString(from); + ignoreFields(from); + readNum(from); // ActivityId of "parent" + + switch (verbosity) { + case compat::kError: + LOG(ERROR) << msg; + break; + case compat::kWarn: + LOG(WARNING) << msg; + break; + case compat::kInfo: + LOG(INFO) << msg; + break; + default: + DLOG(INFO) << msg; + } } else if (msg == STDERR_STOP_ACTIVITY) { - auto act = readNum(from); - logger->stopActivity(act); + readNum(from); // used to be ActivityId } else if (msg == STDERR_RESULT) { - auto act = readNum(from); - auto type = (ResultType)readInt(from); - auto fields = readFields(from); - logger->result(act, type, fields); + readNum(from); // ActivityId + readInt(from); // ResultType + ignoreFields(from); } - else if (msg == STDERR_LAST) + else if (msg == STDERR_LAST) { break; + } - else + else { throw Error("got unknown message type %x from Nix daemon", msg); + } } return nullptr; -- cgit 1.4.1