]> git.tdb.fi Git - builder.git/blobdiff - source/lib/builder.h
Make it possible to use built-in plugins
[builder.git] / source / lib / builder.h
index 0455637c9ca96808de0ebff64e3c4519dd0b5ac9..8ab0f941f8c482774d38d1f8aecd4b86b1234d43 100644 (file)
 #include "buildgraph.h"
 #include "buildtype.h"
 #include "config.h"
+#include "libbuilder_api.h"
 #include "logger.h"
 #include "packagemanager.h"
+#include "sourcepackage.h"
 #include "target.h"
 #include "toolchain.h"
 #include "virtualfilesystem.h"
 
-class FileTarget;
 class Package;
 class Plugin;
-class SourcePackage;
 
 /**
 This class ties everything else together.  It also contains code for loading
 build files and supervising the build process.
 */
-class Builder
+class LIBBUILDER_API Builder
 {
 private:
        class Loader: public Msp::DataFile::ObjectLoader<Builder>
@@ -54,11 +54,13 @@ private:
 
                LoadedPlugin() = default;
                LoadedPlugin(LoadedPlugin &&);
+               LoadedPlugin &operator=(LoadedPlugin &&);
                ~LoadedPlugin();
        };
 
        std::vector<LoadedPlugin> plugins;
        PackageManager package_manager;
+       SourcePackage::ComponentRegistry component_registry;
 
        Architecture native_arch;
        Architecture *current_arch = 0;
@@ -81,7 +83,16 @@ public:
        ~Builder();
 
        void load_plugins();
+
+       template<typename... T>
+       void load_plugins();
+
+private:
+       void add_plugins(std::vector<LoadedPlugin> &);
+
+public:
        PackageManager &get_package_manager() { return package_manager; }
+       SourcePackage::ComponentRegistry &get_component_registry() { return component_registry; }
 
        template<typename F>
        void call_plugins(F) const;
@@ -109,7 +120,10 @@ public:
        const Logger &get_logger() const { return *logger; }
 
        std::vector<std::string> collect_problems() const;
+private:
+       void collect_broken_packages(const Package &, std::vector<const Package *> &) const;
 
+public:
        /** Loads a build file.  If opts is not null, it is used to configure any
        packages loaded from this file.  If all is true, external packages are also
        configured. */
@@ -128,6 +142,20 @@ public:
        int do_create_makefile();
 };
 
+template<typename... T>
+void Builder::load_plugins()
+{
+       Plugin *raw_plugins[] = { new T(*this)... };
+       std::vector<LoadedPlugin> pending_plugins;
+       for(Plugin *p: raw_plugins)
+       {
+               LoadedPlugin plugin;
+               plugin.plugin = p;
+               pending_plugins.emplace_back(std::move(plugin));
+       }
+       add_plugins(pending_plugins);
+}
+
 template<typename F>
 void Builder::call_plugins(F func) const
 {