From: Mikko Rasa Date: Sun, 12 Mar 2023 11:20:27 +0000 (+0200) Subject: Make it possible to use built-in plugins X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ba5078a4334ef419aeb1949190a743a05037750c;p=builder.git Make it possible to use built-in plugins --- diff --git a/plugins/android/androidplugin.cpp b/plugins/android/androidplugin.cpp index 5fc357e..ecd4610 100644 --- a/plugins/android/androidplugin.cpp +++ b/plugins/android/androidplugin.cpp @@ -18,6 +18,7 @@ void AndroidPlugin::add_tools(Toolchain &toolchain, const Architecture &arch) co } +#ifdef ANDROIDTOOLS_BUILD #if defined(_WIN32) #define ANDROIDTOOLS_API __declspec(dllexport) #elif defined(__GNUC__) @@ -31,3 +32,4 @@ ANDROIDTOOLS_API Plugin *create_plugin(Builder &builder) { return new AndroidPlugin(builder); } +#endif diff --git a/plugins/base/baseplugin.cpp b/plugins/base/baseplugin.cpp index 0da610c..0f05fa8 100644 --- a/plugins/base/baseplugin.cpp +++ b/plugins/base/baseplugin.cpp @@ -24,6 +24,7 @@ void BasePlugin::create_targets(SourcePackage &spkg) const } +#ifdef BASETOOLS_BUILD #if defined(_WIN32) #define BASETOOLS_API __declspec(dllexport) #elif defined(__GNUC__) @@ -37,3 +38,4 @@ BASETOOLS_API Plugin *create_plugin(Builder &builder) { return new BasePlugin(builder); } +#endif diff --git a/plugins/clang/clangplugin.cpp b/plugins/clang/clangplugin.cpp index 96a1df8..b33c756 100644 --- a/plugins/clang/clangplugin.cpp +++ b/plugins/clang/clangplugin.cpp @@ -13,6 +13,7 @@ void ClangPlugin::add_tools(Toolchain &toolchain, const Architecture &arch) cons } +#ifdef CLANGTOOLS_BUILD #if defined(_WIN32) #define CLANGTOOLS_API __declspec(dllexport) #elif defined(__GNUC__) @@ -26,3 +27,4 @@ CLANGTOOLS_API Plugin *create_plugin(Builder &builder) { return new ClangPlugin(builder); } +#endif diff --git a/plugins/datafile/datafileplugin.cpp b/plugins/datafile/datafileplugin.cpp index 134ec0e..349e55b 100644 --- a/plugins/datafile/datafileplugin.cpp +++ b/plugins/datafile/datafileplugin.cpp @@ -15,6 +15,7 @@ void DataFilePlugin::add_tools(Toolchain &toolchain, const Architecture &) const } +#ifdef DATATOOLS_BUILD #if defined(_WIN32) #define DATATOOLS_API __declspec(dllexport) #elif defined(__GNUC__) @@ -28,3 +29,4 @@ DATATOOLS_API Plugin *create_plugin(Builder &builder) { return new DataFilePlugin(builder); } +#endif diff --git a/plugins/gnu/gnuplugin.cpp b/plugins/gnu/gnuplugin.cpp index db8c300..5a600af 100644 --- a/plugins/gnu/gnuplugin.cpp +++ b/plugins/gnu/gnuplugin.cpp @@ -7,6 +7,7 @@ void GnuPlugin::add_tools(Toolchain &toolchain, const Architecture &arch) const } +#ifdef GNUTOOLS_BUILD #if defined(_WIN32) #define GNUTOOLS_API __declspec(dllexport) #elif defined(__GNUC__) @@ -20,3 +21,4 @@ GNUTOOLS_API Plugin *create_plugin(Builder &builder) { return new GnuPlugin(builder); } +#endif diff --git a/plugins/msvc/msvcplugin.cpp b/plugins/msvc/msvcplugin.cpp index bf1e26e..fdb0bf2 100644 --- a/plugins/msvc/msvcplugin.cpp +++ b/plugins/msvc/msvcplugin.cpp @@ -23,6 +23,7 @@ void MsvcPlugin::create_targets(SourcePackage &spkg) const } +#ifdef MSVCTOOLS_BUILD #if defined(_WIN32) #define MSVCTOOLS_API __declspec(dllexport) #elif defined(__GNUC__) @@ -36,3 +37,4 @@ MSVCTOOLS_API Plugin *create_plugin(Builder &builder) { return new MsvcPlugin(builder); } +#endif diff --git a/source/lib/builder.cpp b/source/lib/builder.cpp index 3379f2d..f979d28 100644 --- a/source/lib/builder.cpp +++ b/source/lib/builder.cpp @@ -87,6 +87,11 @@ void Builder::load_plugins() } } + add_plugins(unordered_plugins); +} + +void Builder::add_plugins(vector &unordered_plugins) +{ 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; }); }; diff --git a/source/lib/builder.h b/source/lib/builder.h index d9a942b..8ab0f94 100644 --- a/source/lib/builder.h +++ b/source/lib/builder.h @@ -83,6 +83,14 @@ public: ~Builder(); void load_plugins(); + + template + void load_plugins(); + +private: + void add_plugins(std::vector &); + +public: PackageManager &get_package_manager() { return package_manager; } SourcePackage::ComponentRegistry &get_component_registry() { return component_registry; } @@ -134,6 +142,20 @@ public: int do_create_makefile(); }; +template +void Builder::load_plugins() +{ + Plugin *raw_plugins[] = { new T(*this)... }; + std::vector pending_plugins; + for(Plugin *p: raw_plugins) + { + LoadedPlugin plugin; + plugin.plugin = p; + pending_plugins.emplace_back(std::move(plugin)); + } + add_plugins(pending_plugins); +} + template void Builder::call_plugins(F func) const {