1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #ifndef NINJA_GRAPH_H_
16 #define NINJA_GRAPH_H_
28 FileStat(const string& path) : path_(path), mtime_(-1), node_(NULL) {}
30 // Return true if the file exists (mtime_ got a value).
31 bool Stat(DiskInterface* disk_interface);
33 // Return true if we needed to stat.
34 bool StatIfNecessary(DiskInterface* disk_interface) {
45 bool status_known() const {
50 // Possible values of mtime_:
51 // -1: file hasn't been examined
52 // 0: we looked, and file doesn't exist
53 // >0: actual file's mtime
60 Node(FileStat* file) : file_(file), dirty_(false), in_edge_(NULL) {}
62 bool dirty() const { return dirty_; }
67 vector<Edge*> out_edges_;
71 Rule(const string& name) : name_(name) { }
73 bool ParseCommand(const string& command, string* err) {
74 return command_.Parse(command, err);
78 EvalString description_;
84 Edge() : rule_(NULL), env_(NULL), implicit_deps_(0), order_only_deps_(0) {}
86 bool RecomputeDirty(State* state, DiskInterface* disk_interface, string* err);
87 string EvaluateCommand(); // XXX move to env, take env ptr
88 string GetDescription();
89 bool LoadDepFile(State* state, DiskInterface* disk_interface, string* err);
94 vector<Node*> inputs_;
95 vector<Node*> outputs_;
98 // XXX There are three types of inputs.
99 // 1) explicit deps, which show up as $in on the command line;
100 // 2) implicit deps, which the target depends on implicitly (e.g. C headers),
101 // and changes in them cause the target to rebuild;
102 // 3) order-only deps, which are needed before the target builds but which
103 // don't cause the target to rebuild.
104 // Currently we stuff all of these into inputs_ and keep counts of #2 and #3
105 // when we need to compute subsets. This is suboptimal; should think of a
106 // better representation. (Could make each pointer into a pair of a pointer
107 // and a type of input, or if memory matters could use the low bits of the
110 int order_only_deps_;
111 bool is_implicit(int index) {
112 return index >= ((int)inputs_.size()) - order_only_deps_ - implicit_deps_ &&
113 !is_order_only(index);
115 bool is_order_only(int index) {
116 return index >= ((int)inputs_.size()) - order_only_deps_;
119 bool is_phony() const;
122 // Exposed for testing.
123 bool CanonicalizePath(string* path, string* err);
125 #endif // NINJA_GRAPH_H_