]> git.tdb.fi Git - builder.git/blob - source/lib/sourcepackage.h
Collapse the component loading functions in SourcePackage::Loader
[builder.git] / source / lib / 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, typename... Args>
38                 void component(Args..., const std::string &);
39                 void build_info();
40                 void generate(const std::string &);
41                 void interface_version(const std::string &);
42                 void source_archive();
43                 void tarball(const std::string &);
44                 void version(const std::string &);
45         };
46
47 private:
48         std::string version;
49         std::string interface_version;
50         std::string description;
51
52         FileTarget *build_file;
53         Msp::FS::Path source_dir;
54         const BuildType *build_type = 0;
55         Toolchain local_tools;
56         std::vector<Feature> features;
57         BuildInfo build_info;
58         std::vector<Component *> components;
59         SourceArchiveComponent *source_archive;
60         Config config;
61         mutable Cache cache;
62
63 public:
64         SourcePackage(Builder &, const std::string &, const Msp::FS::Path &);
65         ~SourcePackage();
66
67         const std::string &get_version() const { return version; }
68         const std::string &get_interface_version() const { return interface_version; }
69         const std::string &get_description() const { return description; }
70
71         FileTarget &get_build_file() const { return *build_file; }
72         const Msp::FS::Path &get_source_directory() const { return source_dir; }
73         Msp::FS::Path get_temp_directory() const;
74         Msp::FS::Path get_output_directory() const;
75
76         const Toolchain &get_toolchain() const { return local_tools; }
77         const Component &get_component(const std::string &) const;
78         const Config &get_config() const { return config; }
79         bool match_feature(const std::string &, const std::string *) const;
80         void set_build_type(const BuildType &);
81         const BuildInfo &get_build_info() const { return build_info; }
82 private:
83         void do_prepare() override;
84
85 public:
86         Cache &get_cache() const { return cache; }
87 private:
88         void save_caches() override;
89 };
90
91 #endif