summaryrefslogtreecommitdiffstats
path: root/src/build.h
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2010-12-05 00:09:50 (GMT)
committerEvan Martin <martine@danga.com>2010-12-05 00:09:50 (GMT)
commit42d237e7841679b27cd5dcae82d143d86a87a807 (patch)
tree253b0cf88ecf3b0404146a7c7945dd4c660afa04 /src/build.h
parentd0025e234cf3fc0a13f45d179880578285609b59 (diff)
downloadNinja-42d237e7841679b27cd5dcae82d143d86a87a807.zip
Ninja-42d237e7841679b27cd5dcae82d143d86a87a807.tar.gz
Ninja-42d237e7841679b27cd5dcae82d143d86a87a807.tar.bz2
move src into subdir
Diffstat (limited to 'src/build.h')
-rw-r--r--src/build.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/build.h b/src/build.h
new file mode 100644
index 0000000..cf0e67f
--- /dev/null
+++ b/src/build.h
@@ -0,0 +1,75 @@
+#ifndef NINJA_BUILD_H_
+#define NINJA_BUILD_H_
+
+#include <set>
+#include <string>
+#include <queue>
+#include <vector>
+using namespace std;
+
+struct Edge;
+struct DiskInterface;
+struct Node;
+struct State;
+
+// Plan stores the state of a build plan: what we intend to build,
+// which steps we're ready to execute.
+struct Plan {
+ // Add a target to our plan (including all its dependencies).
+ // Returns false if we don't need to build this target; may
+ // fill in |err| with an error message if there's a problem.
+ bool AddTarget(Node* node, string* err);
+
+ // Pop a ready edge off the queue of edges to build.
+ // Returns NULL if there's no work to do.
+ Edge* FindWork();
+
+ // Returns true if there's more work to be done.
+ bool more_to_do() const { return !want_.empty(); }
+
+ // Dumps the current state of the plan.
+ void Dump();
+
+ // Mark an edge as done building. Used internally and by
+ // tests.
+ void EdgeFinished(Edge* edge);
+
+ // Number of edges to run.
+ int edge_count() const { return want_.size() + ready_.size(); }
+
+private:
+ bool AddSubTarget(Node* node, vector<Node*>* stack, string* err);
+ bool CheckDependencyCycle(Node* node, vector<Node*>* stack, string* err);
+ void NodeFinished(Node* node);
+
+ set<Edge*> want_;
+ set<Edge*> ready_;
+};
+
+// CommandRunner is an interface that wraps running the build
+// subcommands. This allows tests to abstract out running commands.
+// RealCommandRunner is an implementation that actually runs commands.
+struct CommandRunner {
+ virtual ~CommandRunner() {}
+ virtual bool CanRunMore() = 0;
+ virtual bool StartCommand(Edge* edge) = 0;
+ virtual void WaitForCommands() = 0;
+ virtual Edge* NextFinishedCommand(bool* success) = 0;
+};
+
+struct Builder {
+ Builder(State* state);
+
+ Node* AddTarget(const string& name, string* err);
+ bool Build(string* err);
+
+ bool StartEdge(Edge* edge, string* err);
+ void FinishEdge(Edge* edge);
+
+ State* state_;
+ Plan plan_;
+ DiskInterface* disk_interface_;
+ CommandRunner* command_runner_;
+};
+
+#endif // NINJA_BUILD_H_