]> git.tdb.fi Git - builder.git/blobdiff - source/lib/component.h
Rearrange sources into subdirectories
[builder.git] / source / lib / component.h
diff --git a/source/lib/component.h b/source/lib/component.h
new file mode 100644 (file)
index 0000000..7ddd972
--- /dev/null
@@ -0,0 +1,87 @@
+#ifndef COMPONENT_H_
+#define COMPONENT_H_
+
+#include <string>
+#include <msp/datafile/objectloader.h>
+#include <msp/fs/path.h>
+#include "buildinfo.h"
+#include "conditionalloader.h"
+#include "installmap.h"
+#include "package.h"
+
+class SourcePackage;
+
+/**
+Components specify things to be built.  Each component may build one binary (it
+may also build none), as well as install a bunch of headers.  Components inherit
+dependencies and build info from the package they belong to, and may also add
+their own.
+*/
+class Component
+{
+public:
+       class Loader: public Msp::DataFile::ObjectLoader<Component>, public ConditionalLoader
+       {
+       public:
+               Loader(Component &);
+       private:
+               void build_info();
+               void install_map();
+               void overlay(const std::string &);
+               void require(const std::string &);
+               void source(const std::string &);
+       };
+
+protected:
+       SourcePackage &package;
+       std::string name;
+       std::vector<Msp::FS::Path> sources;
+       std::vector<std::string> overlays;
+       bool install = false;
+       BuildInfo build_info;
+       Package::Requirements requires;
+       bool deflt = true;
+       InstallMap install_map;
+       std::vector<std::string> problems;
+
+       Component(SourcePackage &p, const std::string &n): package(p), name(n) { }
+public:
+       virtual ~Component() { }
+
+       const SourcePackage &get_package() const { return package; }
+       const std::string &get_name() const { return name; }
+
+       /** Returns a list of sources for the component.  They may refer to
+       directories or individual files. */
+       const std::vector<Msp::FS::Path> &get_sources() const { return sources; }
+
+       const std::vector<std::string> &get_overlays() const { return overlays; }
+
+protected:
+       /** Returns a list of all source files for the component. */
+       std::vector<Msp::FS::Path> collect_source_files() const;
+
+public:
+       bool get_install() const { return install; }
+       const InstallMap &get_install_map() const { return install_map; }
+       const Package::Requirements &get_required_packages() const { return requires; }
+       bool is_default() const { return deflt; }
+       const std::vector<std::string> &get_problems() const { return problems; }
+
+       /** Prepares any required packages. */
+       void prepare();
+
+       /** Prepares the build information for building.  Pulls build info from the
+       parent and dependency packages, and adds any component-specific flags. */
+       virtual void create_build_info();
+
+       virtual void update_exported_build_info(BuildInfo &) const { }
+
+       const BuildInfo &get_build_info() const { return build_info; }
+
+       BuildInfo get_build_info_for_path(const Msp::FS::Path &) const;
+
+       virtual void create_targets() const = 0;
+};
+
+#endif