From d5535ad0823221b326b47f4549bd546118e72599 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 28 Dec 2022 15:38:27 +0200 Subject: [PATCH] Allow plugins to create additional targets in SourcePackages --- source/lib/builder.h | 10 ++++++++++ source/lib/plugin.h | 2 ++ source/lib/sourcepackage.cpp | 3 +++ 3 files changed, 15 insertions(+) diff --git a/source/lib/builder.h b/source/lib/builder.h index 32d06a0..0455637 100644 --- a/source/lib/builder.h +++ b/source/lib/builder.h @@ -83,6 +83,9 @@ public: void load_plugins(); PackageManager &get_package_manager() { return package_manager; } + template + 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 +void Builder::call_plugins(F func) const +{ + for(const LoadedPlugin &p: plugins) + func(*p.plugin); +} + #endif diff --git a/source/lib/plugin.h b/source/lib/plugin.h index 910e259..35cdb32 100644 --- a/source/lib/plugin.h +++ b/source/lib/plugin.h @@ -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 diff --git a/source/lib/sourcepackage.cpp b/source/lib/sourcepackage.cpp index 34e8a1b..014bd83 100644 --- a/source/lib/sourcepackage.cpp +++ b/source/lib/sourcepackage.cpp @@ -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() -- 2.45.2