• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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_MISSING_DEPS_H_
16 #define NINJA_MISSING_DEPS_H_
17 
18 #include <map>
19 #include <set>
20 #include <string>
21 
22 #if __cplusplus >= 201103L
23 #include <unordered_map>
24 #endif
25 
26 struct DepsLog;
27 struct DiskInterface;
28 struct Edge;
29 struct Node;
30 struct Rule;
31 struct State;
32 
33 class MissingDependencyScannerDelegate {
34  public:
35   virtual ~MissingDependencyScannerDelegate();
36   virtual void OnMissingDep(Node* node, const std::string& path,
37                             const Rule& generator) = 0;
38 };
39 
40 class MissingDependencyPrinter : public MissingDependencyScannerDelegate {
41   void OnMissingDep(Node* node, const std::string& path, const Rule& generator);
42   void OnStats(int nodes_processed, int nodes_missing_deps,
43                int missing_dep_path_count, int generated_nodes,
44                int generator_rules);
45 };
46 
47 struct MissingDependencyScanner {
48  public:
49   MissingDependencyScanner(MissingDependencyScannerDelegate* delegate,
50                            DepsLog* deps_log, State* state,
51                            DiskInterface* disk_interface);
52   void ProcessNode(Node* node);
53   void PrintStats();
HadMissingDepsMissingDependencyScanner54   bool HadMissingDeps() { return !nodes_missing_deps_.empty(); }
55 
56   void ProcessNodeDeps(Node* node, Node** dep_nodes, int dep_nodes_count);
57 
58   bool PathExistsBetween(Edge* from, Edge* to);
59 
60   MissingDependencyScannerDelegate* delegate_;
61   DepsLog* deps_log_;
62   State* state_;
63   DiskInterface* disk_interface_;
64   std::set<Node*> seen_;
65   std::set<Node*> nodes_missing_deps_;
66   std::set<Node*> generated_nodes_;
67   std::set<const Rule*> generator_rules_;
68   int missing_dep_path_count_;
69 
70  private:
71 #if __cplusplus >= 201103L
72   using InnerAdjacencyMap = std::unordered_map<Edge*, bool>;
73   using AdjacencyMap = std::unordered_map<Edge*, InnerAdjacencyMap>;
74 #else
75   typedef std::map<Edge*, bool> InnerAdjacencyMap;
76   typedef std::map<Edge*, InnerAdjacencyMap> AdjacencyMap;
77 #endif
78   AdjacencyMap adjacency_map_;
79 };
80 
81 #endif  // NINJA_MISSING_DEPS_H_
82