]> git.tdb.fi Git - builder.git/blobdiff - source/buildgraph.h
Refactor build graph into its own class
[builder.git] / source / buildgraph.h
diff --git a/source/buildgraph.h b/source/buildgraph.h
new file mode 100644 (file)
index 0000000..54409c0
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef BUILDGRAPH_H_
+#define BUILDGRAPH_H_
+
+#include "virtualfilesystem.h"
+
+class Builder;
+class Target;
+
+/**
+Manages a graph of targets.
+*/
+class BuildGraph
+{
+public:
+       typedef std::map<std::string, Target *> TargetMap;
+
+private:
+       Builder &builder;
+       TargetMap targets;
+
+public:
+       BuildGraph(Builder &);
+       ~BuildGraph();
+
+       /** Looks up a target by name.  Returns 0 if no such target exists. */
+       Target *get_target(const std::string &) const;
+
+       const TargetMap &get_targets() const { return targets; }
+
+       /** Adds a target.  It can later be retrieved by name.  Called from Target
+       constructor. */
+       void add_target(Target *);
+
+       /** Adds a target that is a primary build goal.  Such targets will be added
+       as dependencies of the "world" virtual target.  If the target belongs to a
+       default component of the main package, it's also added to the "default"
+       virtual target. */
+       void add_primary_target(Target &);
+
+       /** Adds a target that will be installed.  A new InstalledFile target is
+       created and added as a dependency to the "install" virtual target. */
+       void add_installed_target(Target &);
+};
+
+#endif