Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit c6144cc

Browse files
committed
merge FileStat into Node
The two were always one-to-one anyway. I started adding accessors to FileStat and then realized most users wanted them on Node and that forwarding them through was silly.
1 parent 276f2b3 commit c6144cc

14 files changed

+119
-109
lines changed

src/build.cc

+11-11
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ bool Plan::AddSubTarget(Node* node, vector<Node*>* stack, string* err) {
195195
if (node->dirty_) {
196196
string referenced;
197197
if (!stack->empty())
198-
referenced = ", needed by '" + stack->back()->file_->path_ + "',";
199-
*err = "'" + node->file_->path_ + "'" + referenced + " missing "
198+
referenced = ", needed by '" + stack->back()->path() + "',";
199+
*err = "'" + node->path() + "'" + referenced + " missing "
200200
"and no known rule to make it";
201201
}
202202
return false;
@@ -256,7 +256,7 @@ bool Plan::CheckDependencyCycle(Node* node, vector<Node*>* stack, string* err) {
256256
for (vector<Node*>::iterator i = start; i != stack->end(); ++i) {
257257
if (i != start)
258258
err->append(" -> ");
259-
err->append((*i)->file_->path_);
259+
err->append((*i)->path());
260260
}
261261
return true;
262262
}
@@ -324,8 +324,8 @@ void Plan::CleanNode(BuildLog* build_log, Node* node) {
324324
// Recompute most_recent_input and command.
325325
time_t most_recent_input = 1;
326326
for (vector<Node*>::iterator ni = begin; ni != end; ++ni)
327-
if ((*ni)->file_->mtime_ > most_recent_input)
328-
most_recent_input = (*ni)->file_->mtime_;
327+
if ((*ni)->mtime() > most_recent_input)
328+
most_recent_input = (*ni)->mtime();
329329
string command = (*ei)->EvaluateCommand();
330330

331331
// Now, recompute the dirty state of each output.
@@ -454,7 +454,7 @@ Node* Builder::AddTarget(const string& name, string* err) {
454454
}
455455

456456
bool Builder::AddTarget(Node* node, string* err) {
457-
node->file_->StatIfNecessary(disk_interface_);
457+
node->StatIfNecessary(disk_interface_);
458458
if (Edge* in_edge = node->in_edge_) {
459459
if (!in_edge->RecomputeDirty(state_, disk_interface_, err))
460460
return false;
@@ -555,7 +555,7 @@ bool Builder::StartEdge(Edge* edge, string* err) {
555555
// XXX: this will block; do we care?
556556
for (vector<Node*>::iterator i = edge->outputs_.begin();
557557
i != edge->outputs_.end(); ++i) {
558-
if (!disk_interface_->MakeDirs((*i)->file_->path_))
558+
if (!disk_interface_->MakeDirs((*i)->path()))
559559
return false;
560560
}
561561

@@ -578,9 +578,9 @@ void Builder::FinishEdge(Edge* edge, bool success, const string& output) {
578578

579579
for (vector<Node*>::iterator i = edge->outputs_.begin();
580580
i != edge->outputs_.end(); ++i) {
581-
if ((*i)->file_->exists()) {
582-
time_t new_mtime = disk_interface_->Stat((*i)->file_->path_);
583-
if ((*i)->file_->mtime_ == new_mtime) {
581+
if ((*i)->exists()) {
582+
time_t new_mtime = disk_interface_->Stat((*i)->path());
583+
if ((*i)->mtime() == new_mtime) {
584584
// The rule command did not change the output. Propagate the clean
585585
// state through the build graph.
586586
plan_.CleanNode(log_, *i);
@@ -594,7 +594,7 @@ void Builder::FinishEdge(Edge* edge, bool success, const string& output) {
594594
// (existing) non-order-only input or the depfile.
595595
for (vector<Node*>::iterator i = edge->inputs_.begin();
596596
i != edge->inputs_.end() - edge->order_only_deps_; ++i) {
597-
time_t input_mtime = disk_interface_->Stat((*i)->file_->path_);
597+
time_t input_mtime = disk_interface_->Stat((*i)->path());
598598
if (input_mtime == 0) {
599599
restat_mtime = 0;
600600
break;

src/build_log.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void BuildLog::RecordCommand(Edge* edge, int start_time, int end_time,
7373
const string command = edge->EvaluateCommand();
7474
for (vector<Node*>::iterator out = edge->outputs_.begin();
7575
out != edge->outputs_.end(); ++out) {
76-
const string& path = (*out)->file_->path_;
76+
const string& path = (*out)->path();
7777
Log::iterator i = log_.find(path.c_str());
7878
LogEntry* log_entry;
7979
if (i != log_.end()) {

src/build_test.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ TEST_F(PlanTest, Basic) {
3838

3939
Edge* edge = plan_.FindWork();
4040
ASSERT_TRUE(edge);
41-
ASSERT_EQ("in", edge->inputs_[0]->file_->path_);
42-
ASSERT_EQ("mid", edge->outputs_[0]->file_->path_);
41+
ASSERT_EQ("in", edge->inputs_[0]->path());
42+
ASSERT_EQ("mid", edge->outputs_[0]->path());
4343

4444
ASSERT_FALSE(plan_.FindWork());
4545

4646
plan_.EdgeFinished(edge);
4747

4848
edge = plan_.FindWork();
4949
ASSERT_TRUE(edge);
50-
ASSERT_EQ("mid", edge->inputs_[0]->file_->path_);
51-
ASSERT_EQ("out", edge->outputs_[0]->file_->path_);
50+
ASSERT_EQ("mid", edge->inputs_[0]->path());
51+
ASSERT_EQ("out", edge->outputs_[0]->path());
5252

5353
plan_.EdgeFinished(edge);
5454

@@ -222,7 +222,7 @@ void BuildTest::Dirty(const string& path) {
222222
// If it's an input file, mark that we've already stat()ed it and
223223
// it's missing.
224224
if (!node->in_edge_)
225-
node->file_->mtime_ = 0;
225+
node->MarkMissing();
226226
}
227227

228228
bool BuildTest::CanRunMore() {
@@ -237,7 +237,7 @@ bool BuildTest::StartCommand(Edge* edge) {
237237
edge->rule().name_ == "touch") {
238238
for (vector<Node*>::iterator out = edge->outputs_.begin();
239239
out != edge->outputs_.end(); ++out) {
240-
fs_.Create((*out)->file_->path_, now_, "");
240+
fs_.Create((*out)->path(), now_, "");
241241
}
242242
} else if (edge->rule().name_ == "true" ||
243243
edge->rule().name_ == "fail") {
@@ -508,10 +508,10 @@ TEST_F(BuildTest, OrderOnlyDeps) {
508508
EXPECT_EQ(1, edge->order_only_deps_);
509509
// Verify the inputs are in the order we expect
510510
// (explicit then implicit then orderonly).
511-
EXPECT_EQ("foo.c", edge->inputs_[0]->file_->path_);
512-
EXPECT_EQ("blah.h", edge->inputs_[1]->file_->path_);
513-
EXPECT_EQ("bar.h", edge->inputs_[2]->file_->path_);
514-
EXPECT_EQ("otherfile", edge->inputs_[3]->file_->path_);
511+
EXPECT_EQ("foo.c", edge->inputs_[0]->path());
512+
EXPECT_EQ("blah.h", edge->inputs_[1]->path());
513+
EXPECT_EQ("bar.h", edge->inputs_[2]->path());
514+
EXPECT_EQ("otherfile", edge->inputs_[3]->path());
515515

516516
// Expect the command line we generate to only use the original input.
517517
ASSERT_EQ("cc foo.c", edge->EvaluateCommand());

src/clean.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int Cleaner::CleanAll(bool generator) {
109109
continue;
110110
for (vector<Node*>::iterator out_node = (*e)->outputs_.begin();
111111
out_node != (*e)->outputs_.end(); ++out_node) {
112-
Remove((*out_node)->file_->path_);
112+
Remove((*out_node)->path());
113113
}
114114
if (!(*e)->rule().depfile_.empty())
115115
Remove((*e)->EvaluateDepFile());
@@ -120,7 +120,7 @@ int Cleaner::CleanAll(bool generator) {
120120

121121
void Cleaner::DoCleanTarget(Node* target) {
122122
if (target->in_edge_) {
123-
Remove(target->file_->path_);
123+
Remove(target->path());
124124
for (vector<Node*>::iterator n = target->in_edge_->inputs_.begin();
125125
n != target->in_edge_->inputs_.end();
126126
++n) {
@@ -182,7 +182,7 @@ void Cleaner::DoCleanRule(const Rule* rule) {
182182
for (vector<Node*>::iterator out_node = (*e)->outputs_.begin();
183183
out_node != (*e)->outputs_.end();
184184
++out_node)
185-
Remove((*out_node)->file_->path_);
185+
Remove((*out_node)->path());
186186
}
187187

188188
int Cleaner::CleanRule(const Rule* rule) {

src/disk_interface_test.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ TEST_F(StatTest, Simple) {
193193
"build out: cat in\n"));
194194

195195
Node* out = GetNode("out");
196-
out->file_->Stat(this);
196+
out->Stat(this);
197197
ASSERT_EQ(1u, stats_.size());
198198
Edge* edge = out->in_edge_;
199199
edge->RecomputeDirty(NULL, this, NULL);
@@ -208,7 +208,7 @@ TEST_F(StatTest, TwoStep) {
208208
"build mid: cat in\n"));
209209

210210
Node* out = GetNode("out");
211-
out->file_->Stat(this);
211+
out->Stat(this);
212212
ASSERT_EQ(1u, stats_.size());
213213
Edge* edge = out->in_edge_;
214214
edge->RecomputeDirty(NULL, this, NULL);
@@ -227,7 +227,7 @@ TEST_F(StatTest, Tree) {
227227
"build mid2: cat in21 in22\n"));
228228

229229
Node* out = GetNode("out");
230-
out->file_->Stat(this);
230+
out->Stat(this);
231231
ASSERT_EQ(1u, stats_.size());
232232
Edge* edge = out->in_edge_;
233233
edge->RecomputeDirty(NULL, this, NULL);
@@ -247,7 +247,7 @@ TEST_F(StatTest, Middle) {
247247
mtimes_["out"] = 1;
248248

249249
Node* out = GetNode("out");
250-
out->file_->Stat(this);
250+
out->Stat(this);
251251
ASSERT_EQ(1u, stats_.size());
252252
Edge* edge = out->in_edge_;
253253
edge->RecomputeDirty(NULL, this, NULL);

src/graph.cc

+18-18
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "state.h"
2424
#include "util.h"
2525

26-
bool FileStat::Stat(DiskInterface* disk_interface) {
26+
bool Node::Stat(DiskInterface* disk_interface) {
2727
mtime_ = disk_interface->Stat(path_);
2828
return mtime_ > 0;
2929
}
@@ -41,13 +41,13 @@ bool Edge::RecomputeDirty(State* state, DiskInterface* disk_interface,
4141
// Visit all inputs; we're dirty if any of the inputs are dirty.
4242
time_t most_recent_input = 1;
4343
for (vector<Node*>::iterator i = inputs_.begin(); i != inputs_.end(); ++i) {
44-
if ((*i)->file_->StatIfNecessary(disk_interface)) {
44+
if ((*i)->StatIfNecessary(disk_interface)) {
4545
if (Edge* edge = (*i)->in_edge_) {
4646
if (!edge->RecomputeDirty(state, disk_interface, err))
4747
return false;
4848
} else {
4949
// This input has no in-edge; it is dirty if it is missing.
50-
(*i)->dirty_ = !(*i)->file_->exists();
50+
(*i)->dirty_ = !(*i)->exists();
5151
}
5252
}
5353

@@ -63,8 +63,8 @@ bool Edge::RecomputeDirty(State* state, DiskInterface* disk_interface,
6363
if ((*i)->dirty_) {
6464
dirty = true;
6565
} else {
66-
if ((*i)->file_->mtime_ > most_recent_input)
67-
most_recent_input = (*i)->file_->mtime_;
66+
if ((*i)->mtime() > most_recent_input)
67+
most_recent_input = (*i)->mtime();
6868
}
6969
}
7070
}
@@ -77,7 +77,7 @@ bool Edge::RecomputeDirty(State* state, DiskInterface* disk_interface,
7777

7878
for (vector<Node*>::iterator i = outputs_.begin();
7979
i != outputs_.end(); ++i) {
80-
(*i)->file_->StatIfNecessary(disk_interface);
80+
(*i)->StatIfNecessary(disk_interface);
8181
if (RecomputeOutputDirty(build_log, most_recent_input, command, *i)) {
8282
dirty = true;
8383
break;
@@ -88,7 +88,7 @@ bool Edge::RecomputeDirty(State* state, DiskInterface* disk_interface,
8888
// Finally, visit each output to mark off that we've visited it, and update
8989
// their dirty state if necessary.
9090
for (vector<Node*>::iterator i = outputs_.begin(); i != outputs_.end(); ++i) {
91-
(*i)->file_->StatIfNecessary(disk_interface);
91+
(*i)->StatIfNecessary(disk_interface);
9292
if (dirty)
9393
(*i)->dirty_ = true;
9494
}
@@ -107,23 +107,23 @@ bool Edge::RecomputeOutputDirty(BuildLog* build_log, time_t most_recent_input,
107107
if (is_phony()) {
108108
// Phony edges don't write any output.
109109
// Outputs are only dirty if there are no inputs and we're missing the output.
110-
return inputs_.empty() && !output->file_->exists();
110+
return inputs_.empty() && !output->exists();
111111
}
112112

113113
BuildLog::LogEntry* entry = 0;
114114

115115
// Dirty if we're missing the output.
116-
if (!output->file_->exists())
116+
if (!output->exists())
117117
return true;
118118

119119
// Dirty if the output is older than the input.
120-
if (output->file_->mtime_ < most_recent_input) {
120+
if (output->mtime() < most_recent_input) {
121121
// If this is a restat rule, we may have cleaned the output with a restat
122122
// rule in a previous run and stored the most recent input mtime in the
123123
// build log. Use that mtime instead, so that the file will only be
124124
// considered dirty if an input was modified since the previous run.
125125
if (rule_->restat_ && build_log &&
126-
(entry = build_log->LookupByOutput(output->file_->path_))) {
126+
(entry = build_log->LookupByOutput(output->path()))) {
127127
if (entry->restat_mtime < most_recent_input)
128128
return true;
129129
} else {
@@ -135,7 +135,7 @@ bool Edge::RecomputeOutputDirty(BuildLog* build_log, time_t most_recent_input,
135135
// But if this is a generator rule, the command changing does not make us
136136
// dirty.
137137
if (!rule_->generator_ && build_log &&
138-
(entry || (entry = build_log->LookupByOutput(output->file_->path_)))) {
138+
(entry || (entry = build_log->LookupByOutput(output->path())))) {
139139
if (command != entry->command)
140140
return true;
141141
}
@@ -164,14 +164,14 @@ struct EdgeEnv : public Env {
164164
i != edge_->inputs_.end() && explicit_deps; ++i, --explicit_deps) {
165165
if (!result.empty())
166166
result.push_back(' ');
167-
result.append((*i)->file_->path_);
167+
result.append((*i)->path());
168168
}
169169
} else if (var == "out") {
170170
for (vector<Node*>::iterator i = edge_->outputs_.begin();
171171
i != edge_->outputs_.end(); ++i) {
172172
if (!result.empty())
173173
result.push_back(' ');
174-
result.append((*i)->file_->path_);
174+
result.append((*i)->path());
175175
}
176176
} else if (edge_->env_) {
177177
return edge_->env_->LookupVariable(var);
@@ -213,10 +213,10 @@ bool Edge::LoadDepFile(State* state, DiskInterface* disk_interface,
213213
}
214214

215215
// Check that this depfile matches our output.
216-
StringPiece opath = StringPiece(outputs_[0]->file_->path_);
216+
StringPiece opath = StringPiece(outputs_[0]->path());
217217
if (opath != makefile.out_) {
218218
*err = "expected depfile '" + path + "' to mention '" +
219-
outputs_[0]->file_->path_ + "', got '" + makefile.out_.AsString() + "'";
219+
outputs_[0]->path() + "', got '" + makefile.out_.AsString() + "'";
220220
return false;
221221
}
222222

@@ -260,11 +260,11 @@ bool Edge::LoadDepFile(State* state, DiskInterface* disk_interface,
260260
void Edge::Dump() {
261261
printf("[ ");
262262
for (vector<Node*>::iterator i = inputs_.begin(); i != inputs_.end(); ++i) {
263-
printf("%s ", (*i)->file_->path_.c_str());
263+
printf("%s ", (*i)->path().c_str());
264264
}
265265
printf("--%s-> ", rule_->name_.c_str());
266266
for (vector<Node*>::iterator i = outputs_.begin(); i != outputs_.end(); ++i) {
267-
printf("%s ", (*i)->file_->path_.c_str());
267+
printf("%s ", (*i)->path().c_str());
268268
}
269269
printf("]\n");
270270
}

0 commit comments

Comments
 (0)