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