]> git.tdb.fi Git - builder.git/blob - source/component.h
7cbd1e13cbe1f0099522161e4e2eb74c708fcad3
[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         std::list<std::string> problems;
64
65 public:
66         Component(SourcePackage &, Type, const std::string &);
67
68         const SourcePackage &get_package() const { return package; }
69         Type get_type() const { return type; }
70         const std::string &get_name() const { return name; }
71
72         /** Returns a list of sources for the component.  They may refer to
73         directories or individual files. */
74         const SourceList &get_sources() const { return sources; }
75
76         const OverlayList &get_overlays() const { return overlays; }
77
78 protected:
79         /** Returns a list of all source files for the component. */
80         SourceList collect_source_files() const;
81
82 public:
83         bool get_install() const { return install; }
84         const InstallMap &get_install_map() const { return install_map; }
85         const Package::Requirements &get_required_packages() const { return requires; }
86         const UseList &get_used_components() const { return uses; }
87         bool is_default() const { return deflt; }
88         const std::list<std::string> &get_problems() const { return problems; }
89
90         /** Prepares any required packages. */
91         void prepare();
92
93         /** Prepares the build information for building.  Pulls build info from the
94         parent and dependency packages, and adds any component-specific flags. */
95         void create_build_info();
96
97         const BuildInfo &get_build_info() const { return build_info; }
98
99         BuildInfo get_build_info_for_path(const Msp::FS::Path &) const;
100
101         void create_targets() const;
102 };
103
104 #endif