aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-18 23:01:58 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-06-18 23:01:58 +0000
commit3f8dcfe3fd8372ee8fc1b3233c7e9982d1a6915d (patch)
tree5a104db035aede46168326978dd3bc387f9e49a7 /src/nix
parentd614166cb6864f2448b9e03f8dccccf301dc541e (diff)
parent669c3992e883414269d850bba5f00c59a1b207d0 (diff)
Merge branch 'validPathInfo-temp' into validPathInfo-ca-proper-datatype
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/add-to-store.cc2
-rw-r--r--src/nix/cat.cc4
-rw-r--r--src/nix/command.cc12
-rw-r--r--src/nix/copy.cc2
-rw-r--r--src/nix/develop.cc13
-rw-r--r--src/nix/hash.cc38
-rw-r--r--src/nix/installables.cc24
-rw-r--r--src/nix/local.mk2
-rw-r--r--src/nix/ls.cc2
-rw-r--r--src/nix/main.cc13
-rw-r--r--src/nix/make-content-addressable.cc14
-rw-r--r--src/nix/path-info.cc4
-rw-r--r--src/nix/progress-bar.cc474
-rw-r--r--src/nix/progress-bar.hh11
-rw-r--r--src/nix/repl.cc41
-rw-r--r--src/nix/run.cc10
-rw-r--r--src/nix/show-derivation.cc6
-rw-r--r--src/nix/sigs.cc2
-rw-r--r--src/nix/upgrade-nix.cc15
-rw-r--r--src/nix/verify.cc33
-rw-r--r--src/nix/why-depends.cc16
21 files changed, 130 insertions, 608 deletions
diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc
index e6f6ef27b..d1764167e 100644
--- a/src/nix/add-to-store.cc
+++ b/src/nix/add-to-store.cc
@@ -43,7 +43,7 @@ struct CmdAddToStore : MixDryRun, StoreCommand
StringSink sink;
dumpPath(path, sink);
- auto narHash = hashString(HashType::SHA256, *sink.s);
+ auto narHash = hashString(htSHA256, *sink.s);
ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, *namePart));
info.narHash = narHash;
diff --git a/src/nix/cat.cc b/src/nix/cat.cc
index fd91f2036..c82819af8 100644
--- a/src/nix/cat.cc
+++ b/src/nix/cat.cc
@@ -13,9 +13,9 @@ struct MixCat : virtual Args
{
auto st = accessor->stat(path);
if (st.type == FSAccessor::Type::tMissing)
- throw Error(format("path '%1%' does not exist") % path);
+ throw Error("path '%1%' does not exist", path);
if (st.type != FSAccessor::Type::tRegular)
- throw Error(format("path '%1%' is not a regular file") % path);
+ throw Error("path '%1%' is not a regular file", path);
std::cout << accessor->readFile(path);
}
diff --git a/src/nix/command.cc b/src/nix/command.cc
index 71b027719..3651a9e9c 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -4,7 +4,7 @@
#include "nixexpr.hh"
#include "profiles.hh"
-extern char * * environ;
+extern char * * environ __attribute__((weak));
namespace nix {
@@ -59,19 +59,19 @@ void StorePathsCommand::run(ref<Store> store)
if (installables.size())
throw UsageError("'--all' does not expect arguments");
for (auto & p : store->queryAllValidPaths())
- storePaths.push_back(p.clone());
+ storePaths.push_back(p);
}
else {
for (auto & p : toStorePaths(store, realiseMode, installables))
- storePaths.push_back(p.clone());
+ storePaths.push_back(p);
if (recursive) {
StorePathSet closure;
- store->computeFSClosure(storePathsToSet(storePaths), closure, false, false);
+ store->computeFSClosure(StorePathSet(storePaths.begin(), storePaths.end()), closure, false, false);
storePaths.clear();
for (auto & p : closure)
- storePaths.push_back(p.clone());
+ storePaths.push_back(p);
}
}
@@ -133,7 +133,7 @@ void MixProfile::updateProfile(const Buildables & buildables)
for (auto & output : buildable.outputs) {
if (result)
throw Error("'--profile' requires that the arguments produce a single store path, but there are multiple");
- result = output.second.clone();
+ result = output.second;
}
}
diff --git a/src/nix/copy.cc b/src/nix/copy.cc
index c7c38709d..64099f476 100644
--- a/src/nix/copy.cc
+++ b/src/nix/copy.cc
@@ -94,7 +94,7 @@ struct CmdCopy : StorePathsCommand
ref<Store> dstStore = dstUri.empty() ? openStore() : openStore(dstUri);
- copyPaths(srcStore, dstStore, storePathsToSet(storePaths),
+ copyPaths(srcStore, dstStore, StorePathSet(storePaths.begin(), storePaths.end()),
NoRepair, checkSigs, substitute);
}
};
diff --git a/src/nix/develop.cc b/src/nix/develop.cc
index adfb3558d..8abb710c2 100644
--- a/src/nix/develop.cc
+++ b/src/nix/develop.cc
@@ -135,14 +135,17 @@ StorePath getDerivationEnvironment(ref<Store> store, const StorePath & drvPath)
drv.inputSrcs.insert(std::move(getEnvShPath));
Hash h = hashDerivationModulo(*store, drv, true);
auto shellOutPath = store->makeOutputPath("out", h, drvName);
- drv.outputs.insert_or_assign("out", DerivationOutput(shellOutPath.clone(), FileSystemHash {
- FileIngestionMethod::Flat, Hash { }
- }));
+ drv.outputs.insert_or_assign("out", DerivationOutput {
+ .path = shellOutPath,
+ .hash = FileSystemHash {
+ FileIngestionMethod::Flat, Hash { }
+ },
+ });
drv.env["out"] = store->printStorePath(shellOutPath);
auto shellDrvPath2 = writeDerivation(store, drv, drvName);
/* Build the derivation. */
- store->buildPaths({shellDrvPath2});
+ store->buildPaths({{shellDrvPath2}});
assert(store->isValidPath(shellOutPath));
@@ -207,7 +210,7 @@ struct Common : InstallableCommand, MixProfile
{
auto path = installable->getStorePath();
if (path && hasSuffix(path->to_string(), "-env"))
- return path->clone();
+ return *path;
else {
auto drvs = toDerivations(store, {installable});
diff --git a/src/nix/hash.cc b/src/nix/hash.cc
index a36364f50..b97c6d21f 100644
--- a/src/nix/hash.cc
+++ b/src/nix/hash.cc
@@ -11,18 +11,18 @@ using namespace nix;
struct CmdHash : Command
{
FileIngestionMethod mode;
- Base base = Base::SRI;
+ Base base = SRI;
bool truncate = false;
- HashType ht = HashType::SHA256;
+ HashType ht = htSHA256;
std::vector<std::string> paths;
std::optional<std::string> modulus;
CmdHash(FileIngestionMethod mode) : mode(mode)
{
- mkFlag(0, "sri", "print hash in Base::SRI format", &base, Base::SRI);
- mkFlag(0, "base64", "print hash in base-64", &base, Base::Base64);
- mkFlag(0, "base32", "print hash in base-32 (Nix-specific)", &base, Base::Base32);
- mkFlag(0, "base16", "print hash in base-16", &base, Base::Base16);
+ mkFlag(0, "sri", "print hash in SRI format", &base, SRI);
+ mkFlag(0, "base64", "print hash in base-64", &base, Base64);
+ mkFlag(0, "base32", "print hash in base-32 (Nix-specific)", &base, Base32);
+ mkFlag(0, "base16", "print hash in base-16", &base, Base16);
addFlag(Flag::mkHashTypeFlag("type", &ht));
#if 0
mkFlag()
@@ -69,7 +69,7 @@ struct CmdHash : Command
Hash h = hashSink->finish().first;
if (truncate && h.hashSize > 20) h = compressHash(h, 20);
- logger->stdout(h.to_string(base, base == Base::SRI));
+ logger->stdout(h.to_string(base, base == SRI));
}
}
};
@@ -92,10 +92,10 @@ struct CmdToBase : Command
std::string description() override
{
return fmt("convert a hash to %s representation",
- base == Base::Base16 ? "base-16" :
- base == Base::Base32 ? "base-32" :
- base == Base::Base64 ? "base-64" :
- "Base::SRI");
+ base == Base16 ? "base-16" :
+ base == Base32 ? "base-32" :
+ base == Base64 ? "base-64" :
+ "SRI");
}
Category category() override { return catUtility; }
@@ -103,19 +103,19 @@ struct CmdToBase : Command
void run() override
{
for (auto s : args)
- logger->stdout(Hash(s, ht).to_string(base, base == Base::SRI));
+ logger->stdout(Hash(s, ht).to_string(base, base == SRI));
}
};
-static RegisterCommand r3("to-base16", [](){ return make_ref<CmdToBase>(Base::Base16); });
-static RegisterCommand r4("to-base32", [](){ return make_ref<CmdToBase>(Base::Base32); });
-static RegisterCommand r5("to-base64", [](){ return make_ref<CmdToBase>(Base::Base64); });
-static RegisterCommand r6("to-sri", [](){ return make_ref<CmdToBase>(Base::SRI); });
+static RegisterCommand r3("to-base16", [](){ return make_ref<CmdToBase>(Base16); });
+static RegisterCommand r4("to-base32", [](){ return make_ref<CmdToBase>(Base32); });
+static RegisterCommand r5("to-base64", [](){ return make_ref<CmdToBase>(Base64); });
+static RegisterCommand r6("to-sri", [](){ return make_ref<CmdToBase>(SRI); });
/* Legacy nix-hash command. */
static int compatNixHash(int argc, char * * argv)
{
- HashType ht = HashType::MD5;
+ HashType ht = htMD5;
bool flat = false;
bool base32 = false;
bool truncate = false;
@@ -146,14 +146,14 @@ static int compatNixHash(int argc, char * * argv)
if (op == opHash) {
CmdHash cmd(flat ? FileIngestionMethod::Flat : FileIngestionMethod::Recursive);
cmd.ht = ht;
- cmd.base = base32 ? Base::Base32 : Base::Base16;
+ cmd.base = base32 ? Base32 : Base16;
cmd.truncate = truncate;
cmd.paths = ss;
cmd.run();
}
else {
- CmdToBase cmd(op == opTo32 ? Base::Base32 : Base::Base16);
+ CmdToBase cmd(op == opTo32 ? Base32 : Base16);
cmd.args = ss;
cmd.ht = ht;
cmd.run();
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 17d15f5ee..708a0dc88 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -102,9 +102,9 @@ struct InstallableStorePath : Installable
Buildables toBuildables() override
{
std::map<std::string, StorePath> outputs;
- outputs.insert_or_assign("out", storePath.clone());
+ outputs.insert_or_assign("out", storePath);
Buildable b{
- .drvPath = storePath.isDerivation() ? storePath.clone() : std::optional<StorePath>(),
+ .drvPath = storePath.isDerivation() ? storePath : std::optional<StorePath>(),
.outputs = std::move(outputs)
};
Buildables bs;
@@ -114,7 +114,7 @@ struct InstallableStorePath : Installable
std::optional<StorePath> getStorePath() override
{
- return storePath.clone();
+ return storePath;
}
};
@@ -141,7 +141,7 @@ struct InstallableValue : Installable
for (auto & drv : drvs) {
Buildable b{.drvPath = state->store->parseStorePath(drv.queryDrvPath())};
- drvPaths.insert(b.drvPath->clone());
+ drvPaths.insert(*b.drvPath);
auto outputName = drv.queryOutputName();
if (outputName == "")
@@ -155,10 +155,10 @@ struct InstallableValue : Installable
// Hack to recognize .all: if all drvs have the same drvPath,
// merge the buildables.
if (drvPaths.size() == 1) {
- Buildable b{.drvPath = drvPaths.begin()->clone()};
+ Buildable b{.drvPath = *drvPaths.begin()};
for (auto & b2 : res)
for (auto & output : b2.outputs)
- b.outputs.insert_or_assign(output.first, output.second.clone());
+ b.outputs.insert_or_assign(output.first, output.second);
Buildables bs;
bs.push_back(std::move(b));
return bs;
@@ -273,13 +273,13 @@ Buildables build(ref<Store> store, RealiseMode mode,
pathsToBuild.push_back({*b.drvPath, outputNames});
} else
for (auto & output : b.outputs)
- pathsToBuild.push_back({output.second.clone()});
+ pathsToBuild.push_back({output.second});
buildables.push_back(std::move(b));
}
}
if (mode == DryRun)
- printMissing(store, pathsToBuild, Verbosity::Error);
+ printMissing(store, pathsToBuild, lvlError);
else if (mode == Build)
store->buildPaths(pathsToBuild);
@@ -293,7 +293,7 @@ StorePathSet toStorePaths(ref<Store> store, RealiseMode mode,
for (auto & b : build(store, mode, installables))
for (auto & output : b.outputs)
- outPaths.insert(output.second.clone());
+ outPaths.insert(output.second);
return outPaths;
}
@@ -306,7 +306,7 @@ StorePath toStorePath(ref<Store> store, RealiseMode mode,
if (paths.size() != 1)
throw Error("argument '%s' should evaluate to one store path", installable->what());
- return paths.begin()->clone();
+ return *paths.begin();
}
StorePathSet toDerivations(ref<Store> store,
@@ -324,10 +324,10 @@ StorePathSet toDerivations(ref<Store> store,
if (derivers.empty())
throw Error("'%s' does not have a known deriver", i->what());
// FIXME: use all derivers?
- drvPaths.insert(derivers.begin()->clone());
+ drvPaths.insert(*derivers.begin());
}
} else
- drvPaths.insert(b.drvPath->clone());
+ drvPaths.insert(*b.drvPath);
}
return drvPaths;
diff --git a/src/nix/local.mk b/src/nix/local.mk
index 43b7754e3..b057b7cc6 100644
--- a/src/nix/local.mk
+++ b/src/nix/local.mk
@@ -17,7 +17,7 @@ nix_SOURCES := \
nix_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/libexpr -I src/libmain
-nix_LIBS = libexpr libmain libfetchers libstore libutil libnixrust
+nix_LIBS = libexpr libmain libfetchers libstore libutil
nix_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) -lboost_context -lboost_thread -lboost_system
diff --git a/src/nix/ls.cc b/src/nix/ls.cc
index b9716a6a1..d2157f2d4 100644
--- a/src/nix/ls.cc
+++ b/src/nix/ls.cc
@@ -63,7 +63,7 @@ struct MixLs : virtual Args, MixJSON
auto st = accessor->stat(path);
if (st.type == FSAccessor::Type::tMissing)
- throw Error(format("path '%1%' does not exist") % path);
+ throw Error("path '%1%' does not exist", path);
doPath(st, path,
st.type == FSAccessor::Type::tDirectory ? "." : std::string(baseNameOf(path)),
showDirectory);
diff --git a/src/nix/main.cc b/src/nix/main.cc
index 806f8411b..203901168 100644
--- a/src/nix/main.cc
+++ b/src/nix/main.cc
@@ -10,6 +10,7 @@
#include "progress-bar.hh"
#include "filetransfer.hh"
#include "finally.hh"
+#include "loggers.hh"
#include <sys/types.h>
#include <sys/socket.h>
@@ -90,7 +91,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
.longName = "print-build-logs",
.shortName = 'L',
.description = "print full build logs on stderr",
- .handler = {&printBuildLogs, true},
+ .handler = {[&]() {setLogFormat(LogFormat::barWithLogs); }},
});
addFlag({
@@ -162,9 +163,13 @@ void mainWrapped(int argc, char * * argv)
if (legacy) return legacy(argc, argv);
}
- verbosity = Verbosity::Warn;
+ verbosity = lvlWarn;
settings.verboseBuild = false;
+ setLogFormat("bar");
+
+ Finally f([] { logger->stop(); });
+
NixArgs args;
args.parseCmdline(argvToStrings(argc, argv));
@@ -178,10 +183,6 @@ void mainWrapped(int argc, char * * argv)
&& args.command->first != "upgrade-nix")
settings.requireExperimentalFeature("nix-command");
- Finally f([]() { stopProgressBar(); });
-
- startProgressBar(args.printBuildLogs);
-
if (args.useNet && !haveInternet()) {
warn("you don't have Internet access; disabling some network-dependent features");
args.useNet = false;
diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc
index d19e681bd..8d55171fc 100644
--- a/src/nix/make-content-addressable.cc
+++ b/src/nix/make-content-addressable.cc
@@ -36,7 +36,7 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
void run(ref<Store> store, StorePaths storePaths) override
{
- auto paths = store->topoSortPaths(storePathsToSet(storePaths));
+ auto paths = store->topoSortPaths(StorePathSet(storePaths.begin(), storePaths.end()));
std::reverse(paths.begin(), paths.end());
@@ -48,7 +48,7 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
for (auto & path : paths) {
auto pathS = store->printStorePath(path);
auto oldInfo = store->queryPathInfo(path);
- auto oldHashPart = storePathToHash(pathS);
+ std::string oldHashPart(path.hashPart());
StringSink sink;
store->narFromPath(path, sink);
@@ -62,7 +62,7 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
hasSelfReference = true;
else {
auto i = remappings.find(ref);
- auto replacement = i != remappings.end() ? i->second.clone() : ref.clone();
+ auto replacement = i != remappings.end() ? i->second : ref;
// FIXME: warn about unremapped paths?
if (replacement != ref)
rewrites.insert_or_assign(store->printStorePath(ref), store->printStorePath(replacement));
@@ -72,14 +72,14 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
*sink.s = rewriteStrings(*sink.s, rewrites);
- HashModuloSink hashModuloSink(HashType::SHA256, oldHashPart);
+ HashModuloSink hashModuloSink(htSHA256, oldHashPart);
hashModuloSink((unsigned char *) sink.s->data(), sink.s->size());
auto narHash = hashModuloSink.finish().first;
ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, path.name(), references, hasSelfReference));
info.references = std::move(references);
- if (hasSelfReference) info.references.insert(info.path.clone());
+ if (hasSelfReference) info.references.insert(info.path);
info.narHash = narHash;
info.narSize = sink.s->size();
info.ca = FileSystemHash {
@@ -88,10 +88,10 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
};
if (!json)
- printError("rewrote '%s' to '%s'", pathS, store->printStorePath(info.path));
+ printInfo("rewrote '%s' to '%s'", pathS, store->printStorePath(info.path));
auto source = sinkToSource([&](Sink & nextSink) {
- RewritingSink rsink2(oldHashPart, storePathToHash(store->printStorePath(info.path)), nextSink);
+ RewritingSink rsink2(oldHashPart, std::string(info.path.hashPart()), nextSink);
rsink2((unsigned char *) sink.s->data(), sink.s->size());
rsink2.flush();
});
diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc
index cda371129..b89a44f83 100644
--- a/src/nix/path-info.cc
+++ b/src/nix/path-info.cc
@@ -90,8 +90,8 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
JSONPlaceholder jsonRoot(std::cout);
store->pathInfoToJSON(jsonRoot,
// FIXME: preserve order?
- storePathsToSet(storePaths),
- true, showClosureSize, Base::SRI, AllowInvalid);
+ StorePathSet(storePaths.begin(), storePaths.end()),
+ true, showClosureSize, SRI, AllowInvalid);
}
else {
diff --git a/src/nix/progress-bar.cc b/src/nix/progress-bar.cc
deleted file mode 100644
index 76c6123f0..000000000
--- a/src/nix/progress-bar.cc
+++ /dev/null
@@ -1,474 +0,0 @@
-#include "progress-bar.hh"
-#include "util.hh"
-#include "sync.hh"
-#include "store-api.hh"
-#include "names.hh"
-
-#include <atomic>
-#include <map>
-#include <thread>
-#include <iostream>
-
-namespace nix {
-
-static std::string getS(const std::vector<Logger::Field> & fields, size_t n)
-{
- assert(n < fields.size());
- assert(fields[n].type == Logger::Field::tString);
- return fields[n].s;
-}
-
-static uint64_t getI(const std::vector<Logger::Field> & fields, size_t n)
-{
- assert(n < fields.size());
- assert(fields[n].type == Logger::Field::tInt);
- return fields[n].i;
-}
-
-static std::string_view storePathToName(std::string_view path)
-{
- auto base = baseNameOf(path);
- auto i = base.find('-');
- return i == std::string::npos ? base.substr(0, 0) : base.substr(i + 1);
-}
-
-class ProgressBar : public Logger
-{
-private:
-
- struct ActInfo
- {
- std::string s, lastLine, phase;
- ActivityType type = ActivityType::Unknown;
- uint64_t done = 0;
- uint64_t expected = 0;
- uint64_t running = 0;
- uint64_t failed = 0;
- std::map<ActivityType, uint64_t> expectedByType;
- bool visible = true;
- ActivityId parent;
- std::optional<std::string> name;
- };
-
- struct ActivitiesByType
- {
- std::map<ActivityId, std::list<ActInfo>::iterator> its;
- uint64_t done = 0;
- uint64_t expected = 0;
- uint64_t failed = 0;
- };
-
- struct State
- {
- std::list<ActInfo> activities;
- std::map<ActivityId, std::list<ActInfo>::iterator> its;
-
- std::map<ActivityType, ActivitiesByType> activitiesByType;
-
- uint64_t filesLinked = 0, bytesLinked = 0;
-
- uint64_t corruptedPaths = 0, untrustedPaths = 0;
-
- bool active = true;
- bool haveUpdate = true;
- };
-
- Sync<State> state_;
-
- std::thread updateThread;
-
- std::condition_variable quitCV, updateCV;
-
- bool printBuildLogs;
- bool isTTY;
-
-public:
-
- ProgressBar(bool printBuildLogs, bool isTTY)
- : printBuildLogs(printBuildLogs)
- , isTTY(isTTY)
- {
- state_.lock()->active = isTTY;
- updateThread = std::thread([&]() {
- auto state(state_.lock());
- while (state->active) {
- if (!state->haveUpdate)
- state.wait(updateCV);
- draw(*state);
- state.wait_for(quitCV, std::chrono::milliseconds(50));
- }
- });
- }
-
- ~ProgressBar()
- {
- stop();
- updateThread.join();
- }
-
- void stop()
- {
- auto state(state_.lock());
- if (!state->active) return;
- state->active = false;
- std::string status = getStatus(*state);
- writeToStderr("\r\e[K");
- if (status != "")
- writeToStderr("[" + status + "]\n");
- updateCV.notify_one();
- quitCV.notify_one();
- }
-
- void log(Verbosity lvl, const FormatOrString & fs) override
- {
- auto state(state_.lock());
- log(*state, lvl, fs.s);
- }
-
- void log(State & state, Verbosity lvl, const std::string & s)
- {
- if (state.active) {
- writeToStderr("\r\e[K" + filterANSIEscapes(s, !isTTY) + ANSI_NORMAL "\n");
- draw(state);
- } else {
- auto s2 = s + ANSI_NORMAL "\n";
- if (!isTTY) s2 = filterANSIEscapes(s2, true);
- writeToStderr(s2);
- }
- }
-
- void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
- const std::string & s, const Fields & fields, ActivityId parent) override
- {
- auto state(state_.lock());
-
- if (lvl <= verbosity && !s.empty())
- log(*state, lvl, s + "...");
-
- state->activities.emplace_back(ActInfo());
- auto i = std::prev(state->activities.end());
- i->s = s;
- i->type = type;
- i->parent = parent;
- state->its.emplace(act, i);
- state->activitiesByType[type].its.emplace(act, i);
-
- if (type == ActivityType::Build) {
- auto name = storePathToName(getS(fields, 0));
- if (hasSuffix(name, ".drv"))
- name = name.substr(0, name.size() - 4);
- i->s = fmt("building " ANSI_BOLD "%s" ANSI_NORMAL, name);
- auto machineName = getS(fields, 1);
- if (machineName != "")
- i->s += fmt(" on " ANSI_BOLD "%s" ANSI_NORMAL, machineName);
- auto curRound = getI(fields, 2);
- auto nrRounds = getI(fields, 3);
- if (nrRounds != 1)
- i->s += fmt(" (round %d/%d)", curRound, nrRounds);
- i->name = DrvName(name).name;
- }
-
- if (type == ActivityType::Substitute) {
- auto name = storePathToName(getS(fields, 0));
- auto sub = getS(fields, 1);
- i->s = fmt(
- hasPrefix(sub, "local")
- ? "copying " ANSI_BOLD "%s" ANSI_NORMAL " from %s"
- : "fetching " ANSI_BOLD "%s" ANSI_NORMAL " from %s",
- name, sub);
- }
-
- if (type == ActivityType::PostBuildHook) {
- auto name = storePathToName(getS(fields, 0));
- if (hasSuffix(name, ".drv"))
- name = name.substr(0, name.size() - 4);
- i->s = fmt("post-build " ANSI_BOLD "%s" ANSI_NORMAL, name);
- i->name = DrvName(name).name;
- }
-
- if (type == ActivityType::QueryPathInfo) {
- auto name = storePathToName(getS(fields, 0));
- i->s = fmt("querying " ANSI_BOLD "%s" ANSI_NORMAL " on %s", name, getS(fields, 1));
- }
-
- if ((type == ActivityType::Download && hasAncestor(*state, ActivityType::CopyPath, parent))
- || (type == ActivityType::Download && hasAncestor(*state, ActivityType::QueryPathInfo, parent))
- || (type == ActivityType::CopyPath && hasAncestor(*state, ActivityType::Substitute, parent)))
- i->visible = false;
-
- update(*state);
- }
-
- /* Check whether an activity has an ancestore with the specified
- type. */
- bool hasAncestor(State & state, ActivityType type, ActivityId act)
- {
- while (act != 0) {
- auto i = state.its.find(act);
- if (i == state.its.end()) break;
- if (i->second->type == type) return true;
- act = i->second->parent;
- }
- return false;
- }
-
- void stopActivity(ActivityId act) override
- {
- auto state(state_.lock());
-
- auto i = state->its.find(act);
- if (i != state->its.end()) {
-
- auto & actByType = state->activitiesByType[i->second->type];
- actByType.done += i->second->done;
- actByType.failed += i->second->failed;
-
- for (auto & j : i->second->expectedByType)
- state->activitiesByType[j.first].expected -= j.second;
-
- actByType.its.erase(act);
- state->activities.erase(i->second);
- state->its.erase(i);
- }
-
- update(*state);
- }
-
- void result(ActivityId act, ResultType type, const std::vector<Field> & fields) override
- {
- auto state(state_.lock());
-
- if (type == ResultType::FileLinked) {
- state->filesLinked++;
- state->bytesLinked += getI(fields, 0);
- update(*state);
- }
-
- else if (type == ResultType::BuildLogLine || type == ResultType::PostBuildLogLine) {
- auto lastLine = trim(getS(fields, 0));
- if (!lastLine.empty()) {
- auto i = state->its.find(act);
- assert(i != state->its.end());
- ActInfo info = *i->second;
- if (printBuildLogs) {
- auto suffix = "> ";
- if (type == ResultType::PostBuildLogLine) {
- suffix = " (post)> ";
- }
- log(*state, Verbosity::Info, ANSI_FAINT + info.name.value_or("unnamed") + suffix + ANSI_NORMAL + lastLine);
- } else {
- state->activities.erase(i->second);
- info.lastLine = lastLine;
- state->activities.emplace_back(info);
- i->second = std::prev(state->activities.end());
- update(*state);
- }
- }
- }
-
- else if (type == ResultType::UntrustedPath) {
- state->untrustedPaths++;
- update(*state);
- }
-
- else if (type == ResultType::CorruptedPath) {
- state->corruptedPaths++;
- update(*state);
- }
-
- else if (type == ResultType::SetPhase) {
- auto i = state->its.find(act);
- assert(i != state->its.end());
- i->second->phase = getS(fields, 0);
- update(*state);
- }
-
- else if (type == ResultType::Progress) {
- auto i = state->its.find(act);
- assert(i != state->its.end());
- ActInfo & actInfo = *i->second;
- actInfo.done = getI(fields, 0);
- actInfo.expected = getI(fields, 1);
- actInfo.running = getI(fields, 2);
- actInfo.failed = getI(fields, 3);
- update(*state);
- }
-
- else if (type == ResultType::SetExpected) {
- auto i = state->its.find(act);
- assert(i != state->its.end());
- ActInfo & actInfo = *i->second;
- auto type = (ActivityType) getI(fields, 0);
- auto & j = actInfo.expectedByType[type];
- state->activitiesByType[type].expected -= j;
- j = getI(fields, 1);
- state->activitiesByType[type].expected += j;
- update(*state);
- }
- }
-
- void update(State & state)
- {
- state.haveUpdate = true;
- updateCV.notify_one();
- }
-
- void draw(State & state)
- {
- state.haveUpdate = false;
- if (!state.active) return;
-
- std::string line;
-
- std::string status = getStatus(state);
- if (!status.empty()) {
- line += '[';
- line += status;
- line += "]";
- }
-
- if (!state.activities.empty()) {
- if (!status.empty()) line += " ";
- auto i = state.activities.rbegin();
-
- while (i != state.activities.rend() && (!i->visible || (i->s.empty() && i->lastLine.empty())))
- ++i;
-
- if (i != state.activities.rend()) {
- line += i->s;
- if (!i->phase.empty()) {
- line += " (";
- line += i->phase;
- line += ")";
- }
- if (!i->lastLine.empty()) {
- if (!i->s.empty()) line += ": ";
- line += i->lastLine;
- }
- }
- }
-
- auto width = getWindowSize().second;
- if (width <= 0) width = std::numeric_limits<decltype(width)>::max();
-
- writeToStderr("\r" + filterANSIEscapes(line, false, width) + "\e[K");
- }
-
- std::string getStatus(State & state)
- {
- auto MiB = 1024.0 * 1024.0;
-
- std::string res;
-
- auto renderActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
- auto & act = state.activitiesByType[type];
- uint64_t done = act.done, expected = act.done, running = 0, failed = act.failed;
- for (auto & j : act.its) {
- done += j.second->done;
- expected += j.second->expected;
- running += j.second->running;
- failed += j.second->failed;
- }
-
- expected = std::max(expected, act.expected);
-
- std::string s;
-
- if (running || done || expected || failed) {
- if (running)
- if (expected != 0)
- s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt,
- running / unit, done / unit, expected / unit);
- else
- s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL,
- running / unit, done / unit);
- else if (expected != done)
- if (expected != 0)
- s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt,
- done / unit, expected / unit);
- else
- s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL, done / unit);
- else
- s = fmt(done ? ANSI_GREEN + numberFmt + ANSI_NORMAL : numberFmt, done / unit);
- s = fmt(itemFmt, s);
-
- if (failed)
- s += fmt(" (" ANSI_RED "%d failed" ANSI_NORMAL ")", failed / unit);
- }
-
- return s;
- };
-
- auto showActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
- auto s = renderActivity(type, itemFmt, numberFmt, unit);
- if (s.empty()) return;
- if (!res.empty()) res += ", ";
- res += s;
- };
-
- showActivity(ActivityType::Builds, "%s built");
-
- auto s1 = renderActivity(ActivityType::CopyPaths, "%s copied");
- auto s2 = renderActivity(ActivityType::CopyPath, "%s MiB", "%.1f", MiB);
-
- if (!s1.empty() || !s2.empty()) {
- if (!res.empty()) res += ", ";
- if (s1.empty()) res += "0 copied"; else res += s1;
- if (!s2.empty()) { res += " ("; res += s2; res += ')'; }
- }
-
- showActivity(ActivityType::Download, "%s MiB DL", "%.1f", MiB);
-
- {
- auto s = renderActivity(ActivityType::OptimiseStore, "%s paths optimised");
- if (s != "") {
- s += fmt(", %.1f MiB / %d inodes freed", state.bytesLinked / MiB, state.filesLinked);
- if (!res.empty()) res += ", ";
- res += s;
- }
- }
-
- // FIXME: don't show "done" paths in green.
- showActivity(ActivityType::VerifyPaths, "%s paths verified");
-
- if (state.corruptedPaths) {
- if (!res.empty()) res += ", ";
- res += fmt(ANSI_RED "%d corrupted" ANSI_NORMAL, state.corruptedPaths);
- }
-
- if (state.untrustedPaths) {
- if (!res.empty()) res += ", ";
- res += fmt(ANSI_RED "%d untrusted" ANSI_NORMAL, state.untrustedPaths);
- }
-
- return res;
- }
-
- void writeToStdout(std::string_view s) override
- {
- auto state(state_.lock());
- if (state->active) {
- std::cerr << "\r\e[K";
- Logger::writeToStdout(s);
- draw(*state);
- } else {
- Logger::writeToStdout(s);
- }
- }
-};
-
-void startProgressBar(bool printBuildLogs)
-{
- logger = new ProgressBar(
- printBuildLogs,
- isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb");
-}
-
-void stopProgressBar()
-{
- auto progressBar = dynamic_cast<ProgressBar *>(logger);
- if (progressBar) progressBar->stop();
-
-}
-
-}
diff --git a/src/nix/progress-bar.hh b/src/nix/progress-bar.hh
deleted file mode 100644
index 4d61175c2..000000000
--- a/src/nix/progress-bar.hh
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-
-#include "logging.hh"
-
-namespace nix {
-
-void startProgressBar(bool printBuildLogs = false);
-
-void stopProgressBar();
-
-}
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index 7d66419bd..617d49614 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -19,6 +19,7 @@ extern "C" {
}
#endif
+#include "ansicolor.hh"
#include "shared.hh"
#include "eval.hh"
#include "eval-inline.hh"
@@ -37,14 +38,6 @@ extern "C" {
namespace nix {
-#define ESC_RED "\033[31m"
-#define ESC_GRE "\033[32m"
-#define ESC_YEL "\033[33m"
-#define ESC_BLU "\033[34;1m"
-#define ESC_MAG "\033[35m"
-#define ESC_CYA "\033[36m"
-#define ESC_END "\033[0m"
-
struct NixRepl : gc
{
string curDir;
@@ -218,12 +211,12 @@ void NixRepl::mainLoop(const std::vector<std::string> & files)
// input without clearing the input so far.
continue;
} else {
- printMsg(Verbosity::Error, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg());
+ printMsg(lvlError, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg());
}
} catch (Error & e) {
- printMsg(Verbosity::Error, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg());
+ printMsg(lvlError, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg());
} catch (Interrupted & e) {
- printMsg(Verbosity::Error, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg());
+ printMsg(lvlError, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg());
}
// We handled the current input fully, so we should clear it
@@ -512,7 +505,7 @@ bool NixRepl::processLine(string line)
return false;
else if (command != "")
- throw Error(format("unknown command '%1%'") % command);
+ throw Error("unknown command '%1%'", command);
else {
size_t p = line.find('=');
@@ -645,25 +638,25 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
switch (v.type) {
case tInt:
- str << ESC_CYA << v.integer << ESC_END;
+ str << ANSI_CYAN << v.integer << ANSI_NORMAL;
break;
case tBool:
- str << ESC_CYA << (v.boolean ? "true" : "false") << ESC_END;
+ str << ANSI_CYAN << (v.boolean ? "true" : "false") << ANSI_NORMAL;
break;
case tString:
- str << ESC_YEL;
+ str << ANSI_YELLOW;
printStringValue(str, v.string.s);
- str << ESC_END;
+ str << ANSI_NORMAL;
break;
case tPath:
- str << ESC_GRE << v.path << ESC_END; // !!! escaping?
+ str << ANSI_GREEN << v.path << ANSI_NORMAL; // !!! escaping?
break;
case tNull:
- str << ESC_CYA "null" ESC_END;
+ str << ANSI_CYAN "null" ANSI_NORMAL;
break;
case tAttrs: {
@@ -699,7 +692,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
try {
printValue(str, *i.second, maxDepth - 1, seen);
} catch (AssertionError & e) {
- str << ESC_RED "«error: " << e.msg() << "»" ESC_END;
+ str << ANSI_RED "«error: " << e.msg() << "»" ANSI_NORMAL;
}
str << "; ";
}
@@ -725,7 +718,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
try {
printValue(str, *v.listElems()[n], maxDepth - 1, seen);
} catch (AssertionError & e) {
- str << ESC_RED "«error: " << e.msg() << "»" ESC_END;
+ str << ANSI_RED "«error: " << e.msg() << "»" ANSI_NORMAL;
}
str << " ";
}
@@ -737,16 +730,16 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
case tLambda: {
std::ostringstream s;
s << v.lambda.fun->pos;
- str << ESC_BLU "«lambda @ " << filterANSIEscapes(s.str()) << "»" ESC_END;
+ str << ANSI_BLUE "«lambda @ " << filterANSIEscapes(s.str()) << "»" ANSI_NORMAL;
break;
}
case tPrimOp:
- str << ESC_MAG "«primop»" ESC_END;
+ str << ANSI_MAGENTA "«primop»" ANSI_NORMAL;
break;
case tPrimOpApp:
- str << ESC_BLU "«primop-app»" ESC_END;
+ str << ANSI_BLUE "«primop-app»" ANSI_NORMAL;
break;
case tFloat:
@@ -754,7 +747,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
break;
default:
- str << ESC_RED "«unknown»" ESC_END;
+ str << ANSI_RED "«unknown»" ANSI_NORMAL;
break;
}
diff --git a/src/nix/run.cc b/src/nix/run.cc
index b888281a5..321ee1d11 100644
--- a/src/nix/run.cc
+++ b/src/nix/run.cc
@@ -111,16 +111,16 @@ struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment
std::unordered_set<StorePath> done;
std::queue<StorePath> todo;
- for (auto & path : outPaths) todo.push(path.clone());
+ for (auto & path : outPaths) todo.push(path);
setEnviron();
auto unixPath = tokenizeString<Strings>(getEnv("PATH").value_or(""), ":");
while (!todo.empty()) {
- auto path = todo.front().clone();
+ auto path = todo.front();
todo.pop();
- if (!done.insert(path.clone()).second) continue;
+ if (!done.insert(path).second) continue;
if (true)
unixPath.push_front(store->printStorePath(path) + "/bin");
@@ -197,10 +197,10 @@ void chrootHelper(int argc, char * * argv)
Finally freeCwd([&]() { free(cwd); });
if (chroot(tmpDir.c_str()) == -1)
- throw SysError(format("chrooting into '%s'") % tmpDir);
+ throw SysError("chrooting into '%s'", tmpDir);
if (chdir(cwd) == -1)
- throw SysError(format("chdir to '%s' in chroot") % cwd);
+ throw SysError("chdir to '%s' in chroot", cwd);
} else
if (mount(realStoreDir.c_str(), storeDir.c_str(), "", MS_BIND, 0) == -1)
throw SysError("mounting '%s' on '%s'", realStoreDir, storeDir);
diff --git a/src/nix/show-derivation.cc b/src/nix/show-derivation.cc
index 87387002d..9132c75b1 100644
--- a/src/nix/show-derivation.cc
+++ b/src/nix/show-derivation.cc
@@ -61,11 +61,9 @@ struct CmdShowDerivation : InstallablesCommand
for (auto & drvPath : drvPaths) {
if (!drvPath.isDerivation()) continue;
- auto drvPathS = store->printStorePath(drvPath);
+ auto drvObj(jsonRoot.object(store->printStorePath(drvPath)));
- auto drvObj(jsonRoot.object(drvPathS));
-
- auto drv = readDerivation(*store, drvPathS);
+ auto drv = store->readDerivation(drvPath);
{
auto outputsObj(drvObj.object("outputs"));
diff --git a/src/nix/sigs.cc b/src/nix/sigs.cc
index 311817d1f..6c9b9a792 100644
--- a/src/nix/sigs.cc
+++ b/src/nix/sigs.cc
@@ -47,7 +47,7 @@ struct CmdCopySigs : StorePathsCommand
//logger->setExpected(doneLabel, storePaths.size());
auto doPath = [&](const Path & storePathS) {
- //Activity act(*logger, Verbosity::Info, format("getting signatures for '%s'") % storePath);
+ //Activity act(*logger, lvlInfo, format("getting signatures for '%s'") % storePath);
checkInterrupt();
diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc
index 9018e69b3..a880bdae0 100644
--- a/src/nix/upgrade-nix.cc
+++ b/src/nix/upgrade-nix.cc
@@ -68,17 +68,20 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
if (dryRun) {
stopProgressBar();
- printError("would upgrade to version %s", version);
+ logWarning({
+ .name = "Version update",
+ .hint = hintfmt("would upgrade to version %s", version)
+ });
return;
}
{
- Activity act(*logger, Verbosity::Info, ActivityType::Unknown, fmt("downloading '%s'...", store->printStorePath(storePath)));
+ Activity act(*logger, lvlInfo, actUnknown, fmt("downloading '%s'...", store->printStorePath(storePath)));
store->ensurePath(storePath);
}
{
- Activity act(*logger, Verbosity::Info, ActivityType::Unknown, fmt("verifying that '%s' works...", store->printStorePath(storePath)));
+ Activity act(*logger, lvlInfo, actUnknown, fmt("verifying that '%s' works...", store->printStorePath(storePath)));
auto program = store->printStorePath(storePath) + "/bin/nix-env";
auto s = runProgram(program, false, {"--version"});
if (s.find("Nix") == std::string::npos)
@@ -88,13 +91,13 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
stopProgressBar();
{
- Activity act(*logger, Verbosity::Info, ActivityType::Unknown,
+ Activity act(*logger, lvlInfo, actUnknown,
fmt("installing '%s' into profile '%s'...", store->printStorePath(storePath), profileDir));
runProgram(settings.nixBinDir + "/nix-env", false,
{"--profile", profileDir, "-i", store->printStorePath(storePath), "--no-sandbox"});
}
- printError(ANSI_GREEN "upgrade to version %s done" ANSI_NORMAL, version);
+ printInfo(ANSI_GREEN "upgrade to version %s done" ANSI_NORMAL, version);
}
/* Return the profile in which Nix is installed. */
@@ -139,7 +142,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
/* Return the store path of the latest stable Nix. */
StorePath getLatestNix(ref<Store> store)
{
- Activity act(*logger, Verbosity::Info, ActivityType::Unknown, "querying latest Nix version");
+ Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version");
// FIXME: use nixos.org?
auto req = FileTransferRequest(storePathsUrl);
diff --git a/src/nix/verify.cc b/src/nix/verify.cc
index 58ffc7e4b..bb5e4529b 100644
--- a/src/nix/verify.cc
+++ b/src/nix/verify.cc
@@ -59,7 +59,7 @@ struct CmdVerify : StorePathsCommand
auto publicKeys = getDefaultPublicKeys();
- Activity act(*logger, ActivityType::VerifyPaths);
+ Activity act(*logger, actVerifyPaths);
std::atomic<size_t> done{0};
std::atomic<size_t> untrusted{0};
@@ -77,7 +77,7 @@ struct CmdVerify : StorePathsCommand
try {
checkInterrupt();
- Activity act2(*logger, Verbosity::Info, ActivityType::Unknown, fmt("checking '%s'", storePath));
+ Activity act2(*logger, lvlInfo, actUnknown, fmt("checking '%s'", storePath));
MaintainCount<std::atomic<size_t>> mcActive(active);
update();
@@ -90,7 +90,7 @@ struct CmdVerify : StorePathsCommand
if (!info->ca)
hashSink = std::make_unique<HashSink>(*info->narHash.type);
else
- hashSink = std::make_unique<HashModuloSink>(*info->narHash.type, storePathToHash(store->printStorePath(info->path)));
+ hashSink = std::make_unique<HashModuloSink>(*info->narHash.type, std::string(info->path.hashPart()));
store->narFromPath(info->path, *hashSink);
@@ -98,12 +98,16 @@ struct CmdVerify : StorePathsCommand
if (hash.first != info->narHash) {
corrupted++;
- act2.result(ResultType::CorruptedPath, store->printStorePath(info->path));
- printError(
- "path '%s' was modified! expected hash '%s', got '%s'",
- store->printStorePath(info->path), info->narHash.to_string(), hash.first.to_string());
+ act2.result(resCorruptedPath, store->printStorePath(info->path));
+ logError({
+ .name = "Hash error - path modified",
+ .hint = hintfmt(
+ "path '%s' was modified! expected hash '%s', got '%s'",
+ store->printStorePath(info->path),
+ info->narHash.to_string(Base32, true),
+ hash.first.to_string(Base32, true))
+ });
}
-
}
if (!noTrust) {
@@ -139,7 +143,7 @@ struct CmdVerify : StorePathsCommand
doSigs(info2->sigs);
} catch (InvalidPath &) {
} catch (Error & e) {
- printError(format(ANSI_RED "error:" ANSI_NORMAL " %s") % e.what());
+ logError(e.info());
}
}
@@ -149,8 +153,13 @@ struct CmdVerify : StorePathsCommand
if (!good) {
untrusted++;
- act2.result(ResultType::UntrustedPath, store->printStorePath(info->path));
- printError("path '%s' is untrusted", store->printStorePath(info->path));
+ act2.result(resUntrustedPath, store->printStorePath(info->path));
+ logError({
+ .name = "Untrusted path",
+ .hint = hintfmt("path '%s' is untrusted",
+ store->printStorePath(info->path))
+ });
+
}
}
@@ -158,7 +167,7 @@ struct CmdVerify : StorePathsCommand
done++;
} catch (Error & e) {
- printError(format(ANSI_RED "error:" ANSI_NORMAL " %s") % e.what());
+ logError(e.info());
failed++;
}
diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc
index 6057beedb..167c974ee 100644
--- a/src/nix/why-depends.cc
+++ b/src/nix/why-depends.cc
@@ -76,7 +76,7 @@ struct CmdWhyDepends : SourceExprCommand
auto packagePath = toStorePath(store, Build, package);
auto dependency = parseInstallable(*this, store, _dependency, false);
auto dependencyPath = toStorePath(store, NoBuild, dependency);
- auto dependencyPathHash = storePathToHash(store->printStorePath(dependencyPath));
+ auto dependencyPathHash = dependencyPath.hashPart();
StorePathSet closure;
store->computeFSClosure({packagePath}, closure, false, false);
@@ -106,16 +106,16 @@ struct CmdWhyDepends : SourceExprCommand
std::map<StorePath, Node> graph;
for (auto & path : closure)
- graph.emplace(path.clone(), Node { .path = path.clone(), .refs = cloneStorePathSet(store->queryPathInfo(path)->references) });
+ graph.emplace(path, Node { .path = path, .refs = store->queryPathInfo(path)->references });
// Transpose the graph.
for (auto & node : graph)
for (auto & ref : node.second.refs)
- graph.find(ref)->second.rrefs.insert(node.first.clone());
+ graph.find(ref)->second.rrefs.insert(node.first);
/* Run Dijkstra's shortest path algorithm to get the distance
of every path in the closure to 'dependency'. */
- graph.emplace(dependencyPath.clone(), Node { .path = dependencyPath.clone(), .dist = 0 });
+ graph.emplace(dependencyPath, Node { .path = dependencyPath, .dist = 0 });
std::priority_queue<Node *> queue;
@@ -175,7 +175,7 @@ struct CmdWhyDepends : SourceExprCommand
auto & node2 = graph.at(ref);
if (node2.dist == inf) continue;
refs.emplace(node2.dist, &node2);
- hashes.insert(storePathToHash(store->printStorePath(node2.path)));
+ hashes.insert(std::string(node2.path.hashPart()));
}
/* For each reference, find the files and symlinks that
@@ -211,7 +211,7 @@ struct CmdWhyDepends : SourceExprCommand
p2,
hilite(filterPrintable(
std::string(contents, pos2, pos - pos2 + hash.size() + margin)),
- pos - pos2, storePathHashLen,
+ pos - pos2, StorePath::HashLen,
getColour(hash))));
}
}
@@ -224,7 +224,7 @@ struct CmdWhyDepends : SourceExprCommand
auto pos = target.find(hash);
if (pos != std::string::npos)
hits[hash].emplace_back(fmt("%s -> %s\n", p2,
- hilite(target, pos, storePathHashLen, getColour(hash))));
+ hilite(target, pos, StorePath::HashLen, getColour(hash))));
}
}
};
@@ -235,7 +235,7 @@ struct CmdWhyDepends : SourceExprCommand
RunPager pager;
for (auto & ref : refs) {
- auto hash = storePathToHash(store->printStorePath(ref.second->path));
+ std::string hash(ref.second->path.hashPart());
bool last = all ? ref == *refs.rbegin() : true;