forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdyndep.cc
83 lines (70 loc) · 2.75 KB
/
dyndep.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dyndep.h"
#include <assert.h>
#include <stdio.h>
#include "debug_flags.h"
#include "disk_interface.h"
#include "dyndep_parser.h"
#include "graph.h"
#include "state.h"
#include "util.h"
bool DyndepLoader::LoadDyndeps(Node* node, std::string* err) const {
DyndepFile ddf;
return LoadDyndeps(node, &ddf, err);
}
bool DyndepLoader::LoadDyndeps(Node* node, DyndepFile* ddf,
std::string* err) const {
// We are loading the dyndep file now so it is no longer pending.
node->set_dyndep_pending(false);
// Load the dyndep information from the file.
EXPLAIN("loading dyndep file '%s'", node->path().c_str());
if (!LoadDyndepFile(node, ddf, err))
return false;
// Update each edge that specified this node as its dyndep binding.
for (DyndepFile::const_iterator ddi = ddf->begin();
ddi != ddf->end(); ++ddi) {
Dyndeps const& dyndeps = ddi->second;
if (!UpdateEdge(ddi->first, &dyndeps, err)) {
return false;
}
}
// Some invariant provided by dep gen:
// - It has to be an input
// - It has to be marked as dyndep for each edge listed
// Reject extra outputs in dyndep file.
return true;
}
bool DyndepLoader::UpdateEdge(Edge* edge, Dyndeps const* dyndeps,
std::string* err) {
// Add dyndep-discovered bindings to the edge.
// We know the edge already has its own binding
// scope because it has a "dyndep" binding.
// Add the dyndep-discovered inputs to the edge.
edge->inputs_.insert(edge->inputs_.end() - edge->order_only_deps_,
dyndeps->implicit_inputs_.begin(),
dyndeps->implicit_inputs_.end());
edge->implicit_deps_ += dyndeps->implicit_inputs_.size();
// Add this edge as outgoing from each new input.
for (std::vector<Node*>::const_iterator i =
dyndeps->implicit_inputs_.begin();
i != dyndeps->implicit_inputs_.end(); ++i)
(*i)->AddOutEdge(edge);
return true;
}
bool DyndepLoader::LoadDyndepFile(Node* file, DyndepFile* ddf,
std::string* err) const {
DyndepParser parser(state_, disk_interface_, ddf);
return parser.Load(file->path(), err);
}