]> git.tdb.fi Git - builder.git/blob - source/sourcepackage.h
Externalize dry run handling from Config and DependencyCache
[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 Msp::DataFile::DerivedObjectLoader<SourcePackage, Package>
38         {
39         private:
40                 std::map<std::string, std::string> install_map;
41
42         public:
43                 Loader(SourcePackage &);
44         private:
45                 virtual void finish();
46                 void feature(const std::string &, const std::string &);
47                 template<Component::Type>
48                 void component(const std::string &);
49                 void condition(const std::string &);
50                 void build_info();
51                 void headers(const std::string &);
52                 void tarball(const std::string &);
53                 void tar_file(const std::string &);
54         };
55
56 private:
57         std::string version;
58         std::string description;
59
60         Msp::FS::Path source;
61         FeatureList features;
62         BuildInfo build_info;
63         ConditionList conditions;
64         ComponentList components;
65         Config config;
66         mutable DependencyCache deps_cache;
67
68 public:
69         SourcePackage(Builder &, const std::string &, const Msp::FS::Path &);
70         const std::string &get_name() const { return name; }
71         const std::string &get_version() const { return version; }
72         const std::string &get_description() const { return description; }
73         const Msp::FS::Path &get_source() const { return source; }
74         Msp::FS::Path get_temp_dir() const;
75         Msp::FS::Path get_out_dir() const;
76         const ComponentList &get_components() const { return components; }
77         const Config &get_config() const { return config; }
78         const BuildInfo &get_build_info() const { return build_info; }
79         const BuildInfo &get_exported_binfo() const { return export_binfo; }
80         Builder &get_builder() const { return builder; }
81
82         /** Returns a bitmask indicating which kinds of things the components of
83         this package install. */
84         unsigned get_install_flags();
85
86         LibMode get_library_mode() const;
87         DependencyCache &get_deps_cache() const { return deps_cache; }
88         std::string expand_string(const std::string &) const;
89 private:
90         virtual void do_configure(const StringMap &, unsigned);
91
92         /** Initializes configuration options. */
93         void init_config();
94
95         /** Fills in build info based on configuration.  All required packages must be
96         configured when this is called. */
97         virtual void create_build_info();
98
99         virtual void create_targets();
100
101         virtual void save_caches();
102 };
103
104 #endif