Files
lix/lix/libexec/launch-builder.hh
T
eldritch horrors aa896041e0 libstore: asyncify build child setup completion wait
Change-Id: Ica70af2a1205830f1ca4bb48f42d09923cff2e58
2026-02-03 14:11:59 +00:00

80 lines
2.0 KiB
C++

#pragma once
///@file
#include "lix/libstore/build/request.capnp.h"
#include "lix/libutil/rpc.hh"
#include <boost/format.hpp>
#include <capnp/message.h>
#include <capnp/serialize.h>
#include <cstring>
#include <exception>
#include <memory>
#include <string>
#include <string_view>
#include <unistd.h>
#include <vector>
namespace nix {
bool prepareChildSetup(nix::build::Request::Reader request);
void finishChildSetup(nix::build::Request::Reader request);
[[noreturn]]
void execBuilder(nix::build::Request::Reader request);
// silence the foreign exception lint for this helper
class BaseException : public std::exception
{};
class SysError : public BaseException
{
private:
std::shared_ptr<std::string> msg;
public:
explicit SysError(auto fmt, const auto &... args) : SysError(errno, fmt, args...) {}
SysError(int error, auto fmt, const auto &... args)
{
const auto errstr = strerror(error);
auto format = boost::format(fmt);
((format % args), ...);
msg = std::make_shared<std::string>(format.str() + ": " + errstr);
}
const char * what() const noexcept override
{
return msg->c_str();
}
};
struct ExecRequest
{
std::string builder;
std::vector<std::string> argsStorage, envsStorage;
std::vector<char *> args, envs;
ExecRequest(nix::build::Request::Reader request);
};
void writeFull(int fd, std::string_view data);
extern bool printDebugLogs;
inline void printDebugLog(auto fmt, const auto &... args)
{
auto format = boost::format(fmt);
((format % args), ...);
capnp::MallocMessageBuilder builder;
auto log = builder.getRoot<build::SetupResponse>();
RPC_FILL(log, setLogLine, format.str());
capnp::writeMessageToFd(STDIN_FILENO, builder);
}
#define debug(msg, ...) \
do { \
if (::nix::printDebugLogs) { \
printDebugLog(msg, __VA_ARGS__); \
} \
} while (0)
}