From 939dd9f8176266add4d88572203739fa74b14fa5 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 19 May 2020 01:24:50 +0100 Subject: refactor(3p/nix/libexpr): Replace logging.h with glog --- third_party/nix/src/libexpr/eval.cc | 10 +++++----- third_party/nix/src/libexpr/function-trace.cc | 5 +++-- third_party/nix/src/libexpr/get-drvs.cc | 3 ++- third_party/nix/src/libexpr/meson.build | 4 +++- third_party/nix/src/libexpr/parser.y | 19 +++++++++---------- third_party/nix/src/libexpr/primops.cc | 16 ++++++++-------- third_party/nix/src/libexpr/primops/fetchGit.cc | 6 +++--- third_party/nix/src/libexpr/primops/fetchMercurial.cc | 9 ++++----- 8 files changed, 37 insertions(+), 35 deletions(-) (limited to 'third_party/nix/src') diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc index 14b600b06ec4..5aefc120e2c7 100644 --- a/third_party/nix/src/libexpr/eval.cc +++ b/third_party/nix/src/libexpr/eval.cc @@ -16,6 +16,7 @@ #include "json.hh" #include "store-api.hh" #include "util.hh" +#include #if HAVE_BOEHMGC @@ -232,7 +233,7 @@ void initGC() { if (pageSize != -1) size = (pageSize * pages) / 4; // 25% of RAM if (size > maxSize) size = maxSize; #endif - debug(format("setting initial heap size to %1% bytes") % size); + DLOG(INFO) << "setting initial heap size to " << size << " bytes"; GC_expand_hp(size); } @@ -375,7 +376,7 @@ Path EvalState::checkSourcePath(const Path& path_) { "access to path '%1%' is forbidden in restricted mode", abspath); /* Resolve symlinks. */ - debug(format("checking access to '%s'") % abspath); + DLOG(INFO) << "checking access to '" << abspath << "'"; Path path = canonPath(abspath, true); for (auto& i : *allowedPaths) { @@ -689,7 +690,7 @@ void EvalState::evalFile(const Path& path_, Value& v) { return; } - printTalkative("evaluating file '%1%'", path2); + DLOG(INFO) << "evaluating file '" << path2 << "'"; Expr* e = nullptr; auto j = fileParseCache.find(path2); @@ -1530,8 +1531,7 @@ string EvalState::copyPathToStore(PathSet& context, const Path& path) { : store->addToStore(baseNameOf(path), checkSourcePath(path), true, htSHA256, defaultPathFilter, repair); srcToStore[path] = dstPath; - printMsg(lvlChatty, - format("copied source '%1%' -> '%2%'") % path % dstPath); + DLOG(INFO) << "copied source '" << path << "' -> '" << dstPath << "'"; } context.insert(dstPath); diff --git a/third_party/nix/src/libexpr/function-trace.cc b/third_party/nix/src/libexpr/function-trace.cc index 2bc0d943f339..4f164e6c4498 100644 --- a/third_party/nix/src/libexpr/function-trace.cc +++ b/third_party/nix/src/libexpr/function-trace.cc @@ -1,17 +1,18 @@ #include "function-trace.hh" +#include namespace nix { FunctionCallTrace::FunctionCallTrace(const Pos& pos) : pos(pos) { auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); auto ns = std::chrono::duration_cast(duration); - printMsg(lvlInfo, "function-trace entered %1% at %2%", pos, ns.count()); + LOG(INFO) << "function-trace entered " << pos << " at " << ns.count(); } FunctionCallTrace::~FunctionCallTrace() { auto duration = std::chrono::high_resolution_clock::now().time_since_epoch(); auto ns = std::chrono::duration_cast(duration); - printMsg(lvlInfo, "function-trace exited %1% at %2%", pos, ns.count()); + LOG(INFO) << "function-trace exited " << pos << " at " << ns.count(); } } // namespace nix diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc index cdbcb7d76275..b25556b34c07 100644 --- a/third_party/nix/src/libexpr/get-drvs.cc +++ b/third_party/nix/src/libexpr/get-drvs.cc @@ -4,6 +4,7 @@ #include "derivations.hh" #include "eval-inline.hh" #include "util.hh" +#include namespace nix { @@ -301,7 +302,7 @@ static void getDerivations(EvalState& state, Value& vIn, bound to the attribute with the "lower" name should take precedence). */ 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; string pathPrefix2 = addToPath(pathPrefix, i->name); if (combineChannels) diff --git a/third_party/nix/src/libexpr/meson.build b/third_party/nix/src/libexpr/meson.build index 76f3014388c7..7ddd4cff4ecb 100644 --- a/third_party/nix/src/libexpr/meson.build +++ b/third_party/nix/src/libexpr/meson.build @@ -39,8 +39,10 @@ libexpr_headers = files( libexpr_dep_list = [ gc_dep, + glog_dep, libdl_dep, - libsodium_dep] + libsodium_dep, +] if sys_name == 'freebsd' libexpr_dep_list += libdl_dep diff --git a/third_party/nix/src/libexpr/parser.y b/third_party/nix/src/libexpr/parser.y index 967c88d9bc80..ddcd1a4dae74 100644 --- a/third_party/nix/src/libexpr/parser.y +++ b/third_party/nix/src/libexpr/parser.y @@ -17,9 +17,9 @@ #define BISON_HEADER #include "util.hh" - #include "nixexpr.hh" #include "eval.hh" +#include namespace nix { @@ -681,24 +681,23 @@ std::pair EvalState::resolveSearchPathElem(const SearchPathEl request.unpack = true; res = { true, getDownloader()->downloadCached(store, request).path }; } catch (DownloadError & e) { - printError(format("warning: Nix search path entry '%1%' cannot be downloaded, ignoring") % elem.second); - res = { false, "" }; + LOG(WARNING) << "Nix search path entry '" << elem.second << "' cannot be downloaded, ignoring"; + res = { false, "" }; } } else { auto path = absPath(elem.second); - if (pathExists(path)) + if (pathExists(path)) { res = { true, path }; - else { - printError(format("warning: Nix search path entry '%1%' does not exist, ignoring") % elem.second); - res = { false, "" }; + } else { + LOG(WARNING) << "Nix search path entry '" << elem.second << "' does not exist, ignoring"; + 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; return res; } - -} +} // namespace nix diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index 9d6d4eaba5ee..05fa9c4828b3 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -19,6 +19,7 @@ #include "util.hh" #include "value-to-json.hh" #include "value-to-xml.hh" +#include namespace nix { @@ -139,7 +140,7 @@ static void prim_scopedImport(EvalState& state, const Pos& pos, Value** args, env->values[displ++] = attr.value; } - printTalkative("evaluating file '%1%'", realPath); + DLOG(INFO) << "evaluating file '" << realPath << "'"; Expr* e = state.parseExprFromFile(resolveExprPath(realPath), staticEnv); 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, Value& v) { state.forceValue(*args[0]); - if (args[0]->type == tString) - printError(format("trace: %1%") % args[0]->string.s); - else - printError(format("trace: %1%") % *args[0]); + if (args[0]->type == tString) { + DLOG(INFO) << "trace: " << args[0]->string.s; + } else { + DLOG(INFO)<< "trace: " << *args[0]; + } state.forceValue(*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()) { if (i->name == state.sIgnoreNulls) continue; const string& key = i->name; - vomit("processing attribute '%1%'", key); auto handleHashMode = [&](const std::string& s) { 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. */ Path drvPath = writeDerivation(state.store, drv, drvName, state.repair); - printMsg(lvlChatty, - format("instantiated '%1%' -> '%2%'") % drvName % drvPath); + DLOG(INFO) << "instantiated '" << drvName << "' -> '" << drvPath << "'"; /* Optimisation, but required in read-only mode! because in that case we don't actually write store derivations, so we can't diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc index e1edf9a3e58e..07a0770a3fca 100644 --- a/third_party/nix/src/libexpr/primops/fetchGit.cc +++ b/third_party/nix/src/libexpr/primops/fetchGit.cc @@ -7,6 +7,7 @@ #include "pathlocks.hh" #include "primops.hh" #include "store-api.hh" +#include using namespace std::string_literals; @@ -119,8 +120,7 @@ GitInfo exportGit(ref store, const std::string& uri, (uint64_t)st.st_mtime + settings.tarballTtl <= (uint64_t)now; } if (doFetch) { - Activity act(*logger, lvlTalkative, actUnknown, - fmt("fetching Git repository '%s'", uri)); + DLOG(INFO) << "fetching Git repository '" << uri << "'"; // FIXME: git stderr messes up our progress indicator, so // we're using --quiet for now. Should process its stderr. @@ -142,7 +142,7 @@ GitInfo exportGit(ref store, const std::string& uri, gitInfo.rev = rev != "" ? rev : chomp(readFile(localRefFile)); 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 = hashString(htSHA512, name + std::string("\0"s) + gitInfo.rev) diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc index 1ee12542ef32..677855e85369 100644 --- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc +++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc @@ -1,3 +1,4 @@ +#include #include #include #include @@ -36,7 +37,7 @@ HgInfo exportMercurial(ref store, const std::string& uri, /* This is an unclean working tree. So copy all tracked files. */ - printTalkative("copying unclean Mercurial working tree '%s'", uri); + DLOG(INFO) << "copying unclean Mercurial working tree '" << uri << "'"; HgInfo hgInfo; hgInfo.rev = "0000000000000000000000000000000000000000"; @@ -91,8 +92,7 @@ HgInfo exportMercurial(ref store, const std::string& uri, "--template", "1"}) .killStderr(true)) .second == "1")) { - Activity act(*logger, lvlTalkative, actUnknown, - fmt("fetching Mercurial repository '%s'", uri)); + DLOG(INFO) << "fetching Mercurial repository '" << uri << "'"; if (pathExists(cacheDir)) { try { @@ -141,8 +141,7 @@ HgInfo exportMercurial(ref store, const std::string& uri, hgInfo.storePath = json["storePath"]; if (store->isValidPath(hgInfo.storePath)) { - printTalkative("using cached Mercurial store path '%s'", - hgInfo.storePath); + DLOG(INFO) << "using cached Mercurial store path '" << hgInfo.storePath << "'"; return hgInfo; } -- cgit 1.4.1