forked from lix-project/lix
Make DerivedPathWithHints
a newtype
This allows us to namespace its constructors under it.
This commit is contained in:
parent
9b805d36ac
commit
179582872d
|
@ -170,10 +170,10 @@ void MixProfile::updateProfile(const DerivedPathsWithHints & buildables)
|
||||||
|
|
||||||
for (auto & buildable : buildables) {
|
for (auto & buildable : buildables) {
|
||||||
std::visit(overloaded {
|
std::visit(overloaded {
|
||||||
[&](DerivedPathOpaque bo) {
|
[&](DerivedPathWithHints::Opaque bo) {
|
||||||
result.push_back(bo.path);
|
result.push_back(bo.path);
|
||||||
},
|
},
|
||||||
[&](DerivedPathWithHintsBuilt bfd) {
|
[&](DerivedPathWithHints::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. */
|
||||||
|
@ -181,7 +181,7 @@ void MixProfile::updateProfile(const DerivedPathsWithHints & buildables)
|
||||||
result.push_back(*output.second);
|
result.push_back(*output.second);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}, buildable);
|
}, buildable.raw());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.size() != 1)
|
if (result.size() != 1)
|
||||||
|
|
|
@ -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 {
|
||||||
DerivedPathWithHintsBuilt {
|
DerivedPathWithHints::Built {
|
||||||
.drvPath = storePath,
|
.drvPath = storePath,
|
||||||
.outputs = std::move(outputs)
|
.outputs = std::move(outputs)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
DerivedPathOpaque {
|
DerivedPathWithHints::Opaque {
|
||||||
.path = storePath,
|
.path = storePath,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -364,7 +364,7 @@ DerivedPathsWithHints InstallableValue::toDerivedPathsWithHints()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto & i : drvsToOutputs)
|
for (auto & i : drvsToOutputs)
|
||||||
res.push_back(DerivedPathWithHintsBuilt { i.first, i.second });
|
res.push_back(DerivedPathWithHints::Built { i.first, i.second });
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -684,17 +684,17 @@ DerivedPathsWithHints build(ref<Store> store, Realise mode,
|
||||||
for (auto & i : installables) {
|
for (auto & i : installables) {
|
||||||
for (auto & b : i->toDerivedPathsWithHints()) {
|
for (auto & b : i->toDerivedPathsWithHints()) {
|
||||||
std::visit(overloaded {
|
std::visit(overloaded {
|
||||||
[&](DerivedPathOpaque bo) {
|
[&](DerivedPathWithHints::Opaque bo) {
|
||||||
pathsToBuild.push_back(bo);
|
pathsToBuild.push_back(bo);
|
||||||
},
|
},
|
||||||
[&](DerivedPathWithHintsBuilt bfd) {
|
[&](DerivedPathWithHints::Built bfd) {
|
||||||
StringSet outputNames;
|
StringSet outputNames;
|
||||||
for (auto & output : bfd.outputs)
|
for (auto & output : bfd.outputs)
|
||||||
outputNames.insert(output.first);
|
outputNames.insert(output.first);
|
||||||
pathsToBuild.push_back(
|
pathsToBuild.push_back(
|
||||||
DerivedPath::Built{bfd.drvPath, outputNames});
|
DerivedPath::Built{bfd.drvPath, outputNames});
|
||||||
},
|
},
|
||||||
}, b);
|
}, b.raw());
|
||||||
buildables.push_back(std::move(b));
|
buildables.push_back(std::move(b));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -717,10 +717,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 {
|
||||||
[&](DerivedPathOpaque bo) {
|
[&](DerivedPathWithHints::Opaque bo) {
|
||||||
res.insert(bo.path);
|
res.insert(bo.path);
|
||||||
},
|
},
|
||||||
[&](DerivedPathWithHintsBuilt bfd) {
|
[&](DerivedPathWithHints::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) {
|
||||||
|
@ -745,14 +745,14 @@ std::set<RealisedPath> toRealisedPaths(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}, b);
|
}, b.raw());
|
||||||
} else {
|
} else {
|
||||||
if (mode == Realise::Nothing)
|
if (mode == Realise::Nothing)
|
||||||
settings.readOnlyMode = true;
|
settings.readOnlyMode = true;
|
||||||
|
|
||||||
for (auto & i : installables)
|
for (auto & i : installables)
|
||||||
for (auto & b : i->toDerivedPathsWithHints())
|
for (auto & b : i->toDerivedPathsWithHints())
|
||||||
if (auto bfd = std::get_if<DerivedPathWithHintsBuilt>(&b))
|
if (auto bfd = std::get_if<DerivedPathWithHints::Built>(&b))
|
||||||
res.insert(bfd->drvPath);
|
res.insert(bfd->drvPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -789,7 +789,7 @@ StorePathSet toDerivations(ref<Store> store,
|
||||||
for (auto & i : installables)
|
for (auto & i : installables)
|
||||||
for (auto & b : i->toDerivedPathsWithHints())
|
for (auto & b : i->toDerivedPathsWithHints())
|
||||||
std::visit(overloaded {
|
std::visit(overloaded {
|
||||||
[&](DerivedPathOpaque bo) {
|
[&](DerivedPathWithHints::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);
|
||||||
|
@ -798,10 +798,10 @@ StorePathSet toDerivations(ref<Store> store,
|
||||||
// FIXME: use all derivers?
|
// FIXME: use all derivers?
|
||||||
drvPaths.insert(*derivers.begin());
|
drvPaths.insert(*derivers.begin());
|
||||||
},
|
},
|
||||||
[&](DerivedPathWithHintsBuilt bfd) {
|
[&](DerivedPathWithHints::Built bfd) {
|
||||||
drvPaths.insert(bfd.drvPath);
|
drvPaths.insert(bfd.drvPath);
|
||||||
},
|
},
|
||||||
}, b);
|
}, b.raw());
|
||||||
|
|
||||||
return drvPaths;
|
return drvPaths;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ nlohmann::json DerivedPath::Opaque::toJSON(ref<Store> store) const {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json DerivedPathWithHintsBuilt::toJSON(ref<Store> store) const {
|
nlohmann::json DerivedPathWithHints::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) {
|
||||||
|
@ -25,7 +25,7 @@ nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildab
|
||||||
for (const DerivedPathWithHints & buildable : buildables) {
|
for (const DerivedPathWithHints & 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);
|
}, buildable.raw());
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,11 +56,24 @@ struct DerivedPathWithHintsBuilt {
|
||||||
static DerivedPathWithHintsBuilt parse(const Store & store, std::string_view);
|
static DerivedPathWithHintsBuilt parse(const Store & store, std::string_view);
|
||||||
};
|
};
|
||||||
|
|
||||||
using DerivedPathWithHints = std::variant<
|
using _DerivedPathWithHintsRaw = std::variant<
|
||||||
DerivedPath::Opaque,
|
DerivedPath::Opaque,
|
||||||
DerivedPathWithHintsBuilt
|
DerivedPathWithHintsBuilt
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
struct DerivedPathWithHints : _DerivedPathWithHintsRaw {
|
||||||
|
using Raw = _DerivedPathWithHintsRaw;
|
||||||
|
using Raw::Raw;
|
||||||
|
|
||||||
|
using Opaque = DerivedPathOpaque;
|
||||||
|
using Built = DerivedPathWithHintsBuilt;
|
||||||
|
|
||||||
|
inline const Raw & raw() const {
|
||||||
|
return static_cast<const Raw &>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
typedef std::vector<DerivedPathWithHints> DerivedPathsWithHints;
|
typedef std::vector<DerivedPathWithHints> DerivedPathsWithHints;
|
||||||
|
|
||||||
nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildables, ref<Store> store);
|
nlohmann::json derivedPathsWithHintsToJSON(const DerivedPathsWithHints & buildables, ref<Store> store);
|
||||||
|
|
|
@ -61,12 +61,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 {
|
||||||
[&](DerivedPathOpaque bo) {
|
[&](DerivedPathWithHints::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));
|
||||||
},
|
},
|
||||||
[&](DerivedPathWithHintsBuilt bfd) {
|
[&](DerivedPathWithHints::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;
|
||||||
|
@ -75,7 +75,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
|
||||||
store2->addPermRoot(output.second, absPath(symlink));
|
store2->addPermRoot(output.second, absPath(symlink));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}, buildable);
|
}, buildable.raw());
|
||||||
}
|
}
|
||||||
|
|
||||||
updateProfile(buildables);
|
updateProfile(buildables);
|
||||||
|
|
|
@ -277,14 +277,14 @@ struct Common : InstallableCommand, MixProfile
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
std::visit(overloaded {
|
std::visit(overloaded {
|
||||||
[&](const DerivedPathOpaque & bo) {
|
[&](const DerivedPathWithHints::Opaque & bo) {
|
||||||
doRedirect(bo.path);
|
doRedirect(bo.path);
|
||||||
},
|
},
|
||||||
[&](const DerivedPathWithHintsBuilt & bfd) {
|
[&](const DerivedPathWithHints::Built & bfd) {
|
||||||
for (auto & [outputName, path] : bfd.outputs)
|
for (auto & [outputName, path] : bfd.outputs)
|
||||||
if (path) doRedirect(*path);
|
if (path) doRedirect(*path);
|
||||||
},
|
},
|
||||||
}, buildable);
|
}, buildable.raw());
|
||||||
}
|
}
|
||||||
|
|
||||||
return rewriteStrings(script, rewrites);
|
return rewriteStrings(script, rewrites);
|
||||||
|
|
|
@ -35,13 +35,13 @@ struct CmdLog : InstallableCommand
|
||||||
RunPager pager;
|
RunPager pager;
|
||||||
for (auto & sub : subs) {
|
for (auto & sub : subs) {
|
||||||
auto log = std::visit(overloaded {
|
auto log = std::visit(overloaded {
|
||||||
[&](DerivedPathOpaque bo) {
|
[&](DerivedPathWithHints::Opaque bo) {
|
||||||
return sub->getBuildLog(bo.path);
|
return sub->getBuildLog(bo.path);
|
||||||
},
|
},
|
||||||
[&](DerivedPathWithHintsBuilt bfd) {
|
[&](DerivedPathWithHints::Built bfd) {
|
||||||
return sub->getBuildLog(bfd.drvPath);
|
return sub->getBuildLog(bfd.drvPath);
|
||||||
},
|
},
|
||||||
}, b);
|
}, b.raw());
|
||||||
if (!log) continue;
|
if (!log) continue;
|
||||||
stopProgressBar();
|
stopProgressBar();
|
||||||
printInfo("got build log for '%s' from '%s'", installable->what(), sub->getUri());
|
printInfo("got build log for '%s' from '%s'", installable->what(), sub->getUri());
|
||||||
|
|
|
@ -259,11 +259,11 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
|
||||||
ProfileElement element;
|
ProfileElement element;
|
||||||
|
|
||||||
std::visit(overloaded {
|
std::visit(overloaded {
|
||||||
[&](DerivedPathOpaque bo) {
|
[&](DerivedPathWithHints::Opaque bo) {
|
||||||
pathsToBuild.push_back(bo);
|
pathsToBuild.push_back(bo);
|
||||||
element.storePaths.insert(bo.path);
|
element.storePaths.insert(bo.path);
|
||||||
},
|
},
|
||||||
[&](DerivedPathWithHintsBuilt bfd) {
|
[&](DerivedPathWithHints::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?
|
||||||
|
@ -272,7 +272,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
|
||||||
element.storePaths.insert(output.second);
|
element.storePaths.insert(output.second);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}, buildable);
|
}, buildable.raw());
|
||||||
|
|
||||||
manifest.elements.emplace_back(std::move(element));
|
manifest.elements.emplace_back(std::move(element));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue