]> git.tdb.fi Git - builder.git/blob - source/builder.h
Move file-to-target mapping to a separate 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 "config.h"
12 #include "misc.h"
13 #include "problem.h"
14 #include "target.h"
15 #include "toolchain.h"
16 #include "virtualfilesystem.h"
17
18 class Analyzer;
19 class Config;
20 class FileTarget;
21 class Package;
22 class SourcePackage;
23 class VirtualTarget;
24
25 /**
26 The main application class.  Controls and owns everything.  Rules the world.
27 */
28 class Builder: public Msp::RegisteredApplication<Builder>
29 {
30 private:
31         class Loader: public Msp::DataFile::Loader
32         {
33         private:
34                 Builder &bld;
35                 Msp::FS::Path src;
36
37         public:
38                 Loader(Builder &, const Msp::FS::Path &);
39         private:
40                 void binpkg(const std::string &);
41                 void cross_prefix(const std::string &, const std::string &);
42                 void profile(const std::string &);
43                 void package(const std::string &);
44         };
45
46         class ProfileLoader: public Msp::DataFile::Loader
47         {
48         private:
49                 StringMap &profile;
50
51         public:
52                 ProfileLoader(StringMap &);
53         private:
54                 void option(const std::string &, const std::string &);
55         };
56
57 public:
58         typedef std::map<std::string, Target *> TargetMap;
59
60 private:
61         typedef std::list<Package *> PackageList;
62         typedef std::map<std::string, Package *> PackageMap;
63         typedef std::map<std::string, StringMap> ProfileTemplateMap;
64
65         StringList cmdline_targets;
66         StringMap cmdline_options;
67         Msp::FS::Path cwd;
68
69         PackageMap packages;
70         SourcePackage *main_pkg;
71         PathList pkg_path;
72         PathList pkg_dirs;
73         bool no_externals;
74
75         TargetMap targets;
76         TargetList new_tgts;
77
78         Architecture native_arch;
79         Architecture *current_arch;
80         StringMap cross_prefixes;
81         ProfileTemplateMap profile_tmpl;
82         Toolchain toolchain;
83         VirtualFileSystem vfs;
84
85         ProblemList problems;
86         Analyzer *analyzer;
87         bool build;
88         unsigned clean;
89         bool dry_run;
90         bool help;
91         unsigned verbose;
92         bool show_progress;
93         std::string build_file;
94         unsigned jobs;
95         StringList what_if;
96         bool conf_all;
97         bool conf_only;
98         bool build_all;
99         bool create_makefile;
100         Msp::FS::Path prefix;
101         StringList warnings;
102
103         static std::string usagemsg;
104         static std::string helpmsg;
105
106 public:
107         Builder(int, char **);
108         ~Builder();
109
110         int main();
111         unsigned get_verbose() const { return verbose; }
112         bool get_dry_run() const { return dry_run; }
113         bool get_build_all() const { return build_all; }
114
115         /** Gets a package by name, possibly creating it.  Returns 0 if the package
116         could not be located. */
117         Package *get_package(const std::string &);
118
119         SourcePackage *get_main_package() const { return main_pkg; }
120
121         std::string run_pkgconfig(const std::string &, const std::string &);
122
123         /** Looks up a target by name.  Returns 0 if no such target exists. */
124         Target *get_target(const std::string &) const;
125
126         const TargetMap &get_targets() const { return targets; }
127
128         const Msp::FS::Path &get_cwd() const { return cwd; }
129         const Architecture &get_current_arch() const { return *current_arch; }
130         const Architecture &get_native_arch() const { return native_arch; }
131         const Msp::FS::Path &get_prefix() const { return prefix; }
132         const StringList &get_warnings() const { return warnings; }
133         void apply_profile_template(Config &, const std::string &) const;
134
135         const Toolchain &get_toolchain() const { return toolchain; }
136         VirtualFileSystem &get_vfs() { return vfs; }
137
138         /** Adds a target to both the target map and the new target queue.  Called
139         from Target constructor. */
140         void add_target(Target *);
141         void register_path(const Msp::FS::Path &, FileTarget *);
142
143         void problem(const std::string &, const std::string &);
144
145         static void usage(const char *, const char *, bool);
146
147 private:
148         /** Determines the source directory of a package.  Pkg-config is consulted
149         first, and if it fails, the package path is searched for matches. */
150         Msp::FS::Path get_package_location(const std::string &);
151
152         /** Loads a build file.  Returns 0 on success or -1 if the file could not be
153         opened. */
154         int load_build_file(const Msp::FS::Path &);
155
156         /** Creates targets for all packages and prepares them for building.
157         Returns 0 if everything went ok, -1 if something bad happened and a build
158         shouldn't be attempted. */
159         int create_targets();
160
161         /** Supervises the build process, starting new actions when slots become
162         available. */
163         int do_build();
164
165         /** Cleans buildable targets.  If clean is 1, cleans only the default
166         package.  If clean is 2 or greater, cleans all buildable packages.
167         */
168         int do_clean();
169
170         int do_create_makefile();
171
172         /** Prints out information about the default package. */
173         void package_help();
174 };
175
176 #endif