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;
46 void feature(const std::string &, const std::string &);
47 template<typename C, typename... Args>
48 void component(Args..., const std::string &);
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 &);
57 using ComponentRegistry = Msp::TypeRegistry<Loader::AddComponent, Loader &>;
61 std::string interface_version;
62 std::string description;
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;
70 std::vector<Component *> components;
71 SourceArchiveComponent *source_archive;
76 SourcePackage(Builder &, const std::string &, const Msp::FS::Path &);
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; }
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;
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; }
95 void do_prepare() override;
98 Cache &get_cache() const { return cache; }
100 void save_caches() override;
104 template<typename C, typename... Args>
105 void SourcePackage::Loader::component(Args... args, const std::string &n)
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...);
111 obj.components.push_back(comp);