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