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