]> git.tdb.fi Git - builder.git/blob - source/builder.h
Refactor build graph into its own class
[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 "buildgraph.h"
12 #include "buildtype.h"
13 #include "config.h"
14 #include "logger.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         public:
36                 Loader(Builder &);
37         private:
38                 void architecture(const std::string &);
39                 void binpkg(const std::string &);
40                 void build_type(const std::string &);
41                 void profile(const std::string &);
42                 void package(const std::string &);
43         };
44
45 private:
46         typedef std::list<std::string> NameList;
47         typedef std::map<std::string, BuildType> BuildTypeMap;
48         typedef std::list<Problem> ProblemList;
49
50         NameList cmdline_targets;
51         Config::InputOptions cmdline_options;
52         Msp::FS::Path cwd;
53
54         PackageManager package_manager;
55
56         Architecture native_arch;
57         Architecture *current_arch;
58         BuildTypeMap build_types;
59         BuildType *build_type;
60         Toolchain toolchain;
61         VirtualFileSystem vfs;
62         BuildGraph build_graph;
63         Logger logger;
64
65         ProblemList problems;
66         Analyzer *analyzer;
67         bool build;
68         unsigned clean;
69         bool dry_run;
70         bool help;
71         bool show_progress;
72         std::string build_file;
73         unsigned jobs;
74         NameList what_if;
75         bool conf_all;
76         bool conf_only;
77         bool build_all;
78         bool create_makefile;
79         Msp::FS::Path prefix;
80         Msp::FS::Path tempdir;
81
82         static std::string usagemsg;
83         static std::string helpmsg;
84
85 public:
86         Builder(int, char **);
87         ~Builder();
88
89         int main();
90
91         PackageManager &get_package_manager() { return package_manager; }
92
93         const Msp::FS::Path &get_work_directory() const { return cwd; }
94         const Architecture &get_current_arch() const { return *current_arch; }
95         const Architecture &get_native_arch() const { return native_arch; }
96         BuildGraph &get_build_graph() { return build_graph; }
97         const Msp::FS::Path &get_prefix() const { return prefix; }
98         const Msp::FS::Path &get_temp_directory() const { return tempdir; }
99
100         const Toolchain &get_toolchain() const { return toolchain; }
101         VirtualFileSystem &get_vfs() { return vfs; }
102         const Logger &get_logger() const { return logger; }
103
104         void problem(const std::string &, const std::string &);
105
106         static void usage(const char *, const char *, bool);
107
108         /** Loads a build file.  Returns 0 on success or -1 if the file could not be
109         opened. */
110         void load_build_file(const Msp::FS::Path &);
111
112 private:
113         /** Prepares packages and targets for building.  Returns true if everything
114         went ok, or false if something bad happened and a build shouldn't be
115         attempted. */
116         bool prepare_build();
117
118         /** Supervises the build process, starting new tasks when slots become
119         available. */
120         int do_build();
121
122         /** Cleans buildable targets.  If clean is 1, cleans only the default
123         package.  If clean is 2 or greater, cleans all buildable packages.
124         */
125         int do_clean();
126
127         int do_create_makefile();
128
129         /** Prints out information about the default package. */
130         void package_help();
131 };
132
133 #endif