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