]> git.tdb.fi Git - builder.git/blob - source/builder.h
Move main package tracking to PackageManager
[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 "packagemanager.h"
15 #include "problem.h"
16 #include "target.h"
17 #include "toolchain.h"
18 #include "virtualfilesystem.h"
19
20 class Analyzer;
21 class FileTarget;
22 class Package;
23 class SourcePackage;
24
25 /**
26 The main application class.  Handles command line options and supervises the
27 build process.
28 */
29 class Builder: public Msp::RegisteredApplication<Builder>
30 {
31 private:
32         class Loader: public Msp::DataFile::ObjectLoader<Builder>
33         {
34         public:
35                 Loader(Builder &);
36         private:
37                 void architecture(const std::string &);
38                 void binpkg(const std::string &);
39                 void build_type(const std::string &);
40                 void profile(const std::string &);
41                 void package(const std::string &);
42         };
43
44 public:
45         typedef std::map<std::string, Target *> TargetMap;
46
47 private:
48         typedef std::list<std::string> NameList;
49         typedef std::map<std::string, BuildType> BuildTypeMap;
50         typedef std::list<Problem> ProblemList;
51
52         NameList cmdline_targets;
53         Config::InputOptions cmdline_options;
54         Msp::FS::Path cwd;
55
56         PackageManager package_manager;
57
58         TargetMap targets;
59
60         Architecture native_arch;
61         Architecture *current_arch;
62         BuildTypeMap build_types;
63         BuildType *build_type;
64         Toolchain toolchain;
65         VirtualFileSystem vfs;
66         Logger logger;
67
68         ProblemList problems;
69         Analyzer *analyzer;
70         bool build;
71         unsigned clean;
72         bool dry_run;
73         bool help;
74         bool show_progress;
75         std::string build_file;
76         unsigned jobs;
77         NameList what_if;
78         bool conf_all;
79         bool conf_only;
80         bool build_all;
81         bool create_makefile;
82         Msp::FS::Path prefix;
83         Msp::FS::Path tempdir;
84
85         static std::string usagemsg;
86         static std::string helpmsg;
87
88 public:
89         Builder(int, char **);
90         ~Builder();
91
92         int main();
93
94         PackageManager &get_package_manager() { return package_manager; }
95
96         /** Looks up a target by name.  Returns 0 if no such target exists. */
97         Target *get_target(const std::string &) const;
98
99         const TargetMap &get_targets() const { return targets; }
100
101         const Msp::FS::Path &get_work_directory() const { return cwd; }
102         const Architecture &get_current_arch() const { return *current_arch; }
103         const Architecture &get_native_arch() const { return native_arch; }
104         const Msp::FS::Path &get_prefix() const { return prefix; }
105         const Msp::FS::Path &get_temp_directory() const { return tempdir; }
106
107         const Toolchain &get_toolchain() const { return toolchain; }
108         VirtualFileSystem &get_vfs() { return vfs; }
109         const Logger &get_logger() const { return logger; }
110
111         /** Adds a target.  It can later be retrieved by name.  Called from Target
112         constructor. */
113         void add_target(Target *);
114
115         /** Adds a target that is a primary build goal.  Such targets will be added
116         as dependencies of the "world" virtual target.  If the target belongs to a
117         default component of the main package, it's also added to the "default"
118         virtual target. */
119         void add_primary_target(Target &);
120
121         /** Adds a target that will be installed.  A new InstalledFile target is
122         created and added as a dependency to the "install" virtual target. */
123         void add_installed_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         void 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