#include <msp/io/file.h>
#include <msp/io/print.h>
#include <msp/strings/format.h>
+#include <msp/strings/utils.h>
#include <msp/time/timedelta.h>
#include <msp/time/utils.h>
#include "binarypackage.h"
FS::Path plugins_dir = FS::get_sys_lib_dir();
logger->log("files", "Traversing %s", plugins_dir);
+ vector<LoadedPlugin> unordered_plugins;
for(const string &f: list_filtered(plugins_dir, "\\.dlm$"))
{
LoadedPlugin plugin;
if(plugin.plugin)
{
logger->log("plugins", "Loaded plugin %s", f);
- plugins.emplace_back(move(plugin));
+ unordered_plugins.emplace_back(move(plugin));
continue;
}
else
logger->log("plugins", "Failed to initialize plugin %s: %s", f, exc.what());
}
}
+
+ auto have_plugin = [this](const string &r){
+ return any_of(plugins.begin(), plugins.end(), [&r](const LoadedPlugin &p){ return FS::basepart(FS::basename(p.path))==r; });
+ };
+
+ while(!unordered_plugins.empty())
+ {
+ bool any_added = false;
+ for(auto i=unordered_plugins.begin(); i!=unordered_plugins.end(); )
+ {
+ const vector<string> &required = i->plugin->get_required_plugins();
+ if(all_of(required.begin(), required.end(), have_plugin))
+ {
+ plugins.push_back(move(*i));
+ i = unordered_plugins.erase(i);
+ any_added = true;
+ }
+ else
+ ++i;
+ }
+
+ if(!any_added)
+ break;
+ }
+
+ for(const LoadedPlugin &p: unordered_plugins)
+ {
+ vector<string> missing;
+ for(const string &r: p.plugin->get_required_plugins())
+ if(!have_plugin(r))
+ missing.push_back(r);
+ logger->log("plugins", "Missing required plugins for plugin %s: %s",
+ FS::basename(p.path), join(missing.begin(), missing.end()));
+ }
}
void Builder::set_architecture(const string &name)
other.plugin = 0;
}
+Builder::LoadedPlugin &Builder::LoadedPlugin::operator=(LoadedPlugin &&other)
+{
+ delete plugin;
+ delete module;
+ path = move(other.path);
+ module = other.module;
+ plugin = other.plugin;
+ other.module = 0;
+ other.plugin = 0;
+ return *this;
+}
+
Builder::LoadedPlugin::~LoadedPlugin()
{
delete plugin;
#ifndef PLUGIN_H_
#define PLUGIN_H_
+#include <string>
+#include <vector>
#include "libbuilder_api.h"
class Architecture;
{
protected:
Builder &builder;
+ std::vector<std::string> required_plugins;
Plugin(Builder &b): builder(b) { }
public:
virtual ~Plugin() = default;
+ const std::vector<std::string> &get_required_plugins() const { return required_plugins; }
+
virtual void add_tools(Toolchain &, const Architecture &) const { }
virtual void create_targets(SourcePackage &) const { }
};