From 150228d7dec499a763a8f76477aa35310771fd84 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 15 Mar 2017 16:43:54 +0100 Subject: [PATCH] Upload build logs to the binary cache --- src/hydra-queue-runner/builder.cc | 13 +++++++++++++ src/hydra-queue-runner/hydra-queue-runner.cc | 3 ++- src/hydra-queue-runner/state.hh | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/hydra-queue-runner/builder.cc b/src/hydra-queue-runner/builder.cc index ef690645..4d46457b 100644 --- a/src/hydra-queue-runner/builder.cc +++ b/src/hydra-queue-runner/builder.cc @@ -3,6 +3,7 @@ #include "state.hh" #include "build-result.hh" #include "finally.hh" +#include "binary-cache-store.hh" using namespace nix; @@ -148,6 +149,18 @@ State::StepResult State::doBuildStep(nix::ref destStore, } if (stepNr) { + /* Upload the log file to the binary cache. FIXME: should + be done on a worker thread. */ + try { + auto store = destStore.dynamic_pointer_cast(); + if (uploadLogsToBinaryCache && store && pathExists(result.logFile)) { + store->upsertFile("log/" + baseNameOf(buildDrvPath), readFile(result.logFile), "text/plain"); + unlink(result.logFile.c_str()); + } + } catch (...) { + ignoreException(); + } + /* Asynchronously run plugins. FIXME: if we're killed, plugin actions might not be run. Need to ensure at-least-once semantics. */ diff --git a/src/hydra-queue-runner/hydra-queue-runner.cc b/src/hydra-queue-runner/hydra-queue-runner.cc index 402960b3..bddfcd1a 100644 --- a/src/hydra-queue-runner/hydra-queue-runner.cc +++ b/src/hydra-queue-runner/hydra-queue-runner.cc @@ -58,7 +58,7 @@ struct Config bool getBoolOption(const std::string & key, bool def = false) { auto i = options.find(key); - return i == options.end() ? def : i->second == "true"; + return i == options.end() ? def : (i->second == "true" || i->second == "1"); } }; @@ -74,6 +74,7 @@ State::State() : config(std::make_unique()) , memoryTokens(config->getIntOption("nar_buffer_size", getMemSize() / 2)) , maxOutputSize(config->getIntOption("max_output_size", 2ULL << 30)) + , uploadLogsToBinaryCache(config->getBoolOption("upload_logs_to_binary_cache", false)) { debug("using %d bytes for the NAR buffer", memoryTokens.capacity()); diff --git a/src/hydra-queue-runner/state.hh b/src/hydra-queue-runner/state.hh index 285dac99..e5058593 100644 --- a/src/hydra-queue-runner/state.hh +++ b/src/hydra-queue-runner/state.hh @@ -414,6 +414,8 @@ private: order to detect non-determinism. */ std::map, unsigned int> jobsetRepeats; + bool uploadLogsToBinaryCache; + public: State();