#include "installedfile.h"
#include "msvc/microsofttools.h"
#include "package.h"
+#include "plugin.h"
#include "sharedlibrary.h"
#include "sourcepackage.h"
#include "task.h"
delete current_arch;
}
+void Builder::load_plugins()
+{
+ using CreateFunc = Plugin *(Builder &);
+
+ FS::Path plugins_dir = FS::get_sys_lib_dir();
+ logger->log("files", "Traversing %s", plugins_dir);
+ for(const string &f: list_filtered(plugins_dir, "\\.dlm$"))
+ {
+ LoadedPlugin plugin;
+ plugin.path = plugins_dir/f;
+
+ try
+ {
+ plugin.module = new Module(plugin.path.str());
+ }
+ catch(const exception &exc)
+ {
+ logger->log("plugins", "Failed to load plugin %s: %s", f, exc.what());
+ continue;
+ }
+
+ try
+ {
+ CreateFunc *create_func = reinterpret_cast<CreateFunc *>(plugin.module->get_symbol("create_plugin"));
+ plugin.plugin = create_func(*this);
+ if(plugin.plugin)
+ {
+ logger->log("plugins", "Loaded plugin %s", f);
+ plugins.emplace_back(move(plugin));
+ continue;
+ }
+ else
+ logger->log("plugins", "Plugin %s refused to initialize", f);
+ }
+ catch(const exception &exc)
+ {
+ logger->log("plugins", "Failed to initialize plugin %s: %s", f, exc.what());
+ }
+
+ delete plugin.module;
+ }
+}
+
void Builder::set_architecture(const string &name)
{
if(current_arch!=&native_arch)
toolchain.add_toolchain(new MicrosoftTools(*this, *current_arch));
toolchain.add_toolchain(new BuiltinTools(*this));
toolchain.add_tool(new DataTool(*this));
+ for(const LoadedPlugin &p: plugins)
+ p.plugin->add_tools(toolchain, *current_arch);
auto i = find_if(toolchain.get_toolchains(), [](const Toolchain *tc){ return (tc->has_tool("CC") || tc->has_tool("CXX")); });
if(i!=toolchain.get_toolchains().end())
}
+Builder::LoadedPlugin::LoadedPlugin(LoadedPlugin &&other):
+ path(move(other.path)),
+ module(other.module),
+ plugin(other.plugin)
+{
+ other.module = 0;
+ other.plugin = 0;
+}
+
+Builder::LoadedPlugin::~LoadedPlugin()
+{
+ delete plugin;
+ delete module;
+}
+
+
Builder::Loader::Loader(Builder &b, const Config::InputOptions *o, bool a):
DataFile::ObjectLoader<Builder>(b),
options(o),