]> git.tdb.fi Git - builder.git/commitdiff
Allow plugins to create additional targets in SourcePackages
authorMikko Rasa <tdb@tdb.fi>
Wed, 28 Dec 2022 13:38:27 +0000 (15:38 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 28 Dec 2022 15:39:11 +0000 (17:39 +0200)
source/lib/builder.h
source/lib/plugin.h
source/lib/sourcepackage.cpp

index 32d06a0be62f1d0515cdd30bf9538795bdd9277a..0455637c9ca96808de0ebff64e3c4519dd0b5ac9 100644 (file)
@@ -83,6 +83,9 @@ public:
        void load_plugins();
        PackageManager &get_package_manager() { return package_manager; }
 
+       template<typename F>
+       void call_plugins(F) const;
+
        void set_architecture(const std::string &);
        const Architecture &get_current_arch() const { return *current_arch; }
        const Architecture &get_native_arch() const { return native_arch; }
@@ -125,4 +128,11 @@ public:
        int do_create_makefile();
 };
 
+template<typename F>
+void Builder::call_plugins(F func) const
+{
+       for(const LoadedPlugin &p: plugins)
+               func(*p.plugin);
+}
+
 #endif
index 910e259ad6a6378fe3a0c1e843a7d3f790c2d53a..35cdb323c2560c67f98b78148fa6dbb682d49bad 100644 (file)
@@ -3,6 +3,7 @@
 
 class Architecture;
 class Builder;
+class SourcePackage;
 class Toolchain;
 
 class Plugin
@@ -15,6 +16,7 @@ public:
        virtual ~Plugin() = default;
 
        virtual void add_tools(Toolchain &, const Architecture &) const { }
+       virtual void create_targets(SourcePackage &) const { }
 };
 
 #endif
index 34e8a1b6ec1c6009abc366960844981902a5262e..014bd83eb9dcc99be81409c7d5e5291c2b9f41a2 100644 (file)
@@ -14,6 +14,7 @@
 #include "file.h"
 #include "installcomponent.h"
 #include "builtin/pkgconfigfile.h"
+#include "plugin.h"
 #include "sourcearchivecomponent.h"
 #include "sourcegenerator.h"
 #include "sourcepackage.h"
@@ -157,6 +158,8 @@ void SourcePackage::do_prepare()
        }
 
        new CompileCommandsJson(builder, *this);
+
+       builder.call_plugins([this](const Plugin &p){ p.create_targets(*this); });
 }
 
 void SourcePackage::save_caches()