]> git.tdb.fi Git - builder.git/blob - source/sourcepackage.h
Move some target creation logic to SourcePackage
[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 "component.h"
8 #include "condition.h"
9 #include "config.h"
10 #include "dependencycache.h"
11 #include "feature.h"
12 #include "package.h"
13
14 class Builder;
15
16 class bad_expansion: public std::runtime_error
17 {
18 public:
19         bad_expansion(const std::string &w): std::runtime_error(w) { }
20         virtual ~bad_expansion() throw() { }
21 };
22
23 /**
24 A package that can be built by Builder.
25 */
26 class SourcePackage: public Package
27 {
28 public:
29         enum InstallFlags
30         {
31                 INCLUDE = 1,
32                 BIN = 2,
33                 LIB = 4,
34                 DATA = 8
35         };
36
37         class Loader: public Package::Loader
38         {
39         public:
40                 Loader(Package &);
41                 SourcePackage &get_object() { return static_cast<SourcePackage &>(pkg); }
42         private:
43                 virtual void finish();
44                 void feature(const std::string &, const std::string &);
45                 template<Component::Type>
46                 void component(const std::string &);
47                 void condition(const std::string &);
48                 void build_info();
49                 void tarball(const std::string &);
50                 void tar_file(const std::string &);
51         };
52
53 private:
54         std::string version;
55         std::string description;
56
57         Msp::FS::Path source;
58         FeatureList features;
59         BuildInfo build_info;
60         ConditionList conditions;
61         ComponentList components;
62         Config config;
63         mutable DependencyCache deps_cache;
64
65 public:
66         SourcePackage(Builder &, const std::string &, const Msp::FS::Path &);
67         const std::string &get_name() const { return name; }
68         const std::string &get_version() const { return version; }
69         const std::string &get_description() const { return description; }
70         const Msp::FS::Path &get_source() const { return source; }
71         Msp::FS::Path get_temp_dir() const;
72         Msp::FS::Path get_out_dir() const;
73         const ComponentList &get_components() const { return components; }
74         const Config &get_config() const { return config; }
75         const BuildInfo &get_build_info() const { return build_info; }
76         const BuildInfo &get_exported_binfo() const { return export_binfo; }
77         Builder &get_builder() const { return builder; }
78
79         /** Returns a bitmask indicating which kinds of things the components of
80         this package install. */
81         unsigned get_install_flags();
82
83         LibMode get_library_mode() const;
84         DependencyCache &get_deps_cache() const { return deps_cache; }
85         std::string expand_string(const std::string &) const;
86 private:
87         virtual void do_configure(const StringMap &, unsigned);
88
89         /** Initializes configuration options. */
90         void init_config();
91
92         /** Fills in build info based on configuration.  All required packages must be
93         configured when this is called. */
94         virtual void create_build_info();
95
96         virtual void create_targets();
97 };
98
99 #endif