]> git.tdb.fi Git - builder.git/blob - source/lib/builder.h
Comment cleanup and other cosmetic fixes
[builder.git] / source / lib / builder.h
1 #ifndef BUILDER_H_
2 #define BUILDER_H_
3
4 #include <map>
5 #include <string>
6 #include <msp/core/module.h>
7 #include <msp/datafile/loader.h>
8 #include <msp/fs/path.h>
9 #include "architecture.h"
10 #include "buildgraph.h"
11 #include "buildtype.h"
12 #include "config.h"
13 #include "logger.h"
14 #include "packagemanager.h"
15 #include "sourcepackage.h"
16 #include "target.h"
17 #include "toolchain.h"
18 #include "virtualfilesystem.h"
19
20 class Package;
21 class Plugin;
22
23 /**
24 This class ties everything else together.  It also contains code for loading
25 build files and supervising the build process.
26 */
27 class Builder
28 {
29 private:
30         class Loader: public Msp::DataFile::ObjectLoader<Builder>
31         {
32         private:
33                 const Config::InputOptions *options;
34                 bool conf_all;
35
36         public:
37                 Loader(Builder &, const Config::InputOptions * = 0, bool = false);
38                 ~Loader();
39
40         private:
41                 void architecture(const std::string &);
42                 void binpkg(const std::string &);
43                 void build_type(const std::string &);
44                 void package(const std::string &);
45         };
46
47 private:
48         struct LoadedPlugin
49         {
50                 Msp::FS::Path path;
51                 Msp::Module *module = nullptr;
52                 Plugin *plugin = nullptr;
53
54                 LoadedPlugin() = default;
55                 LoadedPlugin(LoadedPlugin &&);
56                 ~LoadedPlugin();
57         };
58
59         std::vector<LoadedPlugin> plugins;
60         PackageManager package_manager;
61         SourcePackage::ComponentRegistry component_registry;
62
63         Architecture native_arch;
64         Architecture *current_arch = 0;
65         std::map<std::string, BuildType> build_types;
66         BuildType *build_type = 0;
67         Toolchain toolchain;
68         VirtualFileSystem vfs;
69         BuildGraph build_graph;
70         Logger default_logger;
71         const Logger *logger;
72
73         bool auto_prefix = true;
74         Msp::FS::Path prefix;
75         Msp::FS::Path tempdir = "temp";
76
77         Loader *top_loader = 0;
78
79 public:
80         Builder();
81         ~Builder();
82
83         void load_plugins();
84         PackageManager &get_package_manager() { return package_manager; }
85         SourcePackage::ComponentRegistry &get_component_registry() { return component_registry; }
86
87         template<typename F>
88         void call_plugins(F) const;
89
90         void set_architecture(const std::string &);
91         const Architecture &get_current_arch() const { return *current_arch; }
92         const Architecture &get_native_arch() const { return native_arch; }
93         void set_build_type(const std::string &);
94         std::vector<std::string> get_build_types() const;
95         const BuildType &get_build_type() const;
96         BuildGraph &get_build_graph() { return build_graph; }
97         void set_prefix(const Msp::FS::Path &);
98         void set_temp_directory(const Msp::FS::Path &);
99         const Msp::FS::Path &get_prefix() const { return prefix; }
100         const Msp::FS::Path &get_temp_directory() const { return tempdir; }
101
102 private:
103         void update_auto_prefix();
104
105 public:
106         void add_default_tools();
107         const Toolchain &get_toolchain() const { return toolchain; }
108         VirtualFileSystem &get_vfs() { return vfs; }
109         void set_logger(const Logger *);
110         const Logger &get_logger() const { return *logger; }
111
112         std::vector<std::string> collect_problems() const;
113 private:
114         void collect_broken_packages(const Package &, std::vector<const Package *> &) const;
115
116 public:
117         /** Loads a build file.  If opts is not null, it is used to configure any
118         packages loaded from this file.  If all is true, external packages are also
119         configured. */
120         void load_build_file(const Msp::FS::Path &, const Config::InputOptions *opts = 0, bool all = false);
121
122         /** Saves package configuration and dependency caches. */
123         void save_caches();
124
125         /** Builds the goal targets.  The build graph must be prepared first. */
126         int build(unsigned jobs = 1, bool dry_run = false, bool show_progress = false);
127
128         /** Cleans buildable targets.  If all is true, cleans all packages.
129         Otherwise cleans only the default package. */
130         int clean(bool all = false, bool dry_run = false);
131
132         int do_create_makefile();
133 };
134
135 template<typename F>
136 void Builder::call_plugins(F func) const
137 {
138         for(const LoadedPlugin &p: plugins)
139                 func(*p.plugin);
140 }
141
142 #endif