1 #ifndef SOURCEPACKAGE_H_
2 #define SOURCEPACKAGE_H_
7 #include <msp/core/typeregistry.h>
10 #include "component.h"
11 #include "conditionalloader.h"
15 #include "toolchain.h"
19 class SourceArchiveComponent;
22 A package that can be built by Builder.
24 class SourcePackage: public Package
27 class Loader: public Msp::DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>, public FeatureConditional
29 friend class SourcePackage;
35 void operator()(const std::string &n, Loader &l) const { l.add(n, &Loader::component<T>); }
38 const Config::InputOptions *options;
41 Loader(SourcePackage &, const Config::InputOptions *);
43 void finish() override;
45 void feature(const std::string &, const std::string &);
46 template<typename C, typename... Args>
47 void component(Args..., const std::string &);
49 void generate(const std::string &);
50 void interface_version(const std::string &);
51 void source_archive();
52 void tarball(const std::string &);
53 void version(const std::string &);
56 using ComponentRegistry = Msp::TypeRegistry<Loader::AddComponent, Loader &>;
60 std::string interface_version;
61 std::string description;
63 FileTarget *build_file;
64 Msp::FS::Path source_dir;
65 const BuildType *build_type = 0;
66 Toolchain local_tools;
67 std::vector<Feature> features;
69 std::vector<Component *> components;
70 SourceArchiveComponent *source_archive;
75 SourcePackage(Builder &, const std::string &, const Msp::FS::Path &);
78 const std::string &get_version() const { return version; }
79 const std::string &get_interface_version() const { return interface_version; }
80 const std::string &get_description() const { return description; }
82 FileTarget &get_build_file() const { return *build_file; }
83 const Msp::FS::Path &get_source_directory() const { return source_dir; }
84 Msp::FS::Path get_temp_directory() const;
85 Msp::FS::Path get_output_directory() const;
87 const Toolchain &get_toolchain() const { return local_tools; }
88 const Component &get_component(const std::string &) const;
89 const Config &get_config() const { return config; }
90 bool match_feature(const std::string &, const std::string *) const;
91 void set_build_type(const BuildType &);
92 const BuildInfo &get_build_info() const { return build_info; }
94 void do_prepare() override;
97 Cache &get_cache() const { return cache; }
99 void save_caches() override;
103 template<typename C, typename... Args>
104 void SourcePackage::Loader::component(Args... args, const std::string &n)
106 if(std::any_of(obj.components.begin(), obj.components.end(), [&n](const Component *c){ return c->get_name()==n; }))
107 throw Msp::key_error(n);
108 C *comp = new C(obj, n, args...);
110 obj.components.push_back(comp);