1 // Copyright 2015 Google Inc. All Rights Reserved.
2 //
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
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14 
15 #ifndef NINJA_DYNDEP_LOADER_H_
16 #define NINJA_DYNDEP_LOADER_H_
17 
18 #include <map>
19 #include <string>
20 #include <vector>
21 
22 struct DiskInterface;
23 struct Edge;
24 struct Node;
25 struct State;
26 
27 /// Store dynamically-discovered dependency information for one edge.
28 struct Dyndeps {
DyndepsDyndeps29   Dyndeps() : used_(false), restat_(false) {}
30   bool used_;
31   bool restat_;
32   std::vector<Node*> implicit_inputs_;
33   std::vector<Node*> implicit_outputs_;
34 };
35 
36 /// Store data loaded from one dyndep file.  Map from an edge
37 /// to its dynamically-discovered dependency information.
38 /// This is a struct rather than a typedef so that we can
39 /// forward-declare it in other headers.
40 struct DyndepFile: public std::map<Edge*, Dyndeps> {};
41 
42 /// DyndepLoader loads dynamically discovered dependencies, as
43 /// referenced via the "dyndep" attribute in build files.
44 struct DyndepLoader {
DyndepLoaderDyndepLoader45   DyndepLoader(State* state, DiskInterface* disk_interface)
46       : state_(state), disk_interface_(disk_interface) {}
47 
48   /// Load a dyndep file from the given node's path and update the
49   /// build graph with the new information.  One overload accepts
50   /// a caller-owned 'DyndepFile' object in which to store the
51   /// information loaded from the dyndep file.
52   bool LoadDyndeps(Node* node, std::string* err) const;
53   bool LoadDyndeps(Node* node, DyndepFile* ddf, std::string* err) const;
54 
55  private:
56   bool LoadDyndepFile(Node* file, DyndepFile* ddf, std::string* err) const;
57 
58   bool UpdateEdge(Edge* edge, Dyndeps const* dyndeps, std::string* err) const;
59 
60   State* state_;
61   DiskInterface* disk_interface_;
62 };
63 
64 #endif  // NINJA_DYNDEP_LOADER_H_
65