From d3e9e3db18a9fb6024fced0fe506752763c91c7f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 28 Dec 2022 15:39:12 +0200 Subject: [PATCH] Convert builtin tools into a plugin --- .gitignore | 2 +- Build | 13 +++---- plugins/base/baseplugin.cpp | 39 +++++++++++++++++++ plugins/base/baseplugin.h | 15 +++++++ .../builtintools.cpp => base/basetools.cpp} | 0 .../builtintools.h => base/basetools.h} | 0 .../compilecommandsgenerator.cpp | 0 .../compilecommandsgenerator.h | 0 .../{builtin => base}/compilecommandsjson.cpp | 0 .../{builtin => base}/compilecommandsjson.h | 0 plugins/{builtin => base}/copy.cpp | 0 plugins/{builtin => base}/copy.h | 0 plugins/{builtin => base}/pkgconfigfile.cpp | 0 plugins/{builtin => base}/pkgconfigfile.h | 0 .../{builtin => base}/pkgconfiggenerator.cpp | 0 .../{builtin => base}/pkgconfiggenerator.h | 0 plugins/{builtin => base}/tar.cpp | 0 plugins/{builtin => base}/tar.h | 0 plugins/{builtin => base}/tarball.cpp | 0 plugins/{builtin => base}/tarball.h | 0 plugins/{builtin => base}/vcxprojectfile.cpp | 0 plugins/{builtin => base}/vcxprojectfile.h | 0 .../{builtin => base}/vcxprojectgenerator.cpp | 0 .../{builtin => base}/vcxprojectgenerator.h | 0 plugins/{builtin => base}/vssolutionfile.cpp | 0 plugins/{builtin => base}/vssolutionfile.h | 0 .../{builtin => base}/vssolutiongenerator.cpp | 0 .../{builtin => base}/vssolutiongenerator.h | 0 source/lib/builder.cpp | 2 - source/lib/sourcepackage.cpp | 19 --------- 30 files changed, 61 insertions(+), 29 deletions(-) create mode 100644 plugins/base/baseplugin.cpp create mode 100644 plugins/base/baseplugin.h rename plugins/{builtin/builtintools.cpp => base/basetools.cpp} (100%) rename plugins/{builtin/builtintools.h => base/basetools.h} (100%) rename plugins/{builtin => base}/compilecommandsgenerator.cpp (100%) rename plugins/{builtin => base}/compilecommandsgenerator.h (100%) rename plugins/{builtin => base}/compilecommandsjson.cpp (100%) rename plugins/{builtin => base}/compilecommandsjson.h (100%) rename plugins/{builtin => base}/copy.cpp (100%) rename plugins/{builtin => base}/copy.h (100%) rename plugins/{builtin => base}/pkgconfigfile.cpp (100%) rename plugins/{builtin => base}/pkgconfigfile.h (100%) rename plugins/{builtin => base}/pkgconfiggenerator.cpp (100%) rename plugins/{builtin => base}/pkgconfiggenerator.h (100%) rename plugins/{builtin => base}/tar.cpp (100%) rename plugins/{builtin => base}/tar.h (100%) rename plugins/{builtin => base}/tarball.cpp (100%) rename plugins/{builtin => base}/tarball.h (100%) rename plugins/{builtin => base}/vcxprojectfile.cpp (100%) rename plugins/{builtin => base}/vcxprojectfile.h (100%) rename plugins/{builtin => base}/vcxprojectgenerator.cpp (100%) rename plugins/{builtin => base}/vcxprojectgenerator.h (100%) rename plugins/{builtin => base}/vssolutionfile.cpp (100%) rename plugins/{builtin => base}/vssolutionfile.h (100%) rename plugins/{builtin => base}/vssolutiongenerator.cpp (100%) rename plugins/{builtin => base}/vssolutiongenerator.h (100%) diff --git a/.gitignore b/.gitignore index 6bfc7f6..dc00fb7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,12 +2,12 @@ /builder /builder.pc /builder-stage1 +/builtintools.dlm /clangtools.dlm /gnutools.dlm /libbuilder.a /libbuilder.so /libandroidtools.a -/libbuiltintools.a /libdatatools.a /msvctools.dlm /temp diff --git a/Build b/Build index 794c3f3..2cf1583 100644 --- a/Build +++ b/Build @@ -13,12 +13,6 @@ package "builder" standard CXX "c++11"; }; - library "builtintools" - { - source "plugins/builtin"; - default false; - }; - library "androidtools" { source "plugins/android"; @@ -34,7 +28,6 @@ package "builder" library "libbuilder" { source "source/lib"; - use "builtintools"; use "androidtools"; use "datatools"; build_info @@ -63,6 +56,12 @@ package "builder" install true; }; + module "builtintools" + { + source "plugins/builtin"; + install true; + }; + module "gnutools" { source "plugins/gnu"; diff --git a/plugins/base/baseplugin.cpp b/plugins/base/baseplugin.cpp new file mode 100644 index 0000000..3646d10 --- /dev/null +++ b/plugins/base/baseplugin.cpp @@ -0,0 +1,39 @@ +#include +#include +#include "builtinplugin.h" +#include "builtintools.h" +#include "compilecommandsjson.h" +#include "pkgconfigfile.h" +#include "vcxprojectfile.h" +#include "vssolutionfile.h" + +void BuiltinPlugin::add_tools(Toolchain &toolchain, const Architecture &) const +{ + toolchain.add_toolchain(new BuiltinTools(builder)); +} + +void BuiltinPlugin::create_targets(SourcePackage &spkg) const +{ + const Architecture &native_arch = builder.get_native_arch(); + + if(!spkg.get_exported_build_info().libs.empty() && native_arch.get_system()=="linux") + { + PkgConfigFile *pc = new PkgConfigFile(builder, spkg); + builder.get_build_graph().get_target("install")->add_dependency(*builder.get_toolchain().get_tool("CP").create_target(*pc)); + } + + if(native_arch.get_system()=="windows") + { + new VcxProjectFile(builder, spkg); + new VsSolutionFile(builder, spkg); + } + + new CompileCommandsJson(builder, spkg); +} + + +extern "C" +Plugin *create_plugin(Builder &builder) +{ + return new BuiltinPlugin(builder); +} diff --git a/plugins/base/baseplugin.h b/plugins/base/baseplugin.h new file mode 100644 index 0000000..afe48af --- /dev/null +++ b/plugins/base/baseplugin.h @@ -0,0 +1,15 @@ +#ifndef BUILTINPLUGIN_H_ +#define BUILTINPLUGIN_H_ + +#include + +class BuiltinPlugin: public Plugin +{ +public: + BuiltinPlugin(Builder &b): Plugin(b) { } + + void add_tools(Toolchain &, const Architecture &) const override; + void create_targets(SourcePackage &) const override; +}; + +#endif diff --git a/plugins/builtin/builtintools.cpp b/plugins/base/basetools.cpp similarity index 100% rename from plugins/builtin/builtintools.cpp rename to plugins/base/basetools.cpp diff --git a/plugins/builtin/builtintools.h b/plugins/base/basetools.h similarity index 100% rename from plugins/builtin/builtintools.h rename to plugins/base/basetools.h diff --git a/plugins/builtin/compilecommandsgenerator.cpp b/plugins/base/compilecommandsgenerator.cpp similarity index 100% rename from plugins/builtin/compilecommandsgenerator.cpp rename to plugins/base/compilecommandsgenerator.cpp diff --git a/plugins/builtin/compilecommandsgenerator.h b/plugins/base/compilecommandsgenerator.h similarity index 100% rename from plugins/builtin/compilecommandsgenerator.h rename to plugins/base/compilecommandsgenerator.h diff --git a/plugins/builtin/compilecommandsjson.cpp b/plugins/base/compilecommandsjson.cpp similarity index 100% rename from plugins/builtin/compilecommandsjson.cpp rename to plugins/base/compilecommandsjson.cpp diff --git a/plugins/builtin/compilecommandsjson.h b/plugins/base/compilecommandsjson.h similarity index 100% rename from plugins/builtin/compilecommandsjson.h rename to plugins/base/compilecommandsjson.h diff --git a/plugins/builtin/copy.cpp b/plugins/base/copy.cpp similarity index 100% rename from plugins/builtin/copy.cpp rename to plugins/base/copy.cpp diff --git a/plugins/builtin/copy.h b/plugins/base/copy.h similarity index 100% rename from plugins/builtin/copy.h rename to plugins/base/copy.h diff --git a/plugins/builtin/pkgconfigfile.cpp b/plugins/base/pkgconfigfile.cpp similarity index 100% rename from plugins/builtin/pkgconfigfile.cpp rename to plugins/base/pkgconfigfile.cpp diff --git a/plugins/builtin/pkgconfigfile.h b/plugins/base/pkgconfigfile.h similarity index 100% rename from plugins/builtin/pkgconfigfile.h rename to plugins/base/pkgconfigfile.h diff --git a/plugins/builtin/pkgconfiggenerator.cpp b/plugins/base/pkgconfiggenerator.cpp similarity index 100% rename from plugins/builtin/pkgconfiggenerator.cpp rename to plugins/base/pkgconfiggenerator.cpp diff --git a/plugins/builtin/pkgconfiggenerator.h b/plugins/base/pkgconfiggenerator.h similarity index 100% rename from plugins/builtin/pkgconfiggenerator.h rename to plugins/base/pkgconfiggenerator.h diff --git a/plugins/builtin/tar.cpp b/plugins/base/tar.cpp similarity index 100% rename from plugins/builtin/tar.cpp rename to plugins/base/tar.cpp diff --git a/plugins/builtin/tar.h b/plugins/base/tar.h similarity index 100% rename from plugins/builtin/tar.h rename to plugins/base/tar.h diff --git a/plugins/builtin/tarball.cpp b/plugins/base/tarball.cpp similarity index 100% rename from plugins/builtin/tarball.cpp rename to plugins/base/tarball.cpp diff --git a/plugins/builtin/tarball.h b/plugins/base/tarball.h similarity index 100% rename from plugins/builtin/tarball.h rename to plugins/base/tarball.h diff --git a/plugins/builtin/vcxprojectfile.cpp b/plugins/base/vcxprojectfile.cpp similarity index 100% rename from plugins/builtin/vcxprojectfile.cpp rename to plugins/base/vcxprojectfile.cpp diff --git a/plugins/builtin/vcxprojectfile.h b/plugins/base/vcxprojectfile.h similarity index 100% rename from plugins/builtin/vcxprojectfile.h rename to plugins/base/vcxprojectfile.h diff --git a/plugins/builtin/vcxprojectgenerator.cpp b/plugins/base/vcxprojectgenerator.cpp similarity index 100% rename from plugins/builtin/vcxprojectgenerator.cpp rename to plugins/base/vcxprojectgenerator.cpp diff --git a/plugins/builtin/vcxprojectgenerator.h b/plugins/base/vcxprojectgenerator.h similarity index 100% rename from plugins/builtin/vcxprojectgenerator.h rename to plugins/base/vcxprojectgenerator.h diff --git a/plugins/builtin/vssolutionfile.cpp b/plugins/base/vssolutionfile.cpp similarity index 100% rename from plugins/builtin/vssolutionfile.cpp rename to plugins/base/vssolutionfile.cpp diff --git a/plugins/builtin/vssolutionfile.h b/plugins/base/vssolutionfile.h similarity index 100% rename from plugins/builtin/vssolutionfile.h rename to plugins/base/vssolutionfile.h diff --git a/plugins/builtin/vssolutiongenerator.cpp b/plugins/base/vssolutiongenerator.cpp similarity index 100% rename from plugins/builtin/vssolutiongenerator.cpp rename to plugins/base/vssolutiongenerator.cpp diff --git a/plugins/builtin/vssolutiongenerator.h b/plugins/base/vssolutiongenerator.h similarity index 100% rename from plugins/builtin/vssolutiongenerator.h rename to plugins/base/vssolutiongenerator.h diff --git a/source/lib/builder.cpp b/source/lib/builder.cpp index 77d0872..53b9efb 100644 --- a/source/lib/builder.cpp +++ b/source/lib/builder.cpp @@ -15,7 +15,6 @@ #include "android/androidtools.h" #include "binarypackage.h" #include "builder.h" -#include "builtin/builtintools.h" #include "datafile/datatool.h" #include "installedfile.h" #include "package.h" @@ -145,7 +144,6 @@ void Builder::add_default_tools() { if(current_arch->get_system()=="android") toolchain.add_toolchain(new AndroidTools(*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); diff --git a/source/lib/sourcepackage.cpp b/source/lib/sourcepackage.cpp index 014bd83..dfbf16e 100644 --- a/source/lib/sourcepackage.cpp +++ b/source/lib/sourcepackage.cpp @@ -9,18 +9,14 @@ #include "binarycomponent.h" #include "binarypackage.h" #include "builder.h" -#include "builtin/compilecommandsjson.h" #include "datafile/datapackcomponent.h" #include "file.h" #include "installcomponent.h" -#include "builtin/pkgconfigfile.h" #include "plugin.h" #include "sourcearchivecomponent.h" #include "sourcegenerator.h" #include "sourcepackage.h" #include "tool.h" -#include "builtin/vcxprojectfile.h" -#include "builtin/vssolutionfile.h" using namespace std; using namespace Msp; @@ -136,29 +132,14 @@ void SourcePackage::do_prepare() for(Component *c: components) c->create_targets(); - const Architecture &arch = builder.get_native_arch(); if(!export_binfo.libs.empty()) { export_binfo.incpath.push_back((builder.get_prefix()/"include").str()); export_binfo.libpath.push_back((builder.get_prefix()/"lib").str()); - - if(arch.get_system()=="linux") - { - PkgConfigFile *pc = new PkgConfigFile(builder, *this); - builder.get_build_graph().get_target("install")->add_dependency(*builder.get_toolchain().get_tool("CP").create_target(*pc)); - } } export_binfo.standards = build_info.standards; - if(arch.get_system()=="windows") - { - new VcxProjectFile(builder, *this); - new VsSolutionFile(builder, *this); - } - - new CompileCommandsJson(builder, *this); - builder.call_plugins([this](const Plugin &p){ p.create_targets(*this); }); } -- 2.45.2