]> git.tdb.fi Git - builder.git/blob - source/lib/sourcepackage.h
Add visibility decorations to the library and plugins
[builder.git] / source / lib / sourcepackage.h
1 #ifndef SOURCEPACKAGE_H_
2 #define SOURCEPACKAGE_H_
3
4 #include <algorithm>
5 #include <stdexcept>
6 #include <string>
7 #include <msp/core/typeregistry.h>
8 #include "buildinfo.h"
9 #include "cache.h"
10 #include "component.h"
11 #include "conditionalloader.h"
12 #include "config.h"
13 #include "feature.h"
14 #include "libbuilder_api.h"
15 #include "package.h"
16 #include "toolchain.h"
17
18 class BuildType;
19 class FileTarget;
20 class SourceArchiveComponent;
21
22 /**
23 A package that can be built by Builder.
24 */
25 class LIBBUILDER_API SourcePackage: public Package
26 {
27 public:
28         class Loader: public Msp::DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>, public FeatureConditional
29         {
30                 friend class SourcePackage;
31
32         private:
33                 template<typename T>
34                 struct AddComponent
35                 {
36                         void operator()(const std::string &n, Loader &l) const { l.add(n, &Loader::component<T>); }
37                 };
38
39                 const Config::InputOptions *options;
40
41         public:
42                 Loader(SourcePackage &, const Config::InputOptions *);
43         private:
44                 void finish() override;
45
46                 void feature(const std::string &, const std::string &);
47                 template<typename C, typename... Args>
48                 void component(Args..., const std::string &);
49                 void build_info();
50                 void generate(const std::string &);
51                 void interface_version(const std::string &);
52                 void source_archive();
53                 void tarball(const std::string &);
54                 void version(const std::string &);
55         };
56
57         using ComponentRegistry = Msp::TypeRegistry<Loader::AddComponent, Loader &>;
58
59 private:
60         std::string version;
61         std::string interface_version;
62         std::string description;
63
64         FileTarget *build_file;
65         Msp::FS::Path source_dir;
66         const BuildType *build_type = 0;
67         Toolchain local_tools;
68         std::vector<Feature> features;
69         BuildInfo build_info;
70         std::vector<Component *> components;
71         SourceArchiveComponent *source_archive;
72         Config config;
73         mutable Cache cache;
74
75 public:
76         SourcePackage(Builder &, const std::string &, const Msp::FS::Path &);
77         ~SourcePackage();
78
79         const std::string &get_version() const { return version; }
80         const std::string &get_interface_version() const { return interface_version; }
81         const std::string &get_description() const { return description; }
82
83         FileTarget &get_build_file() const { return *build_file; }
84         const Msp::FS::Path &get_source_directory() const { return source_dir; }
85         Msp::FS::Path get_temp_directory() const;
86         Msp::FS::Path get_output_directory() const;
87
88         const Toolchain &get_toolchain() const { return local_tools; }
89         const Component &get_component(const std::string &) const;
90         const Config &get_config() const { return config; }
91         bool match_feature(const std::string &, const std::string *) const;
92         void set_build_type(const BuildType &);
93         const BuildInfo &get_build_info() const { return build_info; }
94 private:
95         void do_prepare() override;
96
97 public:
98         Cache &get_cache() const { return cache; }
99 private:
100         void save_caches() override;
101 };
102
103
104 template<typename C, typename... Args>
105 void SourcePackage::Loader::component(Args... args, const std::string &n)
106 {
107         if(std::any_of(obj.components.begin(), obj.components.end(), [&n](const Component *c){ return c->get_name()==n; }))
108                 throw Msp::key_error(n);
109         C *comp = new C(obj, n, args...);
110         load_sub(*comp);
111         obj.components.push_back(comp);
112 }
113
114 #endif