From 6438ba22af57edc054e441053a7c3cd5d48e5597 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 14 Jul 2017 14:23:38 +0200 Subject: [PATCH] StorePathsCommand: Don't build installables On second though this was annoying. E.g. "nix log nixpkgs.hello" would build/download Hello first, even though the log can be fetched directly from the binary cache. May need to revisit this. --- src/nix/build.cc | 2 +- src/nix/command.cc | 4 ++-- src/nix/command.hh | 4 +++- src/nix/installables.cc | 6 +++--- src/nix/run.cc | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/nix/build.cc b/src/nix/build.cc index 00bda1fd1..cc96ac48a 100644 --- a/src/nix/build.cc +++ b/src/nix/build.cc @@ -23,7 +23,7 @@ struct CmdBuild : MixDryRun, InstallablesCommand void run(ref store) override { - auto paths = buildInstallables(store, dryRun); + auto paths = toStorePaths(store, dryRun ? DryRun : Build); printInfo("build result: %s", showPaths(paths)); } diff --git a/src/nix/command.cc b/src/nix/command.cc index 96b685a5b..6b608a708 100644 --- a/src/nix/command.cc +++ b/src/nix/command.cc @@ -115,7 +115,7 @@ void StorePathsCommand::run(ref store) } else { - for (auto & p : buildInstallables(store, false)) + for (auto & p : toStorePaths(store, NoBuild)) storePaths.push_back(p); if (recursive) { @@ -131,7 +131,7 @@ void StorePathsCommand::run(ref store) void StorePathCommand::run(ref store) { - auto storePaths = buildInstallables(store, false); + auto storePaths = toStorePaths(store, NoBuild); if (storePaths.size() != 1) throw UsageError("this command requires exactly one store path"); diff --git a/src/nix/command.hh b/src/nix/command.hh index 4800b5c91..eb736ce3a 100644 --- a/src/nix/command.hh +++ b/src/nix/command.hh @@ -80,7 +80,9 @@ struct InstallablesCommand : virtual Args, StoreCommand std::vector> parseInstallables(ref store, Strings ss); - PathSet buildInstallables(ref store, bool dryRun); + enum ToStorePathsMode { Build, NoBuild, DryRun }; + + PathSet toStorePaths(ref store, ToStorePathsMode mode); ref getEvalState(); diff --git a/src/nix/installables.cc b/src/nix/installables.cc index 9982ff75f..f0d5d547c 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -214,7 +214,7 @@ std::vector> InstallablesCommand::parseInstallables return result; } -PathSet InstallablesCommand::buildInstallables(ref store, bool dryRun) +PathSet InstallablesCommand::toStorePaths(ref store, ToStorePathsMode mode) { PathSet buildables; @@ -223,9 +223,9 @@ PathSet InstallablesCommand::buildInstallables(ref store, bool dryRun) buildables.insert(b.begin(), b.end()); } - if (dryRun) + if (mode == DryRun) printMissing(store, buildables); - else + else if (mode == Build) store->buildPaths(buildables); PathSet outPaths; diff --git a/src/nix/run.cc b/src/nix/run.cc index bcfa74eb5..49fe4e7a0 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -30,7 +30,7 @@ struct CmdRun : InstallablesCommand void run(ref store) override { - auto outPaths = buildInstallables(store, false); + auto outPaths = toStorePaths(store, Build); auto store2 = store.dynamic_pointer_cast();