refactor(3p/nix/libexpr): Replace logging.h with glog

This commit is contained in:
Vincent Ambo 2020-05-19 01:24:50 +01:00
parent d0c44425e1
commit 939dd9f817
8 changed files with 37 additions and 35 deletions

View file

@ -16,6 +16,7 @@
#include "json.hh" #include "json.hh"
#include "store-api.hh" #include "store-api.hh"
#include "util.hh" #include "util.hh"
#include <glog/logging.h>
#if HAVE_BOEHMGC #if HAVE_BOEHMGC
@ -232,7 +233,7 @@ void initGC() {
if (pageSize != -1) size = (pageSize * pages) / 4; // 25% of RAM if (pageSize != -1) size = (pageSize * pages) / 4; // 25% of RAM
if (size > maxSize) size = maxSize; if (size > maxSize) size = maxSize;
#endif #endif
debug(format("setting initial heap size to %1% bytes") % size); DLOG(INFO) << "setting initial heap size to " << size << " bytes";
GC_expand_hp(size); GC_expand_hp(size);
} }
@ -375,7 +376,7 @@ Path EvalState::checkSourcePath(const Path& path_) {
"access to path '%1%' is forbidden in restricted mode", abspath); "access to path '%1%' is forbidden in restricted mode", abspath);
/* Resolve symlinks. */ /* Resolve symlinks. */
debug(format("checking access to '%s'") % abspath); DLOG(INFO) << "checking access to '" << abspath << "'";
Path path = canonPath(abspath, true); Path path = canonPath(abspath, true);
for (auto& i : *allowedPaths) { for (auto& i : *allowedPaths) {
@ -689,7 +690,7 @@ void EvalState::evalFile(const Path& path_, Value& v) {
return; return;
} }
printTalkative("evaluating file '%1%'", path2); DLOG(INFO) << "evaluating file '" << path2 << "'";
Expr* e = nullptr; Expr* e = nullptr;
auto j = fileParseCache.find(path2); auto j = fileParseCache.find(path2);
@ -1530,8 +1531,7 @@ string EvalState::copyPathToStore(PathSet& context, const Path& path) {
: store->addToStore(baseNameOf(path), checkSourcePath(path), true, : store->addToStore(baseNameOf(path), checkSourcePath(path), true,
htSHA256, defaultPathFilter, repair); htSHA256, defaultPathFilter, repair);
srcToStore[path] = dstPath; srcToStore[path] = dstPath;
printMsg(lvlChatty, DLOG(INFO) << "copied source '" << path << "' -> '" << dstPath << "'";
format("copied source '%1%' -> '%2%'") % path % dstPath);
} }
context.insert(dstPath); context.insert(dstPath);

View file

@ -1,17 +1,18 @@
#include "function-trace.hh" #include "function-trace.hh"
#include <glog/logging.h>
namespace nix { namespace nix {
FunctionCallTrace::FunctionCallTrace(const Pos& pos) : pos(pos) { FunctionCallTrace::FunctionCallTrace(const Pos& pos) : pos(pos) {
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration); auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
printMsg(lvlInfo, "function-trace entered %1% at %2%", pos, ns.count()); LOG(INFO) << "function-trace entered " << pos << " at " << ns.count();
} }
FunctionCallTrace::~FunctionCallTrace() { FunctionCallTrace::~FunctionCallTrace() {
auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); auto duration = std::chrono::high_resolution_clock::now().time_since_epoch();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration); auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
printMsg(lvlInfo, "function-trace exited %1% at %2%", pos, ns.count()); LOG(INFO) << "function-trace exited " << pos << " at " << ns.count();
} }
} // namespace nix } // namespace nix

View file

@ -4,6 +4,7 @@
#include "derivations.hh" #include "derivations.hh"
#include "eval-inline.hh" #include "eval-inline.hh"
#include "util.hh" #include "util.hh"
#include <glog/logging.h>
namespace nix { namespace nix {
@ -301,7 +302,7 @@ static void getDerivations(EvalState& state, Value& vIn,
bound to the attribute with the "lower" name should take bound to the attribute with the "lower" name should take
precedence). */ precedence). */
for (auto& i : v.attrs->lexicographicOrder()) { for (auto& i : v.attrs->lexicographicOrder()) {
debug("evaluating attribute '%1%'", i->name); DLOG(INFO) << "evaluating attribute '" << i->name << "'";
if (!std::regex_match(std::string(i->name), attrRegex)) continue; if (!std::regex_match(std::string(i->name), attrRegex)) continue;
string pathPrefix2 = addToPath(pathPrefix, i->name); string pathPrefix2 = addToPath(pathPrefix, i->name);
if (combineChannels) if (combineChannels)

View file

@ -39,8 +39,10 @@ libexpr_headers = files(
libexpr_dep_list = [ libexpr_dep_list = [
gc_dep, gc_dep,
glog_dep,
libdl_dep, libdl_dep,
libsodium_dep] libsodium_dep,
]
if sys_name == 'freebsd' if sys_name == 'freebsd'
libexpr_dep_list += libdl_dep libexpr_dep_list += libdl_dep

View file

@ -17,9 +17,9 @@
#define BISON_HEADER #define BISON_HEADER
#include "util.hh" #include "util.hh"
#include "nixexpr.hh" #include "nixexpr.hh"
#include "eval.hh" #include "eval.hh"
#include <glog/logging.h>
namespace nix { namespace nix {
@ -681,24 +681,23 @@ std::pair<bool, std::string> EvalState::resolveSearchPathElem(const SearchPathEl
request.unpack = true; request.unpack = true;
res = { true, getDownloader()->downloadCached(store, request).path }; res = { true, getDownloader()->downloadCached(store, request).path };
} catch (DownloadError & e) { } catch (DownloadError & e) {
printError(format("warning: Nix search path entry '%1%' cannot be downloaded, ignoring") % elem.second); LOG(WARNING) << "Nix search path entry '" << elem.second << "' cannot be downloaded, ignoring";
res = { false, "" }; res = { false, "" };
} }
} else { } else {
auto path = absPath(elem.second); auto path = absPath(elem.second);
if (pathExists(path)) if (pathExists(path)) {
res = { true, path }; res = { true, path };
else { } else {
printError(format("warning: Nix search path entry '%1%' does not exist, ignoring") % elem.second); LOG(WARNING) << "Nix search path entry '" << elem.second << "' does not exist, ignoring";
res = { false, "" }; res = { false, "" };
} }
} }
debug(format("resolved search path element '%s' to '%s'") % elem.second % res.second); DLOG(INFO) << "resolved search path element '" << elem.second << "' to '" << res.second << "'";
searchPathResolved[elem.second] = res; searchPathResolved[elem.second] = res;
return res; return res;
} }
} // namespace nix
}

View file

@ -19,6 +19,7 @@
#include "util.hh" #include "util.hh"
#include "value-to-json.hh" #include "value-to-json.hh"
#include "value-to-xml.hh" #include "value-to-xml.hh"
#include <glog/logging.h>
namespace nix { namespace nix {
@ -139,7 +140,7 @@ static void prim_scopedImport(EvalState& state, const Pos& pos, Value** args,
env->values[displ++] = attr.value; env->values[displ++] = attr.value;
} }
printTalkative("evaluating file '%1%'", realPath); DLOG(INFO) << "evaluating file '" << realPath << "'";
Expr* e = state.parseExprFromFile(resolveExprPath(realPath), staticEnv); Expr* e = state.parseExprFromFile(resolveExprPath(realPath), staticEnv);
e->eval(state, *env, v); e->eval(state, *env, v);
@ -504,10 +505,11 @@ static void prim_deepSeq(EvalState& state, const Pos& pos, Value** args,
static void prim_trace(EvalState& state, const Pos& pos, Value** args, static void prim_trace(EvalState& state, const Pos& pos, Value** args,
Value& v) { Value& v) {
state.forceValue(*args[0]); state.forceValue(*args[0]);
if (args[0]->type == tString) if (args[0]->type == tString) {
printError(format("trace: %1%") % args[0]->string.s); DLOG(INFO) << "trace: " << args[0]->string.s;
else } else {
printError(format("trace: %1%") % *args[0]); DLOG(INFO)<< "trace: " << *args[0];
}
state.forceValue(*args[1]); state.forceValue(*args[1]);
v = *args[1]; v = *args[1];
} }
@ -575,7 +577,6 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
for (auto& i : args[0]->attrs->lexicographicOrder()) { for (auto& i : args[0]->attrs->lexicographicOrder()) {
if (i->name == state.sIgnoreNulls) continue; if (i->name == state.sIgnoreNulls) continue;
const string& key = i->name; const string& key = i->name;
vomit("processing attribute '%1%'", key);
auto handleHashMode = [&](const std::string& s) { auto handleHashMode = [&](const std::string& s) {
if (s == "recursive") if (s == "recursive")
@ -781,8 +782,7 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
/* Write the resulting term into the Nix store directory. */ /* Write the resulting term into the Nix store directory. */
Path drvPath = writeDerivation(state.store, drv, drvName, state.repair); Path drvPath = writeDerivation(state.store, drv, drvName, state.repair);
printMsg(lvlChatty, DLOG(INFO) << "instantiated '" << drvName << "' -> '" << drvPath << "'";
format("instantiated '%1%' -> '%2%'") % drvName % drvPath);
/* Optimisation, but required in read-only mode! because in that /* Optimisation, but required in read-only mode! because in that
case we don't actually write store derivations, so we can't case we don't actually write store derivations, so we can't

View file

@ -7,6 +7,7 @@
#include "pathlocks.hh" #include "pathlocks.hh"
#include "primops.hh" #include "primops.hh"
#include "store-api.hh" #include "store-api.hh"
#include <glog/logging.h>
using namespace std::string_literals; using namespace std::string_literals;
@ -119,8 +120,7 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
(uint64_t)st.st_mtime + settings.tarballTtl <= (uint64_t)now; (uint64_t)st.st_mtime + settings.tarballTtl <= (uint64_t)now;
} }
if (doFetch) { if (doFetch) {
Activity act(*logger, lvlTalkative, actUnknown, DLOG(INFO) << "fetching Git repository '" << uri << "'";
fmt("fetching Git repository '%s'", uri));
// FIXME: git stderr messes up our progress indicator, so // FIXME: git stderr messes up our progress indicator, so
// we're using --quiet for now. Should process its stderr. // we're using --quiet for now. Should process its stderr.
@ -142,7 +142,7 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
gitInfo.rev = rev != "" ? rev : chomp(readFile(localRefFile)); gitInfo.rev = rev != "" ? rev : chomp(readFile(localRefFile));
gitInfo.shortRev = std::string(gitInfo.rev, 0, 7); gitInfo.shortRev = std::string(gitInfo.rev, 0, 7);
printTalkative("using revision %s of repo '%s'", gitInfo.rev, uri); DLOG(INFO) << "using revision " << gitInfo.rev << " of repo '" << uri << "'";
std::string storeLinkName = std::string storeLinkName =
hashString(htSHA512, name + std::string("\0"s) + gitInfo.rev) hashString(htSHA512, name + std::string("\0"s) + gitInfo.rev)

View file

@ -1,3 +1,4 @@
#include <glog/logging.h>
#include <sys/time.h> #include <sys/time.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <regex> #include <regex>
@ -36,7 +37,7 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
/* This is an unclean working tree. So copy all tracked /* This is an unclean working tree. So copy all tracked
files. */ files. */
printTalkative("copying unclean Mercurial working tree '%s'", uri); DLOG(INFO) << "copying unclean Mercurial working tree '" << uri << "'";
HgInfo hgInfo; HgInfo hgInfo;
hgInfo.rev = "0000000000000000000000000000000000000000"; hgInfo.rev = "0000000000000000000000000000000000000000";
@ -91,8 +92,7 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
"--template", "1"}) "--template", "1"})
.killStderr(true)) .killStderr(true))
.second == "1")) { .second == "1")) {
Activity act(*logger, lvlTalkative, actUnknown, DLOG(INFO) << "fetching Mercurial repository '" << uri << "'";
fmt("fetching Mercurial repository '%s'", uri));
if (pathExists(cacheDir)) { if (pathExists(cacheDir)) {
try { try {
@ -141,8 +141,7 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
hgInfo.storePath = json["storePath"]; hgInfo.storePath = json["storePath"];
if (store->isValidPath(hgInfo.storePath)) { if (store->isValidPath(hgInfo.storePath)) {
printTalkative("using cached Mercurial store path '%s'", DLOG(INFO) << "using cached Mercurial store path '" << hgInfo.storePath << "'";
hgInfo.storePath);
return hgInfo; return hgInfo;
} }