DerivedPathWithHints -> BuiltPath

Just a renaming for now
This commit is contained in:
regnat 2021-05-12 16:19:51 +02:00
parent 7f9759b18d
commit ec613603ba
10 changed files with 49 additions and 49 deletions

View file

@ -162,7 +162,7 @@ void MixProfile::updateProfile(const StorePath & storePath)
profile2, storePath)); profile2, storePath));
} }
void MixProfile::updateProfile(const DerivedPathsWithHints & buildables) void MixProfile::updateProfile(const BuiltPaths & buildables)
{ {
if (!profile) return; if (!profile) return;
@ -170,10 +170,10 @@ void MixProfile::updateProfile(const DerivedPathsWithHints & buildables)
for (auto & buildable : buildables) { for (auto & buildable : buildables) {
std::visit(overloaded { std::visit(overloaded {
[&](DerivedPathWithHints::Opaque bo) { [&](BuiltPath::Opaque bo) {
result.push_back(bo.path); result.push_back(bo.path);
}, },
[&](DerivedPathWithHints::Built bfd) { [&](BuiltPath::Built bfd) {
for (auto & output : bfd.outputs) { for (auto & output : bfd.outputs) {
/* Output path should be known because we just tried to /* Output path should be known because we just tried to
build it. */ build it. */

View file

@ -216,7 +216,7 @@ static RegisterCommand registerCommand2(std::vector<std::string> && name)
return RegisterCommand(std::move(name), [](){ return make_ref<T>(); }); return RegisterCommand(std::move(name), [](){ return make_ref<T>(); });
} }
DerivedPathsWithHints build(ref<Store> store, Realise mode, BuiltPaths build(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables, BuildMode bMode = bmNormal); std::vector<std::shared_ptr<Installable>> installables, BuildMode bMode = bmNormal);
std::set<StorePath> toStorePaths(ref<Store> store, std::set<StorePath> toStorePaths(ref<Store> store,
@ -252,7 +252,7 @@ struct MixProfile : virtual StoreCommand
/* If 'profile' is set, make it point at the store path produced /* If 'profile' is set, make it point at the store path produced
by 'buildables'. */ by 'buildables'. */
void updateProfile(const DerivedPathsWithHints & buildables); void updateProfile(const BuiltPaths & buildables);
}; };
struct MixDefaultProfile : MixProfile struct MixDefaultProfile : MixProfile

View file

@ -285,9 +285,9 @@ void completeFlakeRef(ref<Store> store, std::string_view prefix)
} }
} }
DerivedPathWithHints Installable::toDerivedPathWithHints() BuiltPath Installable::toBuiltPath()
{ {
auto buildables = toDerivedPathsWithHints(); auto buildables = toBuiltPaths();
if (buildables.size() != 1) if (buildables.size() != 1)
throw Error("installable '%s' evaluates to %d derivations, where only one is expected", what(), buildables.size()); throw Error("installable '%s' evaluates to %d derivations, where only one is expected", what(), buildables.size());
return std::move(buildables[0]); return std::move(buildables[0]);
@ -321,7 +321,7 @@ struct InstallableStorePath : Installable
std::string what() override { return store->printStorePath(storePath); } std::string what() override { return store->printStorePath(storePath); }
DerivedPathsWithHints toDerivedPathsWithHints() override BuiltPaths toBuiltPaths() override
{ {
if (storePath.isDerivation()) { if (storePath.isDerivation()) {
std::map<std::string, std::optional<StorePath>> outputs; std::map<std::string, std::optional<StorePath>> outputs;
@ -329,14 +329,14 @@ struct InstallableStorePath : Installable
for (auto & [name, output] : drv.outputsAndOptPaths(*store)) for (auto & [name, output] : drv.outputsAndOptPaths(*store))
outputs.emplace(name, output.second); outputs.emplace(name, output.second);
return { return {
DerivedPathWithHints::Built { BuiltPath::Built {
.drvPath = storePath, .drvPath = storePath,
.outputs = std::move(outputs) .outputs = std::move(outputs)
} }
}; };
} else { } else {
return { return {
DerivedPathWithHints::Opaque { BuiltPath::Opaque {
.path = storePath, .path = storePath,
} }
}; };
@ -349,9 +349,9 @@ struct InstallableStorePath : Installable
} }
}; };
DerivedPathsWithHints InstallableValue::toDerivedPathsWithHints() BuiltPaths InstallableValue::toBuiltPaths()
{ {
DerivedPathsWithHints res; BuiltPaths res;
std::map<StorePath, std::map<std::string, std::optional<StorePath>>> drvsToOutputs; std::map<StorePath, std::map<std::string, std::optional<StorePath>>> drvsToOutputs;
@ -364,7 +364,7 @@ DerivedPathsWithHints InstallableValue::toDerivedPathsWithHints()
} }
for (auto & i : drvsToOutputs) for (auto & i : drvsToOutputs)
res.push_back(DerivedPathWithHints::Built { i.first, i.second }); res.push_back(BuiltPath::Built { i.first, i.second });
return res; return res;
} }
@ -675,23 +675,23 @@ std::shared_ptr<Installable> SourceExprCommand::parseInstallable(
return installables.front(); return installables.front();
} }
DerivedPathsWithHints build(ref<Store> store, Realise mode, BuiltPaths build(ref<Store> store, Realise mode,
std::vector<std::shared_ptr<Installable>> installables, BuildMode bMode) std::vector<std::shared_ptr<Installable>> installables, BuildMode bMode)
{ {
if (mode == Realise::Nothing) if (mode == Realise::Nothing)
settings.readOnlyMode = true; settings.readOnlyMode = true;
DerivedPathsWithHints buildables; BuiltPaths buildables;
std::vector<DerivedPath> pathsToBuild; std::vector<DerivedPath> pathsToBuild;
for (auto & i : installables) { for (auto & i : installables) {
for (auto & b : i->toDerivedPathsWithHints()) { for (auto & b : i->toBuiltPaths()) {
std::visit(overloaded { std::visit(overloaded {
[&](DerivedPathWithHints::Opaque bo) { [&](BuiltPath::Opaque bo) {
pathsToBuild.push_back(bo); pathsToBuild.push_back(bo);
}, },
[&](DerivedPathWithHints::Built bfd) { [&](BuiltPath::Built bfd) {
StringSet outputNames; StringSet outputNames;
for (auto & output : bfd.outputs) for (auto & output : bfd.outputs)
outputNames.insert(output.first); outputNames.insert(output.first);
@ -721,10 +721,10 @@ std::set<RealisedPath> toRealisedPaths(
if (operateOn == OperateOn::Output) { if (operateOn == OperateOn::Output) {
for (auto & b : build(store, mode, installables)) for (auto & b : build(store, mode, installables))
std::visit(overloaded { std::visit(overloaded {
[&](DerivedPathWithHints::Opaque bo) { [&](BuiltPath::Opaque bo) {
res.insert(bo.path); res.insert(bo.path);
}, },
[&](DerivedPathWithHints::Built bfd) { [&](BuiltPath::Built bfd) {
auto drv = store->readDerivation(bfd.drvPath); auto drv = store->readDerivation(bfd.drvPath);
auto outputHashes = staticOutputHashes(*store, drv); auto outputHashes = staticOutputHashes(*store, drv);
for (auto & output : bfd.outputs) { for (auto & output : bfd.outputs) {
@ -789,9 +789,9 @@ StorePathSet toDerivations(ref<Store> store,
StorePathSet drvPaths; StorePathSet drvPaths;
for (auto & i : installables) for (auto & i : installables)
for (auto & b : i->toDerivedPathsWithHints()) for (auto & b : i->toBuiltPaths())
std::visit(overloaded { std::visit(overloaded {
[&](DerivedPathWithHints::Opaque bo) { [&](BuiltPath::Opaque bo) {
if (!useDeriver) if (!useDeriver)
throw Error("argument '%s' did not evaluate to a derivation", i->what()); throw Error("argument '%s' did not evaluate to a derivation", i->what());
auto derivers = store->queryValidDerivers(bo.path); auto derivers = store->queryValidDerivers(bo.path);
@ -800,7 +800,7 @@ StorePathSet toDerivations(ref<Store> store,
// FIXME: use all derivers? // FIXME: use all derivers?
drvPaths.insert(*derivers.begin()); drvPaths.insert(*derivers.begin());
}, },
[&](DerivedPathWithHints::Built bfd) { [&](BuiltPath::Built bfd) {
drvPaths.insert(bfd.drvPath); drvPaths.insert(bfd.drvPath);
}, },
}, b.raw()); }, b.raw());

View file

@ -29,9 +29,9 @@ struct Installable
virtual std::string what() = 0; virtual std::string what() = 0;
virtual DerivedPathsWithHints toDerivedPathsWithHints() = 0; virtual BuiltPaths toBuiltPaths() = 0;
DerivedPathWithHints toDerivedPathWithHints(); BuiltPath toBuiltPath();
App toApp(EvalState & state); App toApp(EvalState & state);
@ -74,7 +74,7 @@ struct InstallableValue : Installable
virtual std::vector<DerivationInfo> toDerivations() = 0; virtual std::vector<DerivationInfo> toDerivations() = 0;
DerivedPathsWithHints toDerivedPathsWithHints() override; BuiltPaths toBuiltPaths() override;
}; };
struct InstallableFlake : InstallableValue struct InstallableFlake : InstallableValue

View file

@ -11,7 +11,7 @@ nlohmann::json DerivedPath::Opaque::toJSON(ref<Store> store) const {
return res; return res;
} }
nlohmann::json DerivedPathWithHints::Built::toJSON(ref<Store> store) const { nlohmann::json BuiltPath::Built::toJSON(ref<Store> store) const {
nlohmann::json res; nlohmann::json res;
res["drvPath"] = store->printStorePath(drvPath); res["drvPath"] = store->printStorePath(drvPath);
for (const auto& [output, path] : outputs) { for (const auto& [output, path] : outputs) {
@ -20,9 +20,9 @@ nlohmann::json DerivedPathWithHints::Built::toJSON(ref<Store> store) const {
return res; return res;
} }
nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildables, ref<Store> store) { nlohmann::json derivedPathsWithHintsToJSON(const BuiltPaths & buildables, ref<Store> store) {
auto res = nlohmann::json::array(); auto res = nlohmann::json::array();
for (const DerivedPathWithHints & buildable : buildables) { for (const BuiltPath & buildable : buildables) {
std::visit([&res, store](const auto & buildable) { std::visit([&res, store](const auto & buildable) {
res.push_back(buildable.toJSON(store)); res.push_back(buildable.toJSON(store));
}, buildable.raw()); }, buildable.raw());

View file

@ -79,19 +79,19 @@ struct DerivedPath : _DerivedPathRaw {
/** /**
* A built derived path with hints in the form of optional concrete output paths. * A built derived path with hints in the form of optional concrete output paths.
* *
* See 'DerivedPathWithHints' for more an explanation. * See 'BuiltPath' for more an explanation.
*/ */
struct DerivedPathWithHintsBuilt { struct BuiltPathBuilt {
StorePath drvPath; StorePath drvPath;
std::map<std::string, std::optional<StorePath>> outputs; std::map<std::string, std::optional<StorePath>> outputs;
nlohmann::json toJSON(ref<Store> store) const; nlohmann::json toJSON(ref<Store> store) const;
static DerivedPathWithHintsBuilt parse(const Store & store, std::string_view); static BuiltPathBuilt parse(const Store & store, std::string_view);
}; };
using _DerivedPathWithHintsRaw = std::variant< using _BuiltPathRaw = std::variant<
DerivedPath::Opaque, DerivedPath::Opaque,
DerivedPathWithHintsBuilt BuiltPathBuilt
>; >;
/** /**
@ -109,12 +109,12 @@ using _DerivedPathWithHintsRaw = std::variant<
* paths. * paths.
*/ */
// FIXME Stop using and delete this, or if that is not possible move out of libstore to libcmd. // FIXME Stop using and delete this, or if that is not possible move out of libstore to libcmd.
struct DerivedPathWithHints : _DerivedPathWithHintsRaw { struct BuiltPath : _BuiltPathRaw {
using Raw = _DerivedPathWithHintsRaw; using Raw = _BuiltPathRaw;
using Raw::Raw; using Raw::Raw;
using Opaque = DerivedPathOpaque; using Opaque = DerivedPathOpaque;
using Built = DerivedPathWithHintsBuilt; using Built = BuiltPathBuilt;
inline const Raw & raw() const { inline const Raw & raw() const {
return static_cast<const Raw &>(*this); return static_cast<const Raw &>(*this);
@ -122,8 +122,8 @@ struct DerivedPathWithHints : _DerivedPathWithHintsRaw {
}; };
typedef std::vector<DerivedPathWithHints> DerivedPathsWithHints; typedef std::vector<BuiltPath> BuiltPaths;
nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildables, ref<Store> store); nlohmann::json derivedPathsWithHintsToJSON(const BuiltPaths & buildables, ref<Store> store);
} }

View file

@ -63,12 +63,12 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
for (const auto & [_i, buildable] : enumerate(buildables)) { for (const auto & [_i, buildable] : enumerate(buildables)) {
auto i = _i; auto i = _i;
std::visit(overloaded { std::visit(overloaded {
[&](DerivedPathWithHints::Opaque bo) { [&](BuiltPath::Opaque bo) {
std::string symlink = outLink; std::string symlink = outLink;
if (i) symlink += fmt("-%d", i); if (i) symlink += fmt("-%d", i);
store2->addPermRoot(bo.path, absPath(symlink)); store2->addPermRoot(bo.path, absPath(symlink));
}, },
[&](DerivedPathWithHints::Built bfd) { [&](BuiltPath::Built bfd) {
auto builtOutputs = store->queryDerivationOutputMap(bfd.drvPath); auto builtOutputs = store->queryDerivationOutputMap(bfd.drvPath);
for (auto & output : builtOutputs) { for (auto & output : builtOutputs) {
std::string symlink = outLink; std::string symlink = outLink;

View file

@ -265,7 +265,7 @@ struct Common : InstallableCommand, MixProfile
for (auto & [installable_, dir_] : redirects) { for (auto & [installable_, dir_] : redirects) {
auto dir = absPath(dir_); auto dir = absPath(dir_);
auto installable = parseInstallable(store, installable_); auto installable = parseInstallable(store, installable_);
auto buildable = installable->toDerivedPathWithHints(); auto buildable = installable->toBuiltPath();
auto doRedirect = [&](const StorePath & path) auto doRedirect = [&](const StorePath & path)
{ {
auto from = store->printStorePath(path); auto from = store->printStorePath(path);
@ -277,10 +277,10 @@ struct Common : InstallableCommand, MixProfile
} }
}; };
std::visit(overloaded { std::visit(overloaded {
[&](const DerivedPathWithHints::Opaque & bo) { [&](const BuiltPath::Opaque & bo) {
doRedirect(bo.path); doRedirect(bo.path);
}, },
[&](const DerivedPathWithHints::Built & bfd) { [&](const BuiltPath::Built & bfd) {
for (auto & [outputName, path] : bfd.outputs) for (auto & [outputName, path] : bfd.outputs)
if (path) doRedirect(*path); if (path) doRedirect(*path);
}, },

View file

@ -30,15 +30,15 @@ struct CmdLog : InstallableCommand
subs.push_front(store); subs.push_front(store);
auto b = installable->toDerivedPathWithHints(); auto b = installable->toBuiltPath();
RunPager pager; RunPager pager;
for (auto & sub : subs) { for (auto & sub : subs) {
auto log = std::visit(overloaded { auto log = std::visit(overloaded {
[&](DerivedPathWithHints::Opaque bo) { [&](BuiltPath::Opaque bo) {
return sub->getBuildLog(bo.path); return sub->getBuildLog(bo.path);
}, },
[&](DerivedPathWithHints::Built bfd) { [&](BuiltPath::Built bfd) {
return sub->getBuildLog(bfd.drvPath); return sub->getBuildLog(bfd.drvPath);
}, },
}, b.raw()); }, b.raw());

View file

@ -259,11 +259,11 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
ProfileElement element; ProfileElement element;
std::visit(overloaded { std::visit(overloaded {
[&](DerivedPathWithHints::Opaque bo) { [&](BuiltPath::Opaque bo) {
pathsToBuild.push_back(bo); pathsToBuild.push_back(bo);
element.storePaths.insert(bo.path); element.storePaths.insert(bo.path);
}, },
[&](DerivedPathWithHints::Built bfd) { [&](BuiltPath::Built bfd) {
// TODO: Why are we querying if we know the output // TODO: Why are we querying if we know the output
// names already? Is it just to figure out what the // names already? Is it just to figure out what the
// default one is? // default one is?