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"
15 #include "packagemanager.h"
18 #include "toolchain.h"
19 #include "virtualfilesystem.h"
28 The main application class. Controls and owns everything. Rules the world.
30 class Builder: public Msp::RegisteredApplication<Builder>
33 class Loader: public Msp::DataFile::ObjectLoader<Builder>
39 Loader(Builder &, const Msp::FS::Path &);
41 void architecture(const std::string &);
42 void binpkg(const std::string &);
43 void build_type(const std::string &);
44 void profile(const std::string &);
45 void package(const std::string &);
49 typedef std::map<std::string, Target *> TargetMap;
52 typedef std::map<std::string, BuildType> BuildTypeMap;
54 StringList cmdline_targets;
55 StringMap cmdline_options;
58 PackageManager package_manager;
59 SourcePackage *main_pkg;
63 Architecture native_arch;
64 Architecture *current_arch;
65 BuildTypeMap build_types;
66 BuildType *build_type;
68 VirtualFileSystem vfs;
78 std::string build_file;
88 static std::string usagemsg;
89 static std::string helpmsg;
92 Builder(int, char **);
96 bool get_dry_run() const { return dry_run; }
98 PackageManager &get_package_manager() { return package_manager; }
99 SourcePackage *get_main_package() const { return main_pkg; }
101 /** Looks up a target by name. Returns 0 if no such target exists. */
102 Target *get_target(const std::string &) const;
104 const TargetMap &get_targets() const { return targets; }
106 const Msp::FS::Path &get_cwd() const { return cwd; }
107 const Architecture &get_current_arch() const { return *current_arch; }
108 const Architecture &get_native_arch() const { return native_arch; }
109 const Msp::FS::Path &get_prefix() const { return prefix; }
110 const StringList &get_warnings() const { return warnings; }
112 const Toolchain &get_toolchain() const { return toolchain; }
113 VirtualFileSystem &get_vfs() { return vfs; }
114 const Logger &get_logger() const { return logger; }
116 /** Adds a target to both the target map and the new target queue. Called
117 from Target constructor. */
118 void add_target(Target *);
120 void problem(const std::string &, const std::string &);
122 static void usage(const char *, const char *, bool);
124 /** Loads a build file. Returns 0 on success or -1 if the file could not be
126 int load_build_file(const Msp::FS::Path &);
129 /** Creates targets for all packages and prepares them for building.
130 Returns 0 if everything went ok, -1 if something bad happened and a build
131 shouldn't be attempted. */
132 int create_targets();
134 /** Supervises the build process, starting new actions when slots become
138 /** Cleans buildable targets. If clean is 1, cleans only the default
139 package. If clean is 2 or greater, cleans all buildable packages.
143 int do_create_makefile();
145 /** Prints out information about the default package. */