2019-10-14 15:40:16 +03:00
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
///@file
|
2019-10-14 15:40:16 +03:00
|
|
|
|
2019-12-11 15:53:30 +02:00
|
|
|
#include "path.hh"
|
2023-01-10 18:27:19 +02:00
|
|
|
#include "outputs-spec.hh"
|
2021-04-05 17:33:28 +03:00
|
|
|
#include "derived-path.hh"
|
2023-07-13 05:22:44 +03:00
|
|
|
#include "built-path.hh"
|
2022-03-02 14:54:08 +02:00
|
|
|
#include "store-api.hh"
|
2022-11-21 11:49:01 +02:00
|
|
|
#include "build-result.hh"
|
2019-10-14 15:40:16 +03:00
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2019-10-22 01:21:58 +03:00
|
|
|
struct DrvInfo;
|
2020-04-20 14:13:52 +03:00
|
|
|
|
2022-03-02 14:54:08 +02:00
|
|
|
enum class Realise {
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* Build the derivation.
|
|
|
|
*
|
|
|
|
* Postcondition: the derivation outputs exist.
|
|
|
|
*/
|
2022-03-02 14:54:08 +02:00
|
|
|
Outputs,
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* Don't build the derivation.
|
|
|
|
*
|
|
|
|
* Postcondition: the store derivation exists.
|
|
|
|
*/
|
2022-03-02 14:54:08 +02:00
|
|
|
Derivation,
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* Evaluate in dry-run mode.
|
|
|
|
*
|
|
|
|
* Postcondition: nothing.
|
|
|
|
*
|
|
|
|
* \todo currently unused, but could be revived if we can evaluate
|
|
|
|
* derivations in-memory.
|
|
|
|
*/
|
2022-03-02 14:54:08 +02:00
|
|
|
Nothing
|
|
|
|
};
|
|
|
|
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* How to handle derivations in commands that operate on store paths.
|
|
|
|
*/
|
2022-03-02 14:54:08 +02:00
|
|
|
enum class OperateOn {
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* Operate on the output path.
|
|
|
|
*/
|
2022-03-02 14:54:08 +02:00
|
|
|
Output,
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* Operate on the .drv path.
|
|
|
|
*/
|
2022-03-02 14:54:08 +02:00
|
|
|
Derivation
|
|
|
|
};
|
|
|
|
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* Extra info about a DerivedPath
|
|
|
|
*
|
|
|
|
* Yes, this is empty, but that is intended. It will be sub-classed by
|
|
|
|
* the subclasses of Installable to allow those to provide more info.
|
|
|
|
* Certain commands will make use of this info.
|
|
|
|
*/
|
2023-01-10 15:52:49 +02:00
|
|
|
struct ExtraPathInfo
|
2022-12-15 23:09:32 +02:00
|
|
|
{
|
2023-02-06 06:28:18 +02:00
|
|
|
virtual ~ExtraPathInfo() = default;
|
2022-12-15 23:09:32 +02:00
|
|
|
};
|
|
|
|
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* A DerivedPath with \ref ExtraPathInfo "any additional info" that
|
|
|
|
* commands might need from the derivation.
|
|
|
|
*/
|
2022-12-15 23:09:32 +02:00
|
|
|
struct DerivedPathWithInfo
|
|
|
|
{
|
|
|
|
DerivedPath path;
|
2023-02-06 06:28:18 +02:00
|
|
|
ref<ExtraPathInfo> info;
|
2022-12-15 23:09:32 +02:00
|
|
|
};
|
|
|
|
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* Like DerivedPathWithInfo but extending BuiltPath with \ref
|
|
|
|
* ExtraPathInfo "extra info" and also possibly the \ref BuildResult
|
|
|
|
* "result of building".
|
|
|
|
*/
|
2022-11-21 11:49:01 +02:00
|
|
|
struct BuiltPathWithResult
|
|
|
|
{
|
|
|
|
BuiltPath path;
|
2023-02-06 06:28:18 +02:00
|
|
|
ref<ExtraPathInfo> info;
|
2022-11-21 11:49:01 +02:00
|
|
|
std::optional<BuildResult> result;
|
|
|
|
};
|
|
|
|
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* Shorthand, for less typing and helping us keep the choice of
|
|
|
|
* collection in sync.
|
|
|
|
*/
|
2022-12-15 23:09:32 +02:00
|
|
|
typedef std::vector<DerivedPathWithInfo> DerivedPathsWithInfo;
|
|
|
|
|
Make command infra less stateful and more regular
Already, we had classes like `BuiltPathsCommand` and `StorePathsCommand`
which provided alternative `run` virtual functions providing the
implementation with more arguments. This was a very nice and easy way to
make writing command; just fill in the virtual functions and it is
fairly clear what to do.
However, exception to this pattern were `Installable{,s}Command`. These
two classes instead just had a field where the installables would be
stored, and various side-effecting `prepare` and `load` machinery too
fill them in. Command would wish out those fields.
This isn't so clear to use.
What this commit does is make those command classes like the others,
with richer `run` functions.
Not only does this restore the pattern making commands easier to write,
it has a number of other benefits:
- `prepare` and `load` are gone entirely! One command just hands just
hands off to the next.
- `useDefaultInstallables` because `defaultInstallables`. This takes
over `prepare` for the one case that needs it, and provides enough
flexiblity to handle `nix repl`'s idiosyncratic migration.
- We can use `ref` instead of `std::shared_ptr`. The former must be
initialized (so it is like Rust's `Box` rather than `Option<Box>`,
This expresses the invariant that the installable are in fact
initialized much better.
This is possible because since we just have local variables not
fields, we can stop worrying about the not-yet-initialized case.
- Fewer lines of code! (Finally I have a large refactor that makes the
number go down not up...)
- `nix repl` is now implemented in a clearer way.
The last item deserves further mention. `nix repl` is not like the other
installable commands because instead working from once-loaded
installables, it needs to be able to load them again and again.
To properly support this, we make a new superclass
`RawInstallablesCommand`. This class has the argument parsing and
completion logic, but does *not* hand off parsed installables but
instead just the raw string arguments.
This is exactly what `nix repl` needs, and allows us to instead of
having the logic awkwardly split between `prepare`,
`useDefaultInstallables,` and `load`, have everything right next to each
other. I think this will enable future simplifications of that argument
defaulting logic, but I am saving those for a future PR --- best to keep
code motion and more complicated boolean expression rewriting separate
steps.
The "diagnostic ignored `-Woverloaded-virtual`" pragma helps because C++
doesn't like our many `run` methods. In our case, we don't mind the
shadowing it all --- it is *intentional* that the derived class only
provides a `run` method, and doesn't call any of the overridden `run`
methods.
Helps with https://github.com/NixOS/rfcs/pull/134
2023-02-04 19:03:47 +02:00
|
|
|
struct Installable;
|
2023-02-06 06:28:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shorthand, for less typing and helping us keep the choice of
|
|
|
|
* collection in sync.
|
|
|
|
*/
|
Make command infra less stateful and more regular
Already, we had classes like `BuiltPathsCommand` and `StorePathsCommand`
which provided alternative `run` virtual functions providing the
implementation with more arguments. This was a very nice and easy way to
make writing command; just fill in the virtual functions and it is
fairly clear what to do.
However, exception to this pattern were `Installable{,s}Command`. These
two classes instead just had a field where the installables would be
stored, and various side-effecting `prepare` and `load` machinery too
fill them in. Command would wish out those fields.
This isn't so clear to use.
What this commit does is make those command classes like the others,
with richer `run` functions.
Not only does this restore the pattern making commands easier to write,
it has a number of other benefits:
- `prepare` and `load` are gone entirely! One command just hands just
hands off to the next.
- `useDefaultInstallables` because `defaultInstallables`. This takes
over `prepare` for the one case that needs it, and provides enough
flexiblity to handle `nix repl`'s idiosyncratic migration.
- We can use `ref` instead of `std::shared_ptr`. The former must be
initialized (so it is like Rust's `Box` rather than `Option<Box>`,
This expresses the invariant that the installable are in fact
initialized much better.
This is possible because since we just have local variables not
fields, we can stop worrying about the not-yet-initialized case.
- Fewer lines of code! (Finally I have a large refactor that makes the
number go down not up...)
- `nix repl` is now implemented in a clearer way.
The last item deserves further mention. `nix repl` is not like the other
installable commands because instead working from once-loaded
installables, it needs to be able to load them again and again.
To properly support this, we make a new superclass
`RawInstallablesCommand`. This class has the argument parsing and
completion logic, but does *not* hand off parsed installables but
instead just the raw string arguments.
This is exactly what `nix repl` needs, and allows us to instead of
having the logic awkwardly split between `prepare`,
`useDefaultInstallables,` and `load`, have everything right next to each
other. I think this will enable future simplifications of that argument
defaulting logic, but I am saving those for a future PR --- best to keep
code motion and more complicated boolean expression rewriting separate
steps.
The "diagnostic ignored `-Woverloaded-virtual`" pragma helps because C++
doesn't like our many `run` methods. In our case, we don't mind the
shadowing it all --- it is *intentional* that the derived class only
provides a `run` method, and doesn't call any of the overridden `run`
methods.
Helps with https://github.com/NixOS/rfcs/pull/134
2023-02-04 19:03:47 +02:00
|
|
|
typedef std::vector<ref<Installable>> Installables;
|
|
|
|
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* Installables are the main positional arguments for the Nix
|
|
|
|
* Command-line.
|
|
|
|
*
|
|
|
|
* This base class is very flexible, and just assumes and the
|
|
|
|
* Installable refers to a collection of \ref DerivedPath "derived paths" with
|
|
|
|
* \ref ExtraPathInfo "extra info".
|
|
|
|
*/
|
2019-10-14 15:40:16 +03:00
|
|
|
struct Installable
|
|
|
|
{
|
|
|
|
virtual ~Installable() { }
|
|
|
|
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* What Installable is this?
|
|
|
|
*
|
|
|
|
* Prints back valid CLI syntax that would result in this same
|
|
|
|
* installable. It doesn't need to be exactly what the user wrote,
|
|
|
|
* just something that means the same thing.
|
|
|
|
*/
|
2022-01-18 18:28:18 +02:00
|
|
|
virtual std::string what() const = 0;
|
2019-10-14 15:40:16 +03:00
|
|
|
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* Get the collection of \ref DerivedPathWithInfo "derived paths
|
|
|
|
* with info" that this \ref Installable instalallable denotes.
|
|
|
|
*
|
|
|
|
* This is the main method of this class
|
|
|
|
*/
|
2022-12-15 23:09:32 +02:00
|
|
|
virtual DerivedPathsWithInfo toDerivedPaths() = 0;
|
2022-01-18 18:28:18 +02:00
|
|
|
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* A convenience wrapper of the above for when we expect an
|
|
|
|
* installable to produce a single \ref DerivedPath "derived path"
|
|
|
|
* only.
|
|
|
|
*
|
|
|
|
* If no or multiple \ref DerivedPath "derived paths" are produced,
|
|
|
|
* and error is raised.
|
|
|
|
*/
|
2022-12-15 23:09:32 +02:00
|
|
|
DerivedPathWithInfo toDerivedPath();
|
2019-10-14 15:40:16 +03:00
|
|
|
|
2023-02-06 06:28:18 +02:00
|
|
|
/**
|
|
|
|
* Return a value only if this installable is a store path or a
|
|
|
|
* symlink to it.
|
|
|
|
*
|
|
|
|
* \todo should we move this to InstallableDerivedPath? It is only
|
|
|
|
* supposed to work there anyways. Can always downcast.
|
|
|
|
*/
|
2019-12-11 15:53:30 +02:00
|
|
|
virtual std::optional<StorePath> getStorePath()
|
2019-10-14 15:40:16 +03:00
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
2020-04-20 16:27:09 +03:00
|
|
|
|
2022-11-21 11:49:01 +02:00
|
|
|
static std::vector<BuiltPathWithResult> build(
|
2022-03-02 14:54:08 +02:00
|
|
|
ref<Store> evalStore,
|
|
|
|
ref<Store> store,
|
|
|
|
Realise mode,
|
Make command infra less stateful and more regular
Already, we had classes like `BuiltPathsCommand` and `StorePathsCommand`
which provided alternative `run` virtual functions providing the
implementation with more arguments. This was a very nice and easy way to
make writing command; just fill in the virtual functions and it is
fairly clear what to do.
However, exception to this pattern were `Installable{,s}Command`. These
two classes instead just had a field where the installables would be
stored, and various side-effecting `prepare` and `load` machinery too
fill them in. Command would wish out those fields.
This isn't so clear to use.
What this commit does is make those command classes like the others,
with richer `run` functions.
Not only does this restore the pattern making commands easier to write,
it has a number of other benefits:
- `prepare` and `load` are gone entirely! One command just hands just
hands off to the next.
- `useDefaultInstallables` because `defaultInstallables`. This takes
over `prepare` for the one case that needs it, and provides enough
flexiblity to handle `nix repl`'s idiosyncratic migration.
- We can use `ref` instead of `std::shared_ptr`. The former must be
initialized (so it is like Rust's `Box` rather than `Option<Box>`,
This expresses the invariant that the installable are in fact
initialized much better.
This is possible because since we just have local variables not
fields, we can stop worrying about the not-yet-initialized case.
- Fewer lines of code! (Finally I have a large refactor that makes the
number go down not up...)
- `nix repl` is now implemented in a clearer way.
The last item deserves further mention. `nix repl` is not like the other
installable commands because instead working from once-loaded
installables, it needs to be able to load them again and again.
To properly support this, we make a new superclass
`RawInstallablesCommand`. This class has the argument parsing and
completion logic, but does *not* hand off parsed installables but
instead just the raw string arguments.
This is exactly what `nix repl` needs, and allows us to instead of
having the logic awkwardly split between `prepare`,
`useDefaultInstallables,` and `load`, have everything right next to each
other. I think this will enable future simplifications of that argument
defaulting logic, but I am saving those for a future PR --- best to keep
code motion and more complicated boolean expression rewriting separate
steps.
The "diagnostic ignored `-Woverloaded-virtual`" pragma helps because C++
doesn't like our many `run` methods. In our case, we don't mind the
shadowing it all --- it is *intentional* that the derived class only
provides a `run` method, and doesn't call any of the overridden `run`
methods.
Helps with https://github.com/NixOS/rfcs/pull/134
2023-02-04 19:03:47 +02:00
|
|
|
const Installables & installables,
|
2022-03-02 14:54:08 +02:00
|
|
|
BuildMode bMode = bmNormal);
|
|
|
|
|
Make command infra less stateful and more regular
Already, we had classes like `BuiltPathsCommand` and `StorePathsCommand`
which provided alternative `run` virtual functions providing the
implementation with more arguments. This was a very nice and easy way to
make writing command; just fill in the virtual functions and it is
fairly clear what to do.
However, exception to this pattern were `Installable{,s}Command`. These
two classes instead just had a field where the installables would be
stored, and various side-effecting `prepare` and `load` machinery too
fill them in. Command would wish out those fields.
This isn't so clear to use.
What this commit does is make those command classes like the others,
with richer `run` functions.
Not only does this restore the pattern making commands easier to write,
it has a number of other benefits:
- `prepare` and `load` are gone entirely! One command just hands just
hands off to the next.
- `useDefaultInstallables` because `defaultInstallables`. This takes
over `prepare` for the one case that needs it, and provides enough
flexiblity to handle `nix repl`'s idiosyncratic migration.
- We can use `ref` instead of `std::shared_ptr`. The former must be
initialized (so it is like Rust's `Box` rather than `Option<Box>`,
This expresses the invariant that the installable are in fact
initialized much better.
This is possible because since we just have local variables not
fields, we can stop worrying about the not-yet-initialized case.
- Fewer lines of code! (Finally I have a large refactor that makes the
number go down not up...)
- `nix repl` is now implemented in a clearer way.
The last item deserves further mention. `nix repl` is not like the other
installable commands because instead working from once-loaded
installables, it needs to be able to load them again and again.
To properly support this, we make a new superclass
`RawInstallablesCommand`. This class has the argument parsing and
completion logic, but does *not* hand off parsed installables but
instead just the raw string arguments.
This is exactly what `nix repl` needs, and allows us to instead of
having the logic awkwardly split between `prepare`,
`useDefaultInstallables,` and `load`, have everything right next to each
other. I think this will enable future simplifications of that argument
defaulting logic, but I am saving those for a future PR --- best to keep
code motion and more complicated boolean expression rewriting separate
steps.
The "diagnostic ignored `-Woverloaded-virtual`" pragma helps because C++
doesn't like our many `run` methods. In our case, we don't mind the
shadowing it all --- it is *intentional* that the derived class only
provides a `run` method, and doesn't call any of the overridden `run`
methods.
Helps with https://github.com/NixOS/rfcs/pull/134
2023-02-04 19:03:47 +02:00
|
|
|
static std::vector<std::pair<ref<Installable>, BuiltPathWithResult>> build2(
|
2022-03-28 15:21:35 +03:00
|
|
|
ref<Store> evalStore,
|
|
|
|
ref<Store> store,
|
|
|
|
Realise mode,
|
Make command infra less stateful and more regular
Already, we had classes like `BuiltPathsCommand` and `StorePathsCommand`
which provided alternative `run` virtual functions providing the
implementation with more arguments. This was a very nice and easy way to
make writing command; just fill in the virtual functions and it is
fairly clear what to do.
However, exception to this pattern were `Installable{,s}Command`. These
two classes instead just had a field where the installables would be
stored, and various side-effecting `prepare` and `load` machinery too
fill them in. Command would wish out those fields.
This isn't so clear to use.
What this commit does is make those command classes like the others,
with richer `run` functions.
Not only does this restore the pattern making commands easier to write,
it has a number of other benefits:
- `prepare` and `load` are gone entirely! One command just hands just
hands off to the next.
- `useDefaultInstallables` because `defaultInstallables`. This takes
over `prepare` for the one case that needs it, and provides enough
flexiblity to handle `nix repl`'s idiosyncratic migration.
- We can use `ref` instead of `std::shared_ptr`. The former must be
initialized (so it is like Rust's `Box` rather than `Option<Box>`,
This expresses the invariant that the installable are in fact
initialized much better.
This is possible because since we just have local variables not
fields, we can stop worrying about the not-yet-initialized case.
- Fewer lines of code! (Finally I have a large refactor that makes the
number go down not up...)
- `nix repl` is now implemented in a clearer way.
The last item deserves further mention. `nix repl` is not like the other
installable commands because instead working from once-loaded
installables, it needs to be able to load them again and again.
To properly support this, we make a new superclass
`RawInstallablesCommand`. This class has the argument parsing and
completion logic, but does *not* hand off parsed installables but
instead just the raw string arguments.
This is exactly what `nix repl` needs, and allows us to instead of
having the logic awkwardly split between `prepare`,
`useDefaultInstallables,` and `load`, have everything right next to each
other. I think this will enable future simplifications of that argument
defaulting logic, but I am saving those for a future PR --- best to keep
code motion and more complicated boolean expression rewriting separate
steps.
The "diagnostic ignored `-Woverloaded-virtual`" pragma helps because C++
doesn't like our many `run` methods. In our case, we don't mind the
shadowing it all --- it is *intentional* that the derived class only
provides a `run` method, and doesn't call any of the overridden `run`
methods.
Helps with https://github.com/NixOS/rfcs/pull/134
2023-02-04 19:03:47 +02:00
|
|
|
const Installables & installables,
|
2022-03-28 15:21:35 +03:00
|
|
|
BuildMode bMode = bmNormal);
|
|
|
|
|
2022-03-02 14:54:08 +02:00
|
|
|
static std::set<StorePath> toStorePaths(
|
|
|
|
ref<Store> evalStore,
|
|
|
|
ref<Store> store,
|
|
|
|
Realise mode,
|
|
|
|
OperateOn operateOn,
|
Make command infra less stateful and more regular
Already, we had classes like `BuiltPathsCommand` and `StorePathsCommand`
which provided alternative `run` virtual functions providing the
implementation with more arguments. This was a very nice and easy way to
make writing command; just fill in the virtual functions and it is
fairly clear what to do.
However, exception to this pattern were `Installable{,s}Command`. These
two classes instead just had a field where the installables would be
stored, and various side-effecting `prepare` and `load` machinery too
fill them in. Command would wish out those fields.
This isn't so clear to use.
What this commit does is make those command classes like the others,
with richer `run` functions.
Not only does this restore the pattern making commands easier to write,
it has a number of other benefits:
- `prepare` and `load` are gone entirely! One command just hands just
hands off to the next.
- `useDefaultInstallables` because `defaultInstallables`. This takes
over `prepare` for the one case that needs it, and provides enough
flexiblity to handle `nix repl`'s idiosyncratic migration.
- We can use `ref` instead of `std::shared_ptr`. The former must be
initialized (so it is like Rust's `Box` rather than `Option<Box>`,
This expresses the invariant that the installable are in fact
initialized much better.
This is possible because since we just have local variables not
fields, we can stop worrying about the not-yet-initialized case.
- Fewer lines of code! (Finally I have a large refactor that makes the
number go down not up...)
- `nix repl` is now implemented in a clearer way.
The last item deserves further mention. `nix repl` is not like the other
installable commands because instead working from once-loaded
installables, it needs to be able to load them again and again.
To properly support this, we make a new superclass
`RawInstallablesCommand`. This class has the argument parsing and
completion logic, but does *not* hand off parsed installables but
instead just the raw string arguments.
This is exactly what `nix repl` needs, and allows us to instead of
having the logic awkwardly split between `prepare`,
`useDefaultInstallables,` and `load`, have everything right next to each
other. I think this will enable future simplifications of that argument
defaulting logic, but I am saving those for a future PR --- best to keep
code motion and more complicated boolean expression rewriting separate
steps.
The "diagnostic ignored `-Woverloaded-virtual`" pragma helps because C++
doesn't like our many `run` methods. In our case, we don't mind the
shadowing it all --- it is *intentional* that the derived class only
provides a `run` method, and doesn't call any of the overridden `run`
methods.
Helps with https://github.com/NixOS/rfcs/pull/134
2023-02-04 19:03:47 +02:00
|
|
|
const Installables & installables);
|
2022-03-02 14:54:08 +02:00
|
|
|
|
|
|
|
static StorePath toStorePath(
|
|
|
|
ref<Store> evalStore,
|
|
|
|
ref<Store> store,
|
|
|
|
Realise mode,
|
|
|
|
OperateOn operateOn,
|
Make command infra less stateful and more regular
Already, we had classes like `BuiltPathsCommand` and `StorePathsCommand`
which provided alternative `run` virtual functions providing the
implementation with more arguments. This was a very nice and easy way to
make writing command; just fill in the virtual functions and it is
fairly clear what to do.
However, exception to this pattern were `Installable{,s}Command`. These
two classes instead just had a field where the installables would be
stored, and various side-effecting `prepare` and `load` machinery too
fill them in. Command would wish out those fields.
This isn't so clear to use.
What this commit does is make those command classes like the others,
with richer `run` functions.
Not only does this restore the pattern making commands easier to write,
it has a number of other benefits:
- `prepare` and `load` are gone entirely! One command just hands just
hands off to the next.
- `useDefaultInstallables` because `defaultInstallables`. This takes
over `prepare` for the one case that needs it, and provides enough
flexiblity to handle `nix repl`'s idiosyncratic migration.
- We can use `ref` instead of `std::shared_ptr`. The former must be
initialized (so it is like Rust's `Box` rather than `Option<Box>`,
This expresses the invariant that the installable are in fact
initialized much better.
This is possible because since we just have local variables not
fields, we can stop worrying about the not-yet-initialized case.
- Fewer lines of code! (Finally I have a large refactor that makes the
number go down not up...)
- `nix repl` is now implemented in a clearer way.
The last item deserves further mention. `nix repl` is not like the other
installable commands because instead working from once-loaded
installables, it needs to be able to load them again and again.
To properly support this, we make a new superclass
`RawInstallablesCommand`. This class has the argument parsing and
completion logic, but does *not* hand off parsed installables but
instead just the raw string arguments.
This is exactly what `nix repl` needs, and allows us to instead of
having the logic awkwardly split between `prepare`,
`useDefaultInstallables,` and `load`, have everything right next to each
other. I think this will enable future simplifications of that argument
defaulting logic, but I am saving those for a future PR --- best to keep
code motion and more complicated boolean expression rewriting separate
steps.
The "diagnostic ignored `-Woverloaded-virtual`" pragma helps because C++
doesn't like our many `run` methods. In our case, we don't mind the
shadowing it all --- it is *intentional* that the derived class only
provides a `run` method, and doesn't call any of the overridden `run`
methods.
Helps with https://github.com/NixOS/rfcs/pull/134
2023-02-04 19:03:47 +02:00
|
|
|
ref<Installable> installable);
|
2022-03-02 14:54:08 +02:00
|
|
|
|
|
|
|
static std::set<StorePath> toDerivations(
|
|
|
|
ref<Store> store,
|
Make command infra less stateful and more regular
Already, we had classes like `BuiltPathsCommand` and `StorePathsCommand`
which provided alternative `run` virtual functions providing the
implementation with more arguments. This was a very nice and easy way to
make writing command; just fill in the virtual functions and it is
fairly clear what to do.
However, exception to this pattern were `Installable{,s}Command`. These
two classes instead just had a field where the installables would be
stored, and various side-effecting `prepare` and `load` machinery too
fill them in. Command would wish out those fields.
This isn't so clear to use.
What this commit does is make those command classes like the others,
with richer `run` functions.
Not only does this restore the pattern making commands easier to write,
it has a number of other benefits:
- `prepare` and `load` are gone entirely! One command just hands just
hands off to the next.
- `useDefaultInstallables` because `defaultInstallables`. This takes
over `prepare` for the one case that needs it, and provides enough
flexiblity to handle `nix repl`'s idiosyncratic migration.
- We can use `ref` instead of `std::shared_ptr`. The former must be
initialized (so it is like Rust's `Box` rather than `Option<Box>`,
This expresses the invariant that the installable are in fact
initialized much better.
This is possible because since we just have local variables not
fields, we can stop worrying about the not-yet-initialized case.
- Fewer lines of code! (Finally I have a large refactor that makes the
number go down not up...)
- `nix repl` is now implemented in a clearer way.
The last item deserves further mention. `nix repl` is not like the other
installable commands because instead working from once-loaded
installables, it needs to be able to load them again and again.
To properly support this, we make a new superclass
`RawInstallablesCommand`. This class has the argument parsing and
completion logic, but does *not* hand off parsed installables but
instead just the raw string arguments.
This is exactly what `nix repl` needs, and allows us to instead of
having the logic awkwardly split between `prepare`,
`useDefaultInstallables,` and `load`, have everything right next to each
other. I think this will enable future simplifications of that argument
defaulting logic, but I am saving those for a future PR --- best to keep
code motion and more complicated boolean expression rewriting separate
steps.
The "diagnostic ignored `-Woverloaded-virtual`" pragma helps because C++
doesn't like our many `run` methods. In our case, we don't mind the
shadowing it all --- it is *intentional* that the derived class only
provides a `run` method, and doesn't call any of the overridden `run`
methods.
Helps with https://github.com/NixOS/rfcs/pull/134
2023-02-04 19:03:47 +02:00
|
|
|
const Installables & installables,
|
2022-03-02 14:54:08 +02:00
|
|
|
bool useDeriver = false);
|
|
|
|
|
|
|
|
static BuiltPaths toBuiltPaths(
|
|
|
|
ref<Store> evalStore,
|
|
|
|
ref<Store> store,
|
|
|
|
Realise mode,
|
|
|
|
OperateOn operateOn,
|
Make command infra less stateful and more regular
Already, we had classes like `BuiltPathsCommand` and `StorePathsCommand`
which provided alternative `run` virtual functions providing the
implementation with more arguments. This was a very nice and easy way to
make writing command; just fill in the virtual functions and it is
fairly clear what to do.
However, exception to this pattern were `Installable{,s}Command`. These
two classes instead just had a field where the installables would be
stored, and various side-effecting `prepare` and `load` machinery too
fill them in. Command would wish out those fields.
This isn't so clear to use.
What this commit does is make those command classes like the others,
with richer `run` functions.
Not only does this restore the pattern making commands easier to write,
it has a number of other benefits:
- `prepare` and `load` are gone entirely! One command just hands just
hands off to the next.
- `useDefaultInstallables` because `defaultInstallables`. This takes
over `prepare` for the one case that needs it, and provides enough
flexiblity to handle `nix repl`'s idiosyncratic migration.
- We can use `ref` instead of `std::shared_ptr`. The former must be
initialized (so it is like Rust's `Box` rather than `Option<Box>`,
This expresses the invariant that the installable are in fact
initialized much better.
This is possible because since we just have local variables not
fields, we can stop worrying about the not-yet-initialized case.
- Fewer lines of code! (Finally I have a large refactor that makes the
number go down not up...)
- `nix repl` is now implemented in a clearer way.
The last item deserves further mention. `nix repl` is not like the other
installable commands because instead working from once-loaded
installables, it needs to be able to load them again and again.
To properly support this, we make a new superclass
`RawInstallablesCommand`. This class has the argument parsing and
completion logic, but does *not* hand off parsed installables but
instead just the raw string arguments.
This is exactly what `nix repl` needs, and allows us to instead of
having the logic awkwardly split between `prepare`,
`useDefaultInstallables,` and `load`, have everything right next to each
other. I think this will enable future simplifications of that argument
defaulting logic, but I am saving those for a future PR --- best to keep
code motion and more complicated boolean expression rewriting separate
steps.
The "diagnostic ignored `-Woverloaded-virtual`" pragma helps because C++
doesn't like our many `run` methods. In our case, we don't mind the
shadowing it all --- it is *intentional* that the derived class only
provides a `run` method, and doesn't call any of the overridden `run`
methods.
Helps with https://github.com/NixOS/rfcs/pull/134
2023-02-04 19:03:47 +02:00
|
|
|
const Installables & installables);
|
2019-10-14 15:40:16 +03:00
|
|
|
};
|
2022-05-20 08:48:24 +03:00
|
|
|
|
2019-10-14 15:40:16 +03:00
|
|
|
}
|