]> git.tdb.fi Git - builder.git/blob - source/builder.h
Replace the overly generic configuration profiles with something more purposeful
[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 "buildtype.h"
12 #include "config.h"
13 #include "logger.h"
14 #include "misc.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 Config;
23 class FileTarget;
24 class Package;
25 class SourcePackage;
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::ObjectLoader<Builder>
34         {
35         private:
36                 Msp::FS::Path src;
37
38         public:
39                 Loader(Builder &, const Msp::FS::Path &);
40         private:
41                 void architecture(const std::string &);
42                 void binpkg(const std::string &);
43                 void build_type(const std::string &);
44                 void profile(const std::string &);
45                 void package(const std::string &);
46         };
47
48 public:
49         typedef std::map<std::string, Target *> TargetMap;
50
51 private:
52         typedef std::map<std::string, BuildType> BuildTypeMap;
53
54         StringList cmdline_targets;
55         StringMap cmdline_options;
56         Msp::FS::Path cwd;
57
58         PackageManager package_manager;
59         SourcePackage *main_pkg;
60
61         TargetMap targets;
62
63         Architecture native_arch;
64         Architecture *current_arch;
65         BuildTypeMap build_types;
66         BuildType *build_type;
67         Toolchain toolchain;
68         VirtualFileSystem vfs;
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         StringList what_if;
81         bool conf_all;
82         bool conf_only;
83         bool build_all;
84         bool create_makefile;
85         Msp::FS::Path prefix;
86         StringList warnings;
87
88         static std::string usagemsg;
89         static std::string helpmsg;
90
91 public:
92         Builder(int, char **);
93         ~Builder();
94
95         int main();
96         bool get_dry_run() const { return dry_run; }
97
98         PackageManager &get_package_manager() { return package_manager; }
99         SourcePackage *get_main_package() const { return main_pkg; }
100
101         /** Looks up a target by name.  Returns 0 if no such target exists. */
102         Target *get_target(const std::string &) const;
103
104         const TargetMap &get_targets() const { return targets; }
105
106         const Msp::FS::Path &get_cwd() const { return cwd; }
107         const Architecture &get_current_arch() const { return *current_arch; }
108         const Architecture &get_native_arch() const { return native_arch; }
109         const Msp::FS::Path &get_prefix() const { return prefix; }
110         const StringList &get_warnings() const { return warnings; }
111
112         const Toolchain &get_toolchain() const { return toolchain; }
113         VirtualFileSystem &get_vfs() { return vfs; }
114         const Logger &get_logger() const { return logger; }
115
116         /** Adds a target to both the target map and the new target queue.  Called
117         from Target constructor. */
118         void add_target(Target *);
119
120         void problem(const std::string &, const std::string &);
121
122         static void usage(const char *, const char *, bool);
123
124         /** Loads a build file.  Returns 0 on success or -1 if the file could not be
125         opened. */
126         int load_build_file(const Msp::FS::Path &);
127
128 private:
129         /** Creates targets for all packages and prepares them for building.
130         Returns 0 if everything went ok, -1 if something bad happened and a build
131         shouldn't be attempted. */
132         int create_targets();
133
134         /** Supervises the build process, starting new actions when slots become
135         available. */
136         int do_build();
137
138         /** Cleans buildable targets.  If clean is 1, cleans only the default
139         package.  If clean is 2 or greater, cleans all buildable packages.
140         */
141         int do_clean();
142
143         int do_create_makefile();
144
145         /** Prints out information about the default package. */
146         void package_help();
147 };
148
149 #endif