]> git.tdb.fi Git - builder.git/blob - source/builder.h
Save caches before starting the build
[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/datafile/loader.h>
8 #include <msp/fs/path.h>
9 #include "architecture.h"
10 #include "buildgraph.h"
11 #include "buildtype.h"
12 #include "config.h"
13 #include "logger.h"
14 #include "packagemanager.h"
15 #include "target.h"
16 #include "toolchain.h"
17 #include "virtualfilesystem.h"
18
19 class FileTarget;
20 class Package;
21 class SourcePackage;
22
23 /**
24 This class ties everything else together.  It also contains code for loading
25 build files and supervising the build process.
26 */
27 class Builder
28 {
29 private:
30         class Loader: public Msp::DataFile::ObjectLoader<Builder>
31         {
32         private:
33                 const Config::InputOptions *options;
34                 bool conf_all;
35
36         public:
37                 Loader(Builder &, const Config::InputOptions * = 0, bool = false);
38                 ~Loader();
39
40         private:
41                 void architecture(const std::string &);
42                 void binpkg(const std::string &);
43                 void build_type(const std::string &);
44                 void package(const std::string &);
45         };
46
47 private:
48         typedef std::map<std::string, BuildType> BuildTypeMap;
49
50         PackageManager package_manager;
51
52         Architecture native_arch;
53         Architecture *current_arch;
54         BuildTypeMap build_types;
55         BuildType *build_type;
56         Toolchain toolchain;
57         VirtualFileSystem vfs;
58         BuildGraph build_graph;
59         Logger default_logger;
60         const Logger *logger;
61
62         Msp::FS::Path prefix;
63         Msp::FS::Path tempdir;
64
65         Loader *top_loader;
66
67 public:
68         Builder();
69         ~Builder();
70
71         PackageManager &get_package_manager() { return package_manager; }
72
73         void set_architecture(const std::string &);
74         const Architecture &get_current_arch() const { return *current_arch; }
75         const Architecture &get_native_arch() const { return native_arch; }
76         void set_build_type(const std::string &);
77         std::vector<std::string> get_build_types() const;
78         const BuildType &get_build_type() const { return *build_type; }
79         BuildGraph &get_build_graph() { return build_graph; }
80         void set_prefix(const Msp::FS::Path &);
81         void set_temp_directory(const Msp::FS::Path &);
82         const Msp::FS::Path &get_prefix() const { return prefix; }
83         const Msp::FS::Path &get_temp_directory() const { return tempdir; }
84
85         void add_default_tools();
86         const Toolchain &get_toolchain() const { return toolchain; }
87         VirtualFileSystem &get_vfs() { return vfs; }
88         void set_logger(const Logger *);
89         const Logger &get_logger() const { return *logger; }
90
91         std::list<std::string> collect_problems() const;
92
93         /** Loads a build file.  If opts is not null, it is used to configure any
94         packages loaded from this file.  If all is true, external packages are also
95         configured. */
96         void load_build_file(const Msp::FS::Path &, const Config::InputOptions *opts = 0, bool all = false);
97
98         /** Saves package configuration and dependency caches. */
99         void save_caches();
100
101         /** Builds the goal targets.  The build graph must be prepared first. */
102         int build(unsigned jobs = 1, bool dry_run = false, bool show_progress = false);
103
104         /** Cleans buildable targets.  If all is true, cleans all packages.
105         Otherwise cleans only the default package. */
106         int clean(bool all = false, bool dry_run = false);
107
108         int do_create_makefile();
109 };
110
111 #endif