refactor(3p/nix/libmain): Replace logging.h with glog
This commit is contained in:
parent
505b6b044b
commit
d0c44425e1
4 changed files with 58 additions and 98 deletions
21
third_party/nix/src/libmain/common-args.cc
vendored
21
third_party/nix/src/libmain/common-args.cc
vendored
|
@ -1,28 +1,11 @@
|
||||||
#include "common-args.hh"
|
#include "common-args.hh"
|
||||||
|
#include <glog/logging.h>
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
MixCommonArgs::MixCommonArgs(const string& programName)
|
MixCommonArgs::MixCommonArgs(const string& programName)
|
||||||
: programName(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()
|
mkFlag()
|
||||||
.longName("option")
|
.longName("option")
|
||||||
.labels({"name", "value"})
|
.labels({"name", "value"})
|
||||||
|
@ -32,7 +15,7 @@ MixCommonArgs::MixCommonArgs(const string& programName)
|
||||||
try {
|
try {
|
||||||
globalConfig.set(ss[0], ss[1]);
|
globalConfig.set(ss[0], ss[1]);
|
||||||
} catch (UsageError& e) {
|
} catch (UsageError& e) {
|
||||||
warn(e.what());
|
LOG(WARNING) << e.what();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
47
third_party/nix/src/libmain/meson.build
vendored
47
third_party/nix/src/libmain/meson.build
vendored
|
@ -1,12 +1,3 @@
|
||||||
# Nix lib store build file
|
|
||||||
#============================================================================
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# src files
|
|
||||||
#============================================================================
|
|
||||||
|
|
||||||
src_inc += include_directories('.')
|
src_inc += include_directories('.')
|
||||||
|
|
||||||
libmain_src = files(
|
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/common-args.hh'),
|
||||||
join_paths(meson.source_root(), 'src/libmain/shared.hh'))
|
join_paths(meson.source_root(), 'src/libmain/shared.hh'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# dependancies
|
|
||||||
#============================================================================
|
|
||||||
|
|
||||||
libmain_dep_list = [
|
libmain_dep_list = [
|
||||||
|
glog_dep,
|
||||||
pthread_dep,
|
pthread_dep,
|
||||||
openssl_dep,
|
openssl_dep,
|
||||||
libsodium_dep]
|
libsodium_dep,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Link args
|
|
||||||
#============================================================================
|
|
||||||
|
|
||||||
libmain_link_list = [
|
libmain_link_list = [
|
||||||
libutil_lib,
|
libutil_lib,
|
||||||
libstore_lib
|
libstore_lib,
|
||||||
]
|
]
|
||||||
|
|
||||||
libmain_link_args = []
|
libmain_link_args = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# compiler args
|
|
||||||
#============================================================================
|
|
||||||
|
|
||||||
libstore_cxx_args = []
|
libstore_cxx_args = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# targets
|
|
||||||
#============================================================================
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# build
|
|
||||||
#============================================================================
|
|
||||||
|
|
||||||
libmain_lib = library(
|
libmain_lib = library(
|
||||||
'nixmain',
|
'nixmain',
|
||||||
install : true,
|
install : true,
|
||||||
|
|
82
third_party/nix/src/libmain/shared.cc
vendored
82
third_party/nix/src/libmain/shared.cc
vendored
|
@ -1,4 +1,5 @@
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
|
#include <glog/logging.h>
|
||||||
#include <openssl/crypto.h>
|
#include <openssl/crypto.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -20,53 +21,66 @@ static bool gcWarning = true;
|
||||||
|
|
||||||
void printGCWarning() {
|
void printGCWarning() {
|
||||||
if (!gcWarning) return;
|
if (!gcWarning) return;
|
||||||
|
|
||||||
static bool haveWarned = false;
|
static bool haveWarned = false;
|
||||||
warnOnce(haveWarned,
|
if (!haveWarned) {
|
||||||
"you did not specify '--add-root'; "
|
haveWarned = true;
|
||||||
"the result might be removed by the garbage collector");
|
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;
|
unsigned long long downloadSize, narSize;
|
||||||
PathSet willBuild, willSubstitute, unknown;
|
PathSet willBuild, willSubstitute, unknown;
|
||||||
store->queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize,
|
store->queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize,
|
||||||
narSize);
|
narSize);
|
||||||
printMissing(store, willBuild, willSubstitute, unknown, downloadSize, narSize,
|
printMissing(store, willBuild, willSubstitute, unknown, downloadSize,
|
||||||
lvl);
|
narSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printMissing(ref<Store> store, const PathSet& willBuild,
|
void printMissing(ref<Store> store, const PathSet& willBuild,
|
||||||
const PathSet& willSubstitute, const PathSet& unknown,
|
const PathSet& willSubstitute, const PathSet& unknown,
|
||||||
unsigned long long downloadSize, unsigned long long narSize,
|
unsigned long long downloadSize, unsigned long long narSize) {
|
||||||
Verbosity lvl) {
|
|
||||||
if (!willBuild.empty()) {
|
if (!willBuild.empty()) {
|
||||||
printMsg(lvl, "these derivations will be built:");
|
LOG(INFO) << "these derivations will be built:";
|
||||||
Paths sorted = store->topoSortPaths(willBuild);
|
Paths sorted = store->topoSortPaths(willBuild);
|
||||||
reverse(sorted.begin(), sorted.end());
|
reverse(sorted.begin(), sorted.end());
|
||||||
for (auto& i : sorted) printMsg(lvl, fmt(" %s", i));
|
for (auto& i : sorted) {
|
||||||
|
LOG(INFO) << " " << i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!willSubstitute.empty()) {
|
if (!willSubstitute.empty()) {
|
||||||
printMsg(lvl, fmt("these paths will be fetched (%.2f MiB download, %.2f "
|
LOG(INFO) << "these paths will be fetched ("
|
||||||
"MiB unpacked):",
|
<< (downloadSize / (1024.0 * 1024.0)) << " MiB download, "
|
||||||
downloadSize / (1024.0 * 1024.0),
|
<< (narSize / (1024.0 * 1024.0)) << "MiB unpacked):";
|
||||||
narSize / (1024.0 * 1024.0)));
|
|
||||||
for (auto& i : willSubstitute) printMsg(lvl, fmt(" %s", i));
|
for (auto& i : willSubstitute) {
|
||||||
|
LOG(INFO) << i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!unknown.empty()) {
|
if (!unknown.empty()) {
|
||||||
printMsg(lvl, fmt("don't know how to build these paths%s:",
|
LOG(INFO) << "don't know how to build these paths"
|
||||||
(settings.readOnlyMode
|
<< (settings.readOnlyMode
|
||||||
? " (may be caused by read-only store access)"
|
? " (may be caused by read-only store access)"
|
||||||
: "")));
|
: "")
|
||||||
for (auto& i : unknown) printMsg(lvl, fmt(" %s", i));
|
<< ":";
|
||||||
|
|
||||||
|
for (auto& i : unknown) {
|
||||||
|
LOG(INFO) << i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string getArg(const string& opt, Strings::iterator& i,
|
string getArg(const string& opt, Strings::iterator& i,
|
||||||
const Strings::iterator& end) {
|
const Strings::iterator& end) {
|
||||||
++i;
|
++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;
|
return *i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +250,9 @@ void parseCmdLine(
|
||||||
|
|
||||||
void printVersion(const string& programName) {
|
void printVersion(const string& programName) {
|
||||||
std::cout << format("%1% (Nix) %2%") % programName % nixVersion << std::endl;
|
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;
|
Strings cfg;
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
cfg.push_back("gc");
|
cfg.push_back("gc");
|
||||||
|
@ -249,7 +265,7 @@ void printVersion(const string& programName) {
|
||||||
<< "\n";
|
<< "\n";
|
||||||
std::cout << "Store directory: " << settings.nixStore << "\n";
|
std::cout << "Store directory: " << settings.nixStore << "\n";
|
||||||
std::cout << "State directory: " << settings.nixStateDir << "\n";
|
std::cout << "State directory: " << settings.nixStateDir << "\n";
|
||||||
}
|
} */
|
||||||
throw Exit();
|
throw Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,20 +294,21 @@ int handleExceptions(const string& programName, std::function<void()> fun) {
|
||||||
} catch (Exit& e) {
|
} catch (Exit& e) {
|
||||||
return e.status;
|
return e.status;
|
||||||
} catch (UsageError& e) {
|
} catch (UsageError& e) {
|
||||||
printError(format(error + "%1%\nTry '%2% --help' for more information.") %
|
LOG(INFO) << e.what();
|
||||||
e.what() % programName);
|
LOG(INFO) << "Try '"
|
||||||
|
<< " --help' for more information." << programName;
|
||||||
return 1;
|
return 1;
|
||||||
} catch (BaseError& e) {
|
} catch (BaseError& e) {
|
||||||
printError(format(error + "%1%%2%") %
|
LOG(ERROR) << error << (settings.showTrace ? e.prefix() : "") << e.msg();
|
||||||
(settings.showTrace ? e.prefix() : "") % e.msg());
|
if (e.prefix() != "" && !settings.showTrace) {
|
||||||
if (e.prefix() != "" && !settings.showTrace)
|
LOG(INFO) << "(use '--show-trace' to show detailed location information)";
|
||||||
printError("(use '--show-trace' to show detailed location information)");
|
}
|
||||||
return e.status;
|
return e.status;
|
||||||
} catch (std::bad_alloc& e) {
|
} catch (std::bad_alloc& e) {
|
||||||
printError(error + "out of memory");
|
LOG(ERROR) << error << "out of memory";
|
||||||
return 1;
|
return 1;
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
printError(error + e.what());
|
LOG(ERROR) << error << e.what();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,9 +359,10 @@ string showBytes(unsigned long long bytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintFreed::~PrintFreed() {
|
PrintFreed::~PrintFreed() {
|
||||||
if (show)
|
if (show) {
|
||||||
std::cout << format("%1% store paths deleted, %2% freed\n") %
|
std::cout << format("%1% store paths deleted, %2% freed\n") %
|
||||||
results.paths.size() % showBytes(results.bytesFreed);
|
results.paths.size() % showBytes(results.bytesFreed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Exit::~Exit() {}
|
Exit::~Exit() {}
|
||||||
|
|
6
third_party/nix/src/libmain/shared.hh
vendored
6
third_party/nix/src/libmain/shared.hh
vendored
|
@ -38,13 +38,11 @@ void printGCWarning();
|
||||||
|
|
||||||
class Store;
|
class Store;
|
||||||
|
|
||||||
void printMissing(ref<Store> store, const PathSet& paths,
|
void printMissing(ref<Store> store, const PathSet& paths);
|
||||||
Verbosity lvl = lvlInfo);
|
|
||||||
|
|
||||||
void printMissing(ref<Store> store, const PathSet& willBuild,
|
void printMissing(ref<Store> store, const PathSet& willBuild,
|
||||||
const PathSet& willSubstitute, const PathSet& unknown,
|
const PathSet& willSubstitute, const PathSet& unknown,
|
||||||
unsigned long long downloadSize, unsigned long long narSize,
|
unsigned long long downloadSize, unsigned long long narSize);
|
||||||
Verbosity lvl = lvlInfo);
|
|
||||||
|
|
||||||
string getArg(const string& opt, Strings::iterator& i,
|
string getArg(const string& opt, Strings::iterator& i,
|
||||||
const Strings::iterator& end);
|
const Strings::iterator& end);
|
||||||
|
|
Loading…
Reference in a new issue