]> git.tdb.fi Git - builder.git/blob - source/builder.h
Better logging system
[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 "config.h"
12 #include "logger.h"
13 #include "misc.h"
14 #include "packagemanager.h"
15 #include "problem.h"
16 #include "target.h"
17 #include "toolchain.h"
18 #include "virtualfilesystem.h"
19
20 class Analyzer;
21 class Config;
22 class FileTarget;
23 class Package;
24 class SourcePackage;
25 class VirtualTarget;
26
27 /**
28 The main application class.  Controls and owns everything.  Rules the world.
29 */
30 class Builder: public Msp::RegisteredApplication<Builder>
31 {
32 private:
33         class Loader: public Msp::DataFile::Loader
34         {
35         private:
36                 Builder &bld;
37                 Msp::FS::Path src;
38
39         public:
40                 Loader(Builder &, const Msp::FS::Path &);
41         private:
42                 void binpkg(const std::string &);
43                 void cross_prefix(const std::string &, const std::string &);
44                 void profile(const std::string &);
45                 void package(const std::string &);
46         };
47
48         class ProfileLoader: public Msp::DataFile::Loader
49         {
50         private:
51                 StringMap &profile;
52
53         public:
54                 ProfileLoader(StringMap &);
55         private:
56                 void option(const std::string &, const std::string &);
57         };
58
59 public:
60         typedef std::map<std::string, Target *> TargetMap;
61         typedef std::list<Target *> TargetList;
62
63 private:
64         typedef std::map<std::string, StringMap> ProfileTemplateMap;
65
66         StringList cmdline_targets;
67         StringMap cmdline_options;
68         Msp::FS::Path cwd;
69
70         PackageManager package_manager;
71         SourcePackage *main_pkg;
72
73         TargetMap targets;
74
75         Architecture native_arch;
76         Architecture *current_arch;
77         StringMap cross_prefixes;
78         ProfileTemplateMap profile_tmpl;
79         Toolchain toolchain;
80         VirtualFileSystem vfs;
81         Logger logger;
82
83         ProblemList problems;
84         Analyzer *analyzer;
85         bool build;
86         unsigned clean;
87         bool dry_run;
88         bool help;
89         bool show_progress;
90         std::string build_file;
91         unsigned jobs;
92         StringList what_if;
93         bool conf_all;
94         bool conf_only;
95         bool build_all;
96         bool create_makefile;
97         Msp::FS::Path prefix;
98         StringList warnings;
99
100         static std::string usagemsg;
101         static std::string helpmsg;
102
103 public:
104         Builder(int, char **);
105         ~Builder();
106
107         int main();
108         bool get_dry_run() const { return dry_run; }
109
110         PackageManager &get_package_manager() { return package_manager; }
111         SourcePackage *get_main_package() const { return main_pkg; }
112
113         /** Looks up a target by name.  Returns 0 if no such target exists. */
114         Target *get_target(const std::string &) const;
115
116         const TargetMap &get_targets() const { return targets; }
117
118         const Msp::FS::Path &get_cwd() const { return cwd; }
119         const Architecture &get_current_arch() const { return *current_arch; }
120         const Architecture &get_native_arch() const { return native_arch; }
121         const Msp::FS::Path &get_prefix() const { return prefix; }
122         const StringList &get_warnings() const { return warnings; }
123         void apply_profile_template(Config &, const std::string &) const;
124
125         const Toolchain &get_toolchain() const { return toolchain; }
126         VirtualFileSystem &get_vfs() { return vfs; }
127         const Logger &get_logger() const { return logger; }
128
129         /** Adds a target to both the target map and the new target queue.  Called
130         from Target constructor. */
131         void add_target(Target *);
132         void register_path(const Msp::FS::Path &, FileTarget *);
133
134         void problem(const std::string &, const std::string &);
135
136         static void usage(const char *, const char *, bool);
137
138         /** Loads a build file.  Returns 0 on success or -1 if the file could not be
139         opened. */
140         int load_build_file(const Msp::FS::Path &);
141
142 private:
143         /** Creates targets for all packages and prepares them for building.
144         Returns 0 if everything went ok, -1 if something bad happened and a build
145         shouldn't be attempted. */
146         int create_targets();
147
148         /** Supervises the build process, starting new actions when slots become
149         available. */
150         int do_build();
151
152         /** Cleans buildable targets.  If clean is 1, cleans only the default
153         package.  If clean is 2 or greater, cleans all buildable packages.
154         */
155         int do_clean();
156
157         int do_create_makefile();
158
159         /** Prints out information about the default package. */
160         void package_help();
161 };
162
163 #endif