15using PluginsByName = std::map<std::string, const PluginManifest*, std::less<>>;
21 std::vector<std::string> spreading;
22 for (
const auto& [name, reason] : refused)
24 spreading.push_back(name);
27 const auto refuse = [&](
const std::string& name,
Error reason) {
28 if (refused.emplace(name, std::move(reason)).second)
30 spreading.push_back(name);
34 for (
const auto& [name, manifest] : plugins)
36 for (
const std::string& dependency : manifest->Dependencies)
38 if (!plugins.contains(dependency))
40 refuse(name,
Error::NotFound(std::format(
"requires '{}', which is not installed", dependency)));
46 while (!spreading.empty())
48 const std::string gone = std::move(spreading.back());
51 for (
const auto& [name, manifest] : plugins)
53 if (!refused.contains(name) && std::ranges::contains(manifest->Dependencies, gone))
55 refuse(name,
Error::NotReady(std::format(
"requires '{}', which the host refused", gone)));
67 if (!plugins.emplace(manifest.Name, &manifest).second)
69 refused.emplace(manifest.Name,
Error::Invalid(
"installed more than once; each plugin directory needs its "
77 for (
const auto& [name, manifest] : plugins)
79 if (!refused.contains(name))
81 list.
ToLoad.push_back(name);
85 for (
auto& [name, reason] : refused)
87 list.
Refused.push_back({name, std::move(reason)});
94 std::span<const PluginManifest> loaded)
96 std::set<std::string, std::less<>> dependents;
97 std::vector<std::string> spreading{std::string(plugin)};
98 while (!spreading.empty())
100 const std::string needed = std::move(spreading.back());
101 spreading.pop_back();
105 if (manifest.Name != plugin && !dependents.contains(manifest.Name) &&
106 std::ranges::contains(manifest.Dependencies, needed))
108 dependents.insert(manifest.Name);
109 spreading.push_back(manifest.Name);
114 return {dependents.begin(), dependents.end()};
LoadList Resolve(std::span< const PluginManifest > installed)
Decide which of installed the host loads.
std::vector< std::string > RequiredDependents(std::string_view plugin, std::span< const PluginManifest > loaded)
static void RefuseUnsatisfied(const PluginsByName &plugins, RefusalsByName &refused)
std::map< std::string, const PluginManifest *, std::less<> > PluginsByName
std::map< std::string, Error, std::less<> > RefusalsByName
One failure: a code to branch on, text for the log, and an optional translation key.
static Error Invalid(std::string detail)
static Error NotFound(std::string detail)
static Error NotReady(std::string detail)
std::vector< std::string > ToLoad
std::vector< RefusedPlugin > Refused