]> git.tdb.fi Git - builder.git/blob - source/builder.h
Pass the option map through load_build_file and to Loader
[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/core/application.h>
8 #include <msp/datafile/loader.h>
9 #include <msp/fs/path.h>
10 #include "architecture.h"
11 #include "buildgraph.h"
12 #include "buildtype.h"
13 #include "config.h"
14 #include "logger.h"
15 #include "packagemanager.h"
16 #include "problem.h"
17 #include "target.h"
18 #include "toolchain.h"
19 #include "virtualfilesystem.h"
20
21 class Analyzer;
22 class FileTarget;
23 class Package;
24 class SourcePackage;
25
26 /**
27 The main application class.  Handles command line options and supervises the
28 build process.
29 */
30 class Builder: public Msp::RegisteredApplication<Builder>
31 {
32 private:
33         class Loader: public Msp::DataFile::ObjectLoader<Builder>
34         {
35         private:
36                 const Config::InputOptions *options;
37                 bool conf_all;
38
39         public:
40                 Loader(Builder &, const Config::InputOptions * = 0, bool = false);
41                 ~Loader();
42
43         private:
44                 void architecture(const std::string &);
45                 void binpkg(const std::string &);
46                 void build_type(const std::string &);
47                 void profile(const std::string &);
48                 void package(const std::string &);
49         };
50
51 private:
52         typedef std::list<std::string> NameList;
53         typedef std::map<std::string, BuildType> BuildTypeMap;
54         typedef std::list<Problem> ProblemList;
55
56         NameList cmdline_targets;
57         Config::InputOptions cmdline_options;
58         Msp::FS::Path cwd;
59
60         PackageManager package_manager;
61
62         Architecture native_arch;
63         Architecture *current_arch;
64         BuildTypeMap build_types;
65         BuildType *build_type;
66         Toolchain toolchain;
67         VirtualFileSystem vfs;
68         BuildGraph build_graph;
69         Logger logger;
70
71         ProblemList problems;
72         Analyzer *analyzer;
73         bool build;
74         unsigned clean;
75         bool dry_run;
76         bool help;
77         bool show_progress;
78         std::string build_file;
79         unsigned jobs;
80         NameList what_if;
81         bool conf_all;
82         bool conf_only;
83         bool build_all;
84         bool create_makefile;
85         Msp::FS::Path prefix;
86         Msp::FS::Path tempdir;
87
88         Loader *top_loader;
89
90         static std::string usagemsg;
91         static std::string helpmsg;
92
93 public:
94         Builder(int, char **);
95         ~Builder();
96
97         int main();
98
99         PackageManager &get_package_manager() { return package_manager; }
100
101         const Architecture &get_current_arch() const { return *current_arch; }
102         const Architecture &get_native_arch() const { return native_arch; }
103         BuildGraph &get_build_graph() { return build_graph; }
104         const Msp::FS::Path &get_prefix() const { return prefix; }
105         const Msp::FS::Path &get_temp_directory() const { return tempdir; }
106
107         const Toolchain &get_toolchain() const { return toolchain; }
108         VirtualFileSystem &get_vfs() { return vfs; }
109         const Logger &get_logger() const { return logger; }
110
111         void problem(const std::string &, const std::string &);
112
113         static void usage(const char *, const char *, bool);
114
115         /** Loads a build file.  If opts is not null, it is used to configure any
116         packages loaded from this file.  If all is true, external packages are also
117         configured. */
118         void load_build_file(const Msp::FS::Path &, const Config::InputOptions *opts = 0, bool all = false);
119
120 private:
121         /** Prepares packages and targets for building.  Returns true if everything
122         went ok, or false if something bad happened and a build shouldn't be
123         attempted. */
124         bool prepare_build();
125
126         /** Supervises the build process, starting new tasks when slots become
127         available. */
128         int do_build();
129
130         /** Cleans buildable targets.  If clean is 1, cleans only the default
131         package.  If clean is 2 or greater, cleans all buildable packages.
132         */
133         int do_clean();
134
135         int do_create_makefile();
136
137         /** Prints out information about the default package. */
138         void package_help();
139 };
140
141 #endif