forked from NixOS/nix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move value-only methods to
InstallableValue
These methods would previously fail on the other `Installable`s, so moving them to this class is more correct as to where they actually work. Additionally, a `InstallableValueCommand` is created to make it easier (or rather no worse than before) to write commands that just work on `InstallableValue`s. Besides being a cleanup to avoid failing default methods, this gets us closer to NixOS/rfcs#134.
- Loading branch information
1 parent
acd707a
commit c998e01
Showing
14 changed files
with
127 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "command-installable-value.hh" | ||
|
||
namespace nix { | ||
|
||
void InstallableValueCommand::run(ref<Store> store, ref<Installable> installable) | ||
{ | ||
auto installableValue = InstallableValue::require(installable); | ||
run(store, installableValue); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "installable-value.hh" | ||
#include "command.hh" | ||
|
||
namespace nix { | ||
|
||
struct InstallableValueCommand : InstallableCommand | ||
{ | ||
virtual void run(ref<Store> store, ref<InstallableValue> installable) = 0; | ||
|
||
void run(ref<Store> store, ref<Installable> installable) override; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "installable-value.hh" | ||
#include "eval-cache.hh" | ||
|
||
namespace nix { | ||
|
||
std::vector<ref<eval_cache::AttrCursor>> | ||
InstallableValue::getCursors(EvalState & state) | ||
{ | ||
auto evalCache = | ||
std::make_shared<nix::eval_cache::EvalCache>(std::nullopt, state, | ||
[&]() { return toValue(state).first; }); | ||
return {evalCache->getRoot()}; | ||
} | ||
|
||
ref<eval_cache::AttrCursor> | ||
InstallableValue::getCursor(EvalState & state) | ||
{ | ||
/* Although getCursors should return at least one element, in case it doesn't, | ||
bound check to avoid an undefined behavior for vector[0] */ | ||
return getCursors(state).at(0); | ||
} | ||
|
||
static UsageError nonValueInstallable(Installable & installable) | ||
{ | ||
return UsageError("installable '%s' does not correspond to a Nix language value", installable.what()); | ||
} | ||
|
||
InstallableValue & InstallableValue::require(Installable & installable) | ||
{ | ||
auto * castedInstallable = dynamic_cast<InstallableValue *>(&installable); | ||
if (!castedInstallable) | ||
throw nonValueInstallable(installable); | ||
return *castedInstallable; | ||
} | ||
|
||
ref<InstallableValue> InstallableValue::require(ref<Installable> installable) | ||
{ | ||
auto castedInstallable = installable.dynamic_pointer_cast<InstallableValue>(); | ||
if (!castedInstallable) | ||
throw nonValueInstallable(*installable); | ||
return ref { castedInstallable }; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters