]> git.tdb.fi Git - builder.git/blob - source/builder.h
Hide the main package from the outside
[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
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
100         /** Looks up a target by name.  Returns 0 if no such target exists. */
101         Target *get_target(const std::string &) const;
102
103         const TargetMap &get_targets() const { return targets; }
104
105         const Msp::FS::Path &get_work_directory() const { return cwd; }
106         const Architecture &get_current_arch() const { return *current_arch; }
107         const Architecture &get_native_arch() const { return native_arch; }
108         const Msp::FS::Path &get_prefix() const { return prefix; }
109         const Msp::FS::Path &get_temp_directory() const { return tempdir; }
110
111         const Toolchain &get_toolchain() const { return toolchain; }
112         VirtualFileSystem &get_vfs() { return vfs; }
113         const Logger &get_logger() const { return logger; }
114
115         /** Adds a target to both the target map and the new target queue.  Called
116         from Target constructor. */
117         void add_target(Target *);
118
119         /** Adds a target that is a primary build goal.  Such targets will be added
120         as dependencies of the "world" virtual target.  If the target belongs to a
121         default component of the main package, it's also added to the "default"
122         virtual target. */
123         void add_primary_target(Target &);
124
125         void problem(const std::string &, const std::string &);
126
127         static void usage(const char *, const char *, bool);
128
129         /** Loads a build file.  Returns 0 on success or -1 if the file could not be
130         opened. */
131         int load_build_file(const Msp::FS::Path &);
132
133 private:
134         /** Prepares packages and targets for building.  Returns true if everything
135         went ok, or false if something bad happened and a build shouldn't be
136         attempted. */
137         bool prepare_build();
138
139         /** Supervises the build process, starting new tasks when slots become
140         available. */
141         int do_build();
142
143         /** Cleans buildable targets.  If clean is 1, cleans only the default
144         package.  If clean is 2 or greater, cleans all buildable packages.
145         */
146         int do_clean();
147
148         int do_create_makefile();
149
150         /** Prints out information about the default package. */
151         void package_help();
152 };
153
154 #endif