aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd/installables.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2022-07-14 16:36:00 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2022-07-14 19:37:55 -0400
commitf3262bc2165af90fd20f04f74243aa75137767a2 (patch)
treec7f0c2b86c266a73d4bee05000f6a88085426f43 /src/libcmd/installables.cc
parent6cafe308c946af7658514ad0e6970cc464554fbb (diff)
Combine `InstallableStorePath` with `InstallableIndexedStorePath`
No behavior should be changed, the `isDerivation` logic is moved from the methods to the constructor.
Diffstat (limited to 'src/libcmd/installables.cc')
-rw-r--r--src/libcmd/installables.cc82
1 files changed, 37 insertions, 45 deletions
diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
index b78581a7c..7b8860a88 100644
--- a/src/libcmd/installables.cc
+++ b/src/libcmd/installables.cc
@@ -395,53 +395,21 @@ static StorePath getDeriver(
struct InstallableStorePath : Installable
{
ref<Store> store;
- StorePath storePath;
+ DerivedPath req;
InstallableStorePath(ref<Store> store, StorePath && storePath)
- : store(store), storePath(std::move(storePath)) { }
-
- std::string what() const override { return store->printStorePath(storePath); }
-
- DerivedPaths toDerivedPaths() override
- {
- if (storePath.isDerivation()) {
- auto drv = store->readDerivation(storePath);
- return {
- DerivedPath::Built {
- .drvPath = storePath,
- .outputs = drv.outputNames(),
- }
- };
- } else {
- return {
- DerivedPath::Opaque {
- .path = storePath,
- }
- };
- }
- }
-
- StorePathSet toDrvPaths(ref<Store> store) override
- {
- if (storePath.isDerivation()) {
- return {storePath};
- } else {
- return {getDeriver(store, *this, storePath)};
- }
- }
-
- std::optional<StorePath> getStorePath() override
- {
- return storePath;
- }
-};
-
-struct InstallableIndexedStorePath : Installable
-{
- ref<Store> store;
- DerivedPath::Built req;
+ : store(store),
+ req(storePath.isDerivation()
+ ? (DerivedPath) DerivedPath::Built {
+ .drvPath = std::move(storePath),
+ .outputs = {},
+ }
+ : (DerivedPath) DerivedPath::Opaque {
+ .path = std::move(storePath),
+ })
+ { }
- InstallableIndexedStorePath(ref<Store> store, DerivedPath::Built && req)
+ InstallableStorePath(ref<Store> store, DerivedPath && req)
: store(store), req(std::move(req))
{ }
@@ -454,6 +422,30 @@ struct InstallableIndexedStorePath : Installable
{
return { req };
}
+
+ StorePathSet toDrvPaths(ref<Store> store) override
+ {
+ return std::visit(overloaded {
+ [&](const DerivedPath::Built & bfd) -> StorePathSet {
+ return { bfd.drvPath };
+ },
+ [&](const DerivedPath::Opaque & bo) -> StorePathSet {
+ return { getDeriver(store, *this, bo.path) };
+ },
+ }, req.raw());
+ }
+
+ std::optional<StorePath> getStorePath() override
+ {
+ return std::visit(overloaded {
+ [&](const DerivedPath::Built & bfd) {
+ return bfd.drvPath;
+ },
+ [&](const DerivedPath::Opaque & bo) {
+ return bo.path;
+ },
+ }, req.raw());
+ }
};
DerivedPaths InstallableValue::toDerivedPaths()
@@ -819,7 +811,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
auto found = s.rfind('^');
if (found != std::string::npos) {
try {
- result.push_back(std::make_shared<InstallableIndexedStorePath>(
+ result.push_back(std::make_shared<InstallableStorePath>(
store,
DerivedPath::Built::parse(*store, s.substr(0, found), s.substr(found + 1))));
settings.requireExperimentalFeature(Xp::ComputedDerivations);