]> git.tdb.fi Git - builder.git/blob - source/sourcepackage.h
Refactor the constructor of SourcePackage::Loader
[builder.git] / source / sourcepackage.h
1 #ifndef SOURCEPACKAGE_H_
2 #define SOURCEPACKAGE_H_
3
4 #include <stdexcept>
5 #include <string>
6 #include "buildinfo.h"
7 #include "cache.h"
8 #include "component.h"
9 #include "conditionalloader.h"
10 #include "config.h"
11 #include "feature.h"
12 #include "package.h"
13 #include "toolchain.h"
14
15 class Builder;
16 class BuildType;
17 class FileTarget;
18 class SourceArchiveComponent;
19
20 /**
21 A package that can be built by Builder.
22 */
23 class SourcePackage: public Package
24 {
25 public:
26         class Loader: public Msp::DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>, public FeatureConditional
27         {
28         private:
29                 const Config::InputOptions *options;
30
31         public:
32                 Loader(SourcePackage &, const Config::InputOptions *);
33         private:
34                 void finish() override;
35
36                 void feature(const std::string &, const std::string &);
37                 template<typename C>
38                 void component(const std::string &);
39                 template<typename C, typename A, A>
40                 void component_arg(const std::string &);
41                 void build_info();
42                 void generate(const std::string &);
43                 void interface_version(const std::string &);
44                 void source_archive();
45                 void tarball(const std::string &);
46                 void version(const std::string &);
47         };
48
49         typedef std::list<Component *> ComponentList;
50
51 private:
52         typedef std::list<Feature> FeatureList;
53
54         std::string version;
55         std::string interface_version;
56         std::string description;
57
58         FileTarget *build_file;
59         Msp::FS::Path source_dir;
60         const BuildType *build_type;
61         Toolchain local_tools;
62         FeatureList features;
63         BuildInfo build_info;
64         ComponentList components;
65         SourceArchiveComponent *source_archive;
66         Config config;
67         mutable Cache cache;
68
69 public:
70         SourcePackage(Builder &, const std::string &, const Msp::FS::Path &);
71         ~SourcePackage();
72
73         const std::string &get_version() const { return version; }
74         const std::string &get_interface_version() const { return interface_version; }
75         const std::string &get_description() const { return description; }
76
77         FileTarget &get_build_file() const { return *build_file; }
78         const Msp::FS::Path &get_source_directory() const { return source_dir; }
79         Msp::FS::Path get_temp_directory() const;
80         Msp::FS::Path get_output_directory() const;
81
82         const Toolchain &get_toolchain() const { return local_tools; }
83         const Component &get_component(const std::string &) const;
84         const Config &get_config() const { return config; }
85         bool match_feature(const std::string &, const std::string *) const;
86         void set_build_type(const BuildType &);
87         const BuildInfo &get_build_info() const { return build_info; }
88 private:
89         void do_prepare() override;
90
91 public:
92         Cache &get_cache() const { return cache; }
93 private:
94         void save_caches() override;
95 };
96
97 #endif