]> git.tdb.fi Git - builder.git/blob - source/builder.h
Move package management to a separate class
[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 "misc.h"
13 #include "packagemanager.h"
14 #include "problem.h"
15 #include "target.h"
16 #include "toolchain.h"
17 #include "virtualfilesystem.h"
18
19 class Analyzer;
20 class Config;
21 class FileTarget;
22 class Package;
23 class SourcePackage;
24 class VirtualTarget;
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::Loader
33         {
34         private:
35                 Builder &bld;
36                 Msp::FS::Path src;
37
38         public:
39                 Loader(Builder &, const Msp::FS::Path &);
40         private:
41                 void binpkg(const std::string &);
42                 void cross_prefix(const std::string &, const std::string &);
43                 void profile(const std::string &);
44                 void package(const std::string &);
45         };
46
47         class ProfileLoader: public Msp::DataFile::Loader
48         {
49         private:
50                 StringMap &profile;
51
52         public:
53                 ProfileLoader(StringMap &);
54         private:
55                 void option(const std::string &, const std::string &);
56         };
57
58 public:
59         typedef std::map<std::string, Target *> TargetMap;
60         typedef std::list<Target *> TargetList;
61
62 private:
63         typedef std::map<std::string, StringMap> ProfileTemplateMap;
64
65         StringList cmdline_targets;
66         StringMap cmdline_options;
67         Msp::FS::Path cwd;
68
69         PackageManager package_manager;
70         SourcePackage *main_pkg;
71
72         TargetMap targets;
73         TargetList new_tgts;
74
75         Architecture native_arch;
76         Architecture *current_arch;
77         StringMap cross_prefixes;
78         ProfileTemplateMap profile_tmpl;
79         Toolchain toolchain;
80         VirtualFileSystem vfs;
81
82         ProblemList problems;
83         Analyzer *analyzer;
84         bool build;
85         unsigned clean;
86         bool dry_run;
87         bool help;
88         unsigned verbose;
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         unsigned get_verbose() const { return verbose; }
109         bool get_dry_run() const { return dry_run; }
110
111         PackageManager &get_package_manager() { return package_manager; }
112         SourcePackage *get_main_package() const { return main_pkg; }
113
114         /** Looks up a target by name.  Returns 0 if no such target exists. */
115         Target *get_target(const std::string &) const;
116
117         const TargetMap &get_targets() const { return targets; }
118
119         const Msp::FS::Path &get_cwd() const { return cwd; }
120         const Architecture &get_current_arch() const { return *current_arch; }
121         const Architecture &get_native_arch() const { return native_arch; }
122         const Msp::FS::Path &get_prefix() const { return prefix; }
123         const StringList &get_warnings() const { return warnings; }
124         void apply_profile_template(Config &, const std::string &) const;
125
126         const Toolchain &get_toolchain() const { return toolchain; }
127         VirtualFileSystem &get_vfs() { return vfs; }
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