1 #ifndef SOURCEPACKAGE_H_
2 #define SOURCEPACKAGE_H_
7 #include <msp/core/typeregistry.h>
10 #include "component.h"
11 #include "conditionalloader.h"
14 #include "libbuilder_api.h"
16 #include "toolchain.h"
20 class SourceArchiveComponent;
23 A package that can be built by Builder.
25 class LIBBUILDER_API SourcePackage: public Package
28 class Loader: public Msp::DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>, public FeatureConditional
30 friend class SourcePackage;
36 void operator()(const std::string &n, Loader &l) const { l.add(n, &Loader::component<T>); }
39 const Config::InputOptions *options;
42 Loader(SourcePackage &, const Config::InputOptions *);
44 void finish() override;
47 void feature(const std::string &, const std::string &);
48 template<typename C, typename... Args>
49 void component(Args..., const std::string &);
51 void generate(const std::string &);
52 void interface_version(const std::string &);
53 void source_archive();
54 void tarball(const std::string &);
55 void version(const std::string &);
58 using ComponentRegistry = Msp::TypeRegistry<Loader::AddComponent, Loader &>;
61 class ExportLoader: public Msp::DataFile::ObjectLoader<SourcePackage>
64 ExportLoader(SourcePackage &);
71 std::string interface_version;
72 std::string description;
74 FileTarget *build_file;
75 Msp::FS::Path source_dir;
76 const BuildType *build_type = 0;
77 Toolchain local_tools;
78 std::vector<Feature> features;
80 std::vector<Component *> components;
81 SourceArchiveComponent *source_archive;
86 SourcePackage(Builder &, const std::string &, const Msp::FS::Path &);
89 const std::string &get_version() const { return version; }
90 const std::string &get_interface_version() const { return interface_version; }
91 const std::string &get_description() const { return description; }
93 FileTarget &get_build_file() const { return *build_file; }
94 const Msp::FS::Path &get_source_directory() const { return source_dir; }
95 Msp::FS::Path get_temp_directory() const;
96 Msp::FS::Path get_output_directory() const;
97 Msp::FS::Path get_staging_directory() const;
99 const Toolchain &get_toolchain() const { return local_tools; }
100 const Component &get_component(const std::string &) const;
101 const Config &get_config() const { return config; }
102 bool match_feature(const std::string &, const std::string *) const;
103 void set_build_type(const BuildType &);
104 const BuildInfo &get_build_info() const { return build_info; }
106 void do_prepare() override;
109 Cache &get_cache() const { return cache; }
111 void save_caches() override;
115 template<typename C, typename... Args>
116 void SourcePackage::Loader::component(Args... args, const std::string &n)
118 if(std::any_of(obj.components.begin(), obj.components.end(), [&n](const Component *c){ return c->get_name()==n; }))
119 throw Msp::key_error(n);
120 C *comp = new C(obj, n, args...);
122 obj.components.push_back(comp);