]> git.tdb.fi Git - builder.git/blob - source/lib/component.h
816d2c11803c1eb947fb6244590548b71f5fcd84
[builder.git] / source / lib / 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 "conditionalloader.h"
9 #include "installmap.h"
10 #include "package.h"
11
12 class SourcePackage;
13
14 /**
15 Components specify things to be built.  Each component may build one binary (it
16 may also build none), as well as install a bunch of headers.  Components inherit
17 dependencies and build info from the package they belong to, and may also add
18 their own.
19 */
20 class Component
21 {
22 public:
23         class Loader: public Msp::DataFile::ObjectLoader<Component>, public ConditionalLoader
24         {
25         public:
26                 Loader(Component &);
27         private:
28                 void build_info();
29                 void install_map();
30                 void overlay(const std::string &);
31                 void require(const std::string &);
32                 void source(const std::string &);
33         };
34
35 protected:
36         SourcePackage &package;
37         std::string name;
38         std::vector<Msp::FS::Path> sources;
39         std::vector<std::string> overlays;
40         bool install = false;
41         BuildInfo build_info;
42         Package::Requirements requires;
43         bool deflt = true;
44         InstallMap install_map;
45         bool broken = false;
46         std::vector<std::string> problems;
47
48         Component(SourcePackage &p, const std::string &n): package(p), name(n) { }
49 public:
50         virtual ~Component() { }
51
52         const SourcePackage &get_package() const { return package; }
53         const std::string &get_name() const { return name; }
54
55         /** Returns a list of sources for the component.  They may refer to
56         directories or individual files. */
57         const std::vector<Msp::FS::Path> &get_sources() const { return sources; }
58
59         const std::vector<std::string> &get_overlays() const { return overlays; }
60
61 protected:
62         /** Returns a list of all source files for the component. */
63         std::vector<Msp::FS::Path> collect_source_files() const;
64
65 public:
66         bool get_install() const { return install; }
67         const InstallMap &get_install_map() const { return install_map; }
68         const Package::Requirements &get_required_packages() const { return requires; }
69         bool is_default() const { return deflt; }
70         bool is_broken() const { return broken; }
71         const std::vector<std::string> &get_problems() const { return problems; }
72
73         /** Prepares any required packages. */
74         void prepare();
75
76         /** Prepares the build information for building.  Pulls build info from the
77         parent and dependency packages, and adds any component-specific flags. */
78         virtual void create_build_info();
79
80         virtual void update_exported_build_info(BuildInfo &) const { }
81
82         const BuildInfo &get_build_info() const { return build_info; }
83
84         BuildInfo get_build_info_for_path(const Msp::FS::Path &) const;
85
86         virtual void create_targets() const = 0;
87 };
88
89 #endif