about summary refs log tree commit diff
path: root/third_party
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-19T00·03+0100
committerVincent Ambo <tazjin@google.com>2020-05-19T00·04+0100
commitd0c44425e147ab7d38410f400825ad20da15037b (patch)
treefc274eeb9c1a35d43cf4bb9383229e36ff094245 /third_party
parent505b6b044b132b28e1501491bcfe6bd68ca1989e (diff)
refactor(3p/nix/libmain): Replace logging.h with glog r/757
Diffstat (limited to 'third_party')
-rw-r--r--third_party/nix/src/libmain/common-args.cc21
-rw-r--r--third_party/nix/src/libmain/meson.build47
-rw-r--r--third_party/nix/src/libmain/shared.cc82
-rw-r--r--third_party/nix/src/libmain/shared.hh6
4 files changed, 58 insertions, 98 deletions
diff --git a/third_party/nix/src/libmain/common-args.cc b/third_party/nix/src/libmain/common-args.cc
index e4c7c6daf6..bbd73cc840 100644
--- a/third_party/nix/src/libmain/common-args.cc
+++ b/third_party/nix/src/libmain/common-args.cc
@@ -1,4 +1,5 @@
 #include "common-args.hh"
+#include <glog/logging.h>
 #include "globals.hh"
 
 namespace nix {
@@ -6,24 +7,6 @@ namespace nix {
 MixCommonArgs::MixCommonArgs(const string& programName)
     : programName(programName) {
   mkFlag()
-      .longName("verbose")
-      .shortName('v')
-      .description("increase verbosity level")
-      .handler([]() { verbosity = (Verbosity)(verbosity + 1); });
-
-  mkFlag()
-      .longName("quiet")
-      .description("decrease verbosity level")
-      .handler([]() {
-        verbosity =
-            verbosity > lvlError ? (Verbosity)(verbosity - 1) : lvlError;
-      });
-
-  mkFlag().longName("debug").description("enable debug output").handler([]() {
-    verbosity = lvlDebug;
-  });
-
-  mkFlag()
       .longName("option")
       .labels({"name", "value"})
       .description("set a Nix configuration option (overriding nix.conf)")
@@ -32,7 +15,7 @@ MixCommonArgs::MixCommonArgs(const string& programName)
         try {
           globalConfig.set(ss[0], ss[1]);
         } catch (UsageError& e) {
-          warn(e.what());
+          LOG(WARNING) << e.what();
         }
       });
 
diff --git a/third_party/nix/src/libmain/meson.build b/third_party/nix/src/libmain/meson.build
index ec510ee2e5..0524301059 100644
--- a/third_party/nix/src/libmain/meson.build
+++ b/third_party/nix/src/libmain/meson.build
@@ -1,12 +1,3 @@
-# Nix lib store build file
-#============================================================================
-
-
-
-
-# src files
-#============================================================================
-
 src_inc += include_directories('.')
 
 libmain_src = files(
@@ -18,51 +9,21 @@ libmain_headers = files(
     join_paths(meson.source_root(), 'src/libmain/common-args.hh'),
     join_paths(meson.source_root(), 'src/libmain/shared.hh'))
 
-
-
-
-# dependancies
-#============================================================================
-
 libmain_dep_list = [
+    glog_dep,
     pthread_dep,
     openssl_dep,
-    libsodium_dep]
-
-
-
-
-
-# Link args
-#============================================================================
+    libsodium_dep,
+]
 
 libmain_link_list = [
     libutil_lib,
-    libstore_lib
+    libstore_lib,
 ]
 
 libmain_link_args = []
-
-
-
-
-# compiler args
-#============================================================================
-
 libstore_cxx_args = []
 
-
-
-
-# targets
-#============================================================================
-
-
-
-
-# build
-#============================================================================
-
 libmain_lib = library(
     'nixmain',
     install : true,
diff --git a/third_party/nix/src/libmain/shared.cc b/third_party/nix/src/libmain/shared.cc
index 72b84e28e0..fee18c5f1a 100644
--- a/third_party/nix/src/libmain/shared.cc
+++ b/third_party/nix/src/libmain/shared.cc
@@ -1,4 +1,5 @@
 #include "shared.hh"
+#include <glog/logging.h>
 #include <openssl/crypto.h>
 #include <signal.h>
 #include <sys/stat.h>
@@ -20,53 +21,66 @@ static bool gcWarning = true;
 
 void printGCWarning() {
   if (!gcWarning) return;
+
   static bool haveWarned = false;
-  warnOnce(haveWarned,
-           "you did not specify '--add-root'; "
-           "the result might be removed by the garbage collector");
+  if (!haveWarned) {
+    haveWarned = true;
+    LOG(WARNING) << "you did not specify '--add-root'; "
+                 << "the result might be removed by the garbage collector";
+  }
 }
 
-void printMissing(ref<Store> store, const PathSet& paths, Verbosity lvl) {
+void printMissing(ref<Store> store, const PathSet& paths) {
   unsigned long long downloadSize, narSize;
   PathSet willBuild, willSubstitute, unknown;
   store->queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize,
                       narSize);
-  printMissing(store, willBuild, willSubstitute, unknown, downloadSize, narSize,
-               lvl);
+  printMissing(store, willBuild, willSubstitute, unknown, downloadSize,
+               narSize);
 }
 
 void printMissing(ref<Store> store, const PathSet& willBuild,
                   const PathSet& willSubstitute, const PathSet& unknown,
-                  unsigned long long downloadSize, unsigned long long narSize,
-                  Verbosity lvl) {
+                  unsigned long long downloadSize, unsigned long long narSize) {
   if (!willBuild.empty()) {
-    printMsg(lvl, "these derivations will be built:");
+    LOG(INFO) << "these derivations will be built:";
     Paths sorted = store->topoSortPaths(willBuild);
     reverse(sorted.begin(), sorted.end());
-    for (auto& i : sorted) printMsg(lvl, fmt("  %s", i));
+    for (auto& i : sorted) {
+      LOG(INFO) << "  " << i;
+    }
   }
 
   if (!willSubstitute.empty()) {
-    printMsg(lvl, fmt("these paths will be fetched (%.2f MiB download, %.2f "
-                      "MiB unpacked):",
-                      downloadSize / (1024.0 * 1024.0),
-                      narSize / (1024.0 * 1024.0)));
-    for (auto& i : willSubstitute) printMsg(lvl, fmt("  %s", i));
+    LOG(INFO) << "these paths will be fetched ("
+              << (downloadSize / (1024.0 * 1024.0)) << " MiB download, "
+              << (narSize / (1024.0 * 1024.0)) << "MiB unpacked):";
+
+    for (auto& i : willSubstitute) {
+      LOG(INFO) << i;
+    }
   }
 
   if (!unknown.empty()) {
-    printMsg(lvl, fmt("don't know how to build these paths%s:",
-                      (settings.readOnlyMode
-                           ? " (may be caused by read-only store access)"
-                           : "")));
-    for (auto& i : unknown) printMsg(lvl, fmt("  %s", i));
+    LOG(INFO) << "don't know how to build these paths"
+              << (settings.readOnlyMode
+                      ? " (may be caused by read-only store access)"
+                      : "")
+              << ":";
+
+    for (auto& i : unknown) {
+      LOG(INFO) << i;
+    }
   }
 }
 
 string getArg(const string& opt, Strings::iterator& i,
               const Strings::iterator& end) {
   ++i;
-  if (i == end) throw UsageError(format("'%1%' requires an argument") % opt);
+  if (i == end) {
+    throw UsageError(format("'%1%' requires an argument") % opt);
+  }
+
   return *i;
 }
 
@@ -236,7 +250,9 @@ void parseCmdLine(
 
 void printVersion(const string& programName) {
   std::cout << format("%1% (Nix) %2%") % programName % nixVersion << std::endl;
-  if (verbosity > lvlInfo) {
+
+  // TODO(tazjin): figure out what the fuck this is
+  /*if (verbosity > lvlInfo) {
     Strings cfg;
 #if HAVE_BOEHMGC
     cfg.push_back("gc");
@@ -249,7 +265,7 @@ void printVersion(const string& programName) {
               << "\n";
     std::cout << "Store directory: " << settings.nixStore << "\n";
     std::cout << "State directory: " << settings.nixStateDir << "\n";
-  }
+    } */
   throw Exit();
 }
 
@@ -278,20 +294,21 @@ int handleExceptions(const string& programName, std::function<void()> fun) {
   } catch (Exit& e) {
     return e.status;
   } catch (UsageError& e) {
-    printError(format(error + "%1%\nTry '%2% --help' for more information.") %
-               e.what() % programName);
+    LOG(INFO) << e.what();
+    LOG(INFO) << "Try '"
+              << " --help' for more information." << programName;
     return 1;
   } catch (BaseError& e) {
-    printError(format(error + "%1%%2%") %
-               (settings.showTrace ? e.prefix() : "") % e.msg());
-    if (e.prefix() != "" && !settings.showTrace)
-      printError("(use '--show-trace' to show detailed location information)");
+    LOG(ERROR) << error << (settings.showTrace ? e.prefix() : "") << e.msg();
+    if (e.prefix() != "" && !settings.showTrace) {
+      LOG(INFO) << "(use '--show-trace' to show detailed location information)";
+    }
     return e.status;
   } catch (std::bad_alloc& e) {
-    printError(error + "out of memory");
+    LOG(ERROR) << error << "out of memory";
     return 1;
   } catch (std::exception& e) {
-    printError(error + e.what());
+    LOG(ERROR) << error << e.what();
     return 1;
   }
 
@@ -342,9 +359,10 @@ string showBytes(unsigned long long bytes) {
 }
 
 PrintFreed::~PrintFreed() {
-  if (show)
+  if (show) {
     std::cout << format("%1% store paths deleted, %2% freed\n") %
                      results.paths.size() % showBytes(results.bytesFreed);
+  }
 }
 
 Exit::~Exit() {}
diff --git a/third_party/nix/src/libmain/shared.hh b/third_party/nix/src/libmain/shared.hh
index 8f895109d7..68d4c49cf6 100644
--- a/third_party/nix/src/libmain/shared.hh
+++ b/third_party/nix/src/libmain/shared.hh
@@ -38,13 +38,11 @@ void printGCWarning();
 
 class Store;
 
-void printMissing(ref<Store> store, const PathSet& paths,
-                  Verbosity lvl = lvlInfo);
+void printMissing(ref<Store> store, const PathSet& paths);
 
 void printMissing(ref<Store> store, const PathSet& willBuild,
                   const PathSet& willSubstitute, const PathSet& unknown,
-                  unsigned long long downloadSize, unsigned long long narSize,
-                  Verbosity lvl = lvlInfo);
+                  unsigned long long downloadSize, unsigned long long narSize);
 
 string getArg(const string& opt, Strings::iterator& i,
               const Strings::iterator& end);