]> git.tdb.fi Git - builder.git/blob - source/builder.h
Make tempdir a global option
[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         Msp::FS::Path tempdir;
88         StringList warnings;
89
90         static std::string usagemsg;
91         static std::string helpmsg;
92
93 public:
94         Builder(int, char **);
95         ~Builder();
96
97         int main();
98         bool get_dry_run() const { return dry_run; }
99
100         PackageManager &get_package_manager() { return package_manager; }
101         SourcePackage *get_main_package() const { return main_pkg; }
102
103         /** Looks up a target by name.  Returns 0 if no such target exists. */
104         Target *get_target(const std::string &) const;
105
106         const TargetMap &get_targets() const { return targets; }
107
108         const Msp::FS::Path &get_cwd() const { return cwd; }
109         const Architecture &get_current_arch() const { return *current_arch; }
110         const Architecture &get_native_arch() const { return native_arch; }
111         const Msp::FS::Path &get_prefix() const { return prefix; }
112         const Msp::FS::Path &get_temp_directory() const { return tempdir; }
113         const StringList &get_warnings() const { return warnings; }
114
115         const Toolchain &get_toolchain() const { return toolchain; }
116         VirtualFileSystem &get_vfs() { return vfs; }
117         const Logger &get_logger() const { return logger; }
118
119         /** Adds a target to both the target map and the new target queue.  Called
120         from Target constructor. */
121         void add_target(Target *);
122
123         void problem(const std::string &, const std::string &);
124
125         static void usage(const char *, const char *, bool);
126
127         /** Loads a build file.  Returns 0 on success or -1 if the file could not be
128         opened. */
129         int load_build_file(const Msp::FS::Path &);
130
131 private:
132         /** Creates targets for all packages and prepares them for building.
133         Returns 0 if everything went ok, -1 if something bad happened and a build
134         shouldn't be attempted. */
135         int create_targets();
136
137         /** Supervises the build process, starting new actions when slots become
138         available. */
139         int do_build();
140
141         /** Cleans buildable targets.  If clean is 1, cleans only the default
142         package.  If clean is 2 or greater, cleans all buildable packages.
143         */
144         int do_clean();
145
146         int do_create_makefile();
147
148         /** Prints out information about the default package. */
149         void package_help();
150 };
151
152 #endif