]> git.tdb.fi Git - builder.git/blob - source/component.h
Add a feature for overlay source directories
[builder.git] / source / component.h
1 #ifndef COMPONENT_H_
2 #define COMPONENT_H_
3
4 #include <string>
5 #include <msp/datafile/objectloader.h>
6 #include <msp/fs/path.h>
7 #include "buildinfo.h"
8 #include "installmap.h"
9 #include "package.h"
10
11 class SourcePackage;
12
13 /**
14 Components specify things to be built.  Each component may build one binary (it
15 may also build none), as well as install a bunch of headers.  Components inherit
16 dependencies and build info from the package they belong to, and may also add
17 their own.
18 */
19 class Component
20 {
21 public:
22         class Loader: public Msp::DataFile::ObjectLoader<Component>
23         {
24         public:
25                 Loader(Component &);
26         private:
27                 void build_info();
28                 void if_arch(const std::string &);
29                 void if_feature(const std::string &);
30                 void install_map();
31                 void overlay(const std::string &);
32                 void require(const std::string &);
33                 void source(const std::string &);
34                 void use(const std::string &);
35         };
36
37         enum Type
38         {
39                 LIBRARY,
40                 PROGRAM,
41                 MODULE,
42                 DATAPACK,
43                 INSTALL,
44                 TARBALL
45         };
46
47         typedef std::list<Msp::FS::Path> SourceList;
48         typedef std::list<std::string> OverlayList;
49         typedef std::list<const Component *> UseList;
50
51 protected:
52         SourcePackage &package;
53         Type type;
54         std::string name;
55         SourceList sources;
56         OverlayList overlays;
57         bool install;
58         BuildInfo build_info;
59         Package::Requirements requires;
60         UseList uses;
61         bool deflt;
62         InstallMap install_map;
63
64 public:
65         Component(SourcePackage &, Type, const std::string &);
66
67         const SourcePackage &get_package() const { return package; }
68         Type get_type() const { return type; }
69         const std::string &get_name() const { return name; }
70
71         /** Returns a list of sources for the component.  They may refer to
72         directories or individual files. */
73         const SourceList &get_sources() const { return sources; }
74
75         const OverlayList &get_overlays() const { return overlays; }
76
77 protected:
78         /** Returns a list of all source files for the component. */
79         SourceList collect_source_files() const;
80
81 public:
82         bool get_install() const { return install; }
83         const InstallMap &get_install_map() const { return install_map; }
84         const Package::Requirements &get_required_packages() const { return requires; }
85         const UseList &get_used_components() const { return uses; }
86         bool is_default() const { return deflt; }
87
88         /** Prepares any required packages. */
89         void prepare();
90
91         /** Prepares the build information for building.  Pulls build info from the
92         parent and dependency packages, and adds any component-specific flags. */
93         void create_build_info();
94
95         const BuildInfo &get_build_info() const { return build_info; }
96
97         BuildInfo get_build_info_for_path(const Msp::FS::Path &) const;
98
99         void create_targets() const;
100 };
101
102 #endif