]> git.tdb.fi Git - builder.git/blob - source/builder.h
Evaluate conditions at load time to allow more flexibility
[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 FileTarget;
23 class Package;
24 class SourcePackage;
25
26 /**
27 The main application class.  Handles command line options and supervises the
28 build process.
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         Config::InputOptions 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         Msp::FS::Path tempdir;
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 Msp::FS::Path &get_temp_directory() const { return tempdir; }
112         const StringList &get_warnings() const { return warnings; }
113
114         const Toolchain &get_toolchain() const { return toolchain; }
115         VirtualFileSystem &get_vfs() { return vfs; }
116         const Logger &get_logger() const { return logger; }
117
118         /** Adds a target to both the target map and the new target queue.  Called
119         from Target constructor. */
120         void add_target(Target *);
121
122         void problem(const std::string &, const std::string &);
123
124         static void usage(const char *, const char *, bool);
125
126         /** Loads a build file.  Returns 0 on success or -1 if the file could not be
127         opened. */
128         int load_build_file(const Msp::FS::Path &);
129
130 private:
131         /** Creates targets for all packages and prepares them for building.
132         Returns 0 if everything went ok, -1 if something bad happened and a build
133         shouldn't be attempted. */
134         int create_targets();
135
136         /** Supervises the build process, starting new actions when slots become
137         available. */
138         int do_build();
139
140         /** Cleans buildable targets.  If clean is 1, cleans only the default
141         package.  If clean is 2 or greater, cleans all buildable packages.
142         */
143         int do_clean();
144
145         int do_create_makefile();
146
147         /** Prints out information about the default package. */
148         void package_help();
149 };
150
151 #endif