about summary refs log tree commit diff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-04-25T10·06+0200
committerEelco Dolstra <edolstra@gmail.com>2017-04-25T10·07+0200
commitc769841bc4ecb9dd3d8456931fec78e102c3832f (patch)
treee6723ab7c0c9e2af87181ea787a60bb4a662cfaf /src/nix
parent6267d748891b3c6e6a41b5bd1f6684ae8b88f31c (diff)
Move code around
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/build.cc3
-rw-r--r--src/nix/command.hh54
-rw-r--r--src/nix/eval.cc3
-rw-r--r--src/nix/installables.cc20
-rw-r--r--src/nix/installables.hh61
-rw-r--r--src/nix/log.cc3
-rw-r--r--src/nix/run.cc3
-rw-r--r--src/nix/show-config.cc1
8 files changed, 68 insertions, 80 deletions
diff --git a/src/nix/build.cc b/src/nix/build.cc
index 0a34c68f8819..00bda1fd1045 100644
--- a/src/nix/build.cc
+++ b/src/nix/build.cc
@@ -1,12 +1,11 @@
 #include "command.hh"
 #include "common-args.hh"
-#include "installables.hh"
 #include "shared.hh"
 #include "store-api.hh"
 
 using namespace nix;
 
-struct CmdBuild : MixDryRun, MixInstallables
+struct CmdBuild : MixDryRun, InstallablesCommand
 {
     CmdBuild()
     {
diff --git a/src/nix/command.hh b/src/nix/command.hh
index bb667ee325ca..ee9485e5dd14 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -4,6 +4,9 @@
 
 namespace nix {
 
+struct Value;
+class EvalState;
+
 /* A command is an argument parser that can be executed by calling its
    run() method. */
 struct Command : virtual Args
@@ -61,6 +64,57 @@ public:
     void run(ref<Store> store) override;
 };
 
+struct Installable
+{
+    virtual std::string what() = 0;
+
+    virtual PathSet toBuildable()
+    {
+        throw Error("argument ‘%s’ cannot be built", what());
+    }
+
+    virtual Value * toValue(EvalState & state)
+    {
+        throw Error("argument ‘%s’ cannot be evaluated", what());
+    }
+};
+
+/* A command that operates on a list of "installables", which can be
+   store paths, attribute paths, Nix expressions, etc. */
+struct InstallablesCommand : virtual Args, StoreCommand
+{
+    std::vector<std::shared_ptr<Installable>> installables;
+    Path file;
+
+    InstallablesCommand()
+    {
+        mkFlag('f', "file", "file", "evaluate FILE rather than the default", &file);
+        expectArgs("installables", &_installables);
+    }
+
+    /* Return a value representing the Nix expression from which we
+       are installing. This is either the file specified by ‘--file’,
+       or an attribute set constructed from $NIX_PATH, e.g. ‘{ nixpkgs
+       = import ...; bla = import ...; }’. */
+    Value * getSourceExpr(EvalState & state);
+
+    std::vector<std::shared_ptr<Installable>> parseInstallables(ref<Store> store, Strings installables);
+
+    PathSet buildInstallables(ref<Store> store, bool dryRun);
+
+    ref<EvalState> getEvalState();
+
+    void prepare() override;
+
+private:
+
+    Strings _installables;
+
+    std::shared_ptr<EvalState> evalState;
+
+    Value * vSourceExpr = 0;
+};
+
 typedef std::map<std::string, ref<Command>> Commands;
 
 /* An argument parser that supports multiple subcommands,
diff --git a/src/nix/eval.cc b/src/nix/eval.cc
index 7a6bf07c3535..eb2b13a2dcd7 100644
--- a/src/nix/eval.cc
+++ b/src/nix/eval.cc
@@ -1,6 +1,5 @@
 #include "command.hh"
 #include "common-args.hh"
-#include "installables.hh"
 #include "shared.hh"
 #include "store-api.hh"
 #include "eval.hh"
@@ -9,7 +8,7 @@
 
 using namespace nix;
 
-struct CmdEval : MixJSON, MixInstallables
+struct CmdEval : MixJSON, InstallablesCommand
 {
     std::string name() override
     {
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 70007d62a290..3cf4a6f8d32b 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -1,10 +1,10 @@
+#include "command.hh"
 #include "attr-path.hh"
 #include "common-opts.hh"
 #include "derivations.hh"
 #include "eval-inline.hh"
 #include "eval.hh"
 #include "get-drvs.hh"
-#include "installables.hh"
 #include "store-api.hh"
 #include "shared.hh"
 
@@ -12,7 +12,7 @@
 
 namespace nix {
 
-Value * MixInstallables::getSourceExpr(EvalState & state)
+Value * InstallablesCommand::getSourceExpr(EvalState & state)
 {
     if (vSourceExpr) return vSourceExpr;
 
@@ -89,10 +89,10 @@ struct InstallableStorePath : Installable
 
 struct InstallableExpr : Installable
 {
-    MixInstallables & installables;
+    InstallablesCommand & installables;
     std::string text;
 
-    InstallableExpr(MixInstallables & installables, const std::string & text)
+    InstallableExpr(InstallablesCommand & installables, const std::string & text)
          : installables(installables), text(text) { }
 
     std::string what() override { return text; }
@@ -128,10 +128,10 @@ struct InstallableExpr : Installable
 
 struct InstallableAttrPath : Installable
 {
-    MixInstallables & installables;
+    InstallablesCommand & installables;
     std::string attrPath;
 
-    InstallableAttrPath(MixInstallables & installables, const std::string & attrPath)
+    InstallableAttrPath(InstallablesCommand & installables, const std::string & attrPath)
         : installables(installables), attrPath(attrPath)
     { }
 
@@ -177,7 +177,7 @@ struct InstallableAttrPath : Installable
 std::string attrRegex = R"([A-Za-z_][A-Za-z0-9-_+]*)";
 static std::regex attrPathRegex(fmt(R"(%1%(\.%1%)*)", attrRegex));
 
-std::vector<std::shared_ptr<Installable>> MixInstallables::parseInstallables(ref<Store> store, Strings installables)
+std::vector<std::shared_ptr<Installable>> InstallablesCommand::parseInstallables(ref<Store> store, Strings installables)
 {
     std::vector<std::shared_ptr<Installable>> result;
 
@@ -212,7 +212,7 @@ std::vector<std::shared_ptr<Installable>> MixInstallables::parseInstallables(ref
     return result;
 }
 
-PathSet MixInstallables::buildInstallables(ref<Store> store, bool dryRun)
+PathSet InstallablesCommand::buildInstallables(ref<Store> store, bool dryRun)
 {
     PathSet buildables;
 
@@ -229,14 +229,14 @@ PathSet MixInstallables::buildInstallables(ref<Store> store, bool dryRun)
     return buildables;
 }
 
-ref<EvalState> MixInstallables::getEvalState()
+ref<EvalState> InstallablesCommand::getEvalState()
 {
     if (!evalState)
         evalState = std::make_shared<EvalState>(Strings{}, getStore());
     return ref<EvalState>(evalState);
 }
 
-void MixInstallables::prepare()
+void InstallablesCommand::prepare()
 {
     installables = parseInstallables(getStore(), _installables);
 }
diff --git a/src/nix/installables.hh b/src/nix/installables.hh
deleted file mode 100644
index 5f0b0a292242..000000000000
--- a/src/nix/installables.hh
+++ /dev/null
@@ -1,61 +0,0 @@
-#pragma once
-
-#include "args.hh"
-#include "command.hh"
-
-namespace nix {
-
-struct Value;
-class EvalState;
-class Expr;
-
-struct Installable
-{
-    virtual std::string what() = 0;
-
-    virtual PathSet toBuildable()
-    {
-        throw Error("argument ‘%s’ cannot be built", what());
-    }
-
-    virtual Value * toValue(EvalState & state)
-    {
-        throw Error("argument ‘%s’ cannot be evaluated", what());
-    }
-};
-
-struct MixInstallables : virtual Args, StoreCommand
-{
-    std::vector<std::shared_ptr<Installable>> installables;
-    Path file;
-
-    MixInstallables()
-    {
-        mkFlag('f', "file", "file", "evaluate FILE rather than the default", &file);
-        expectArgs("installables", &_installables);
-    }
-
-    /* Return a value representing the Nix expression from which we
-       are installing. This is either the file specified by ‘--file’,
-       or an attribute set constructed from $NIX_PATH, e.g. ‘{ nixpkgs
-       = import ...; bla = import ...; }’. */
-    Value * getSourceExpr(EvalState & state);
-
-    std::vector<std::shared_ptr<Installable>> parseInstallables(ref<Store> store, Strings installables);
-
-    PathSet buildInstallables(ref<Store> store, bool dryRun);
-
-    ref<EvalState> getEvalState();
-
-    void prepare() override;
-
-private:
-
-    Strings _installables;
-
-    std::shared_ptr<EvalState> evalState;
-
-    Value * vSourceExpr = 0;
-};
-
-}
diff --git a/src/nix/log.cc b/src/nix/log.cc
index 75f3c1ab0d63..ed610261d1ca 100644
--- a/src/nix/log.cc
+++ b/src/nix/log.cc
@@ -1,12 +1,11 @@
 #include "command.hh"
 #include "common-args.hh"
-#include "installables.hh"
 #include "shared.hh"
 #include "store-api.hh"
 
 using namespace nix;
 
-struct CmdLog : MixInstallables
+struct CmdLog : InstallablesCommand
 {
     CmdLog()
     {
diff --git a/src/nix/run.cc b/src/nix/run.cc
index f3333b777805..a0ce56134b07 100644
--- a/src/nix/run.cc
+++ b/src/nix/run.cc
@@ -1,6 +1,5 @@
 #include "command.hh"
 #include "common-args.hh"
-#include "installables.hh"
 #include "shared.hh"
 #include "store-api.hh"
 #include "derivations.hh"
@@ -13,7 +12,7 @@
 
 using namespace nix;
 
-struct CmdRun : MixInstallables
+struct CmdRun : InstallablesCommand
 {
     CmdRun()
     {
diff --git a/src/nix/show-config.cc b/src/nix/show-config.cc
index e354891a82e4..c628c2898d73 100644
--- a/src/nix/show-config.cc
+++ b/src/nix/show-config.cc
@@ -1,6 +1,5 @@
 #include "command.hh"
 #include "common-args.hh"
-#include "installables.hh"
 #include "shared.hh"
 #include "store-api.hh"
 #include "json.hh"