OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef TOOLS_GN_HEADER_CHECKER_H_ | 5 #ifndef TOOLS_GN_HEADER_CHECKER_H_ |
6 #define TOOLS_GN_HEADER_CHECKER_H_ | 6 #define TOOLS_GN_HEADER_CHECKER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 23 matching lines...) Expand all Loading... |
34 const std::vector<const Target*>& targets); | 34 const std::vector<const Target*>& targets); |
35 | 35 |
36 // This assumes that the current thread already has a message loop. On | 36 // This assumes that the current thread already has a message loop. On |
37 // error, fills the given vector with the errors and returns false. Returns | 37 // error, fills the given vector with the errors and returns false. Returns |
38 // true on success. | 38 // true on success. |
39 bool Run(std::vector<Err>* errors); | 39 bool Run(std::vector<Err>* errors); |
40 | 40 |
41 private: | 41 private: |
42 friend class base::RefCountedThreadSafe<HeaderChecker>; | 42 friend class base::RefCountedThreadSafe<HeaderChecker>; |
43 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, IsDependencyOf); | 43 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, IsDependencyOf); |
| 44 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, |
| 45 IsDependencyOf_ForwardsDirectDependentConfigs); |
44 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, CheckInclude); | 46 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, CheckInclude); |
45 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, DoDirectDependentConfigsApply); | 47 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, |
| 48 GetDependentConfigChainProblemIndex); |
46 ~HeaderChecker(); | 49 ~HeaderChecker(); |
47 | 50 |
48 struct TargetInfo { | 51 struct TargetInfo { |
49 TargetInfo() : target(NULL), is_public(false) {} | 52 TargetInfo() : target(NULL), is_public(false) {} |
50 TargetInfo(const Target* t, bool p) : target(t), is_public(p) {} | 53 TargetInfo(const Target* t, bool p) : target(t), is_public(p) {} |
51 | 54 |
52 const Target* target; | 55 const Target* target; |
53 bool is_public; | 56 bool is_public; |
54 }; | 57 }; |
55 | 58 |
(...skipping 21 matching lines...) Expand all Loading... |
77 // include file. If disallowed, returns false and sets the error. The | 80 // include file. If disallowed, returns false and sets the error. The |
78 // range indicates the location of the include in the file for error | 81 // range indicates the location of the include in the file for error |
79 // reporting. | 82 // reporting. |
80 bool CheckInclude(const Target* from_target, | 83 bool CheckInclude(const Target* from_target, |
81 const InputFile& source_file, | 84 const InputFile& source_file, |
82 const SourceFile& include_file, | 85 const SourceFile& include_file, |
83 const LocationRange& range, | 86 const LocationRange& range, |
84 Err* err) const; | 87 Err* err) const; |
85 | 88 |
86 // Returns true if the given search_for target is a dependency of | 89 // Returns true if the given search_for target is a dependency of |
87 // search_from. Many subtrees are duplicated so this function avoids | 90 // search_from. |
88 // duplicate checking across recursive calls by keeping track of checked | |
89 // targets in the given set. It should point to an empty set for the first | |
90 // call. A target is not considered to be a dependency of itself. | |
91 // | 91 // |
92 // If found, the vector given in "chain" will be filled with the reverse | 92 // If found, the vector given in "chain" will be filled with the reverse |
93 // dependency chain from the dest target (chain[0] = search_for) to the src | 93 // dependency chain from the dest target (chain[0] = search_for) to the src |
94 // target (chain[chain.size() - 1] = search_from). | 94 // target (chain[chain.size() - 1] = search_from). |
| 95 // |
| 96 // If prefer_direct_dependent_configs is true, chains which forward direct |
| 97 // dependent configs will be considered first, and a chain which does not |
| 98 // will be returned only if no such chain exists. |
| 99 // |
| 100 // If direct_dependent_configs_apply is non-null, it will be set to true |
| 101 // if the chain was found during a search that requires forwarding direct |
| 102 // dependent configs, and false if it was found during a search of the |
| 103 // entire dependency graph. |
95 bool IsDependencyOf(const Target* search_for, | 104 bool IsDependencyOf(const Target* search_for, |
96 const Target* search_from, | 105 const Target* search_from, |
97 std::vector<const Target*>* chain) const; | 106 bool prefer_direct_dependent_configs, |
| 107 std::vector<const Target*>* chain, |
| 108 bool* direct_dependent_configs_apply) const; |
| 109 |
| 110 // For internal use by the previous override of IsDependencyOf. |
| 111 // If requires_dependent_configs is true, only chains which forward |
| 112 // direct dependent configs are considered. |
98 bool IsDependencyOf(const Target* search_for, | 113 bool IsDependencyOf(const Target* search_for, |
99 const Target* search_from, | 114 const Target* search_from, |
100 std::vector<const Target*>* chain, | 115 bool requires_dependent_configs, |
101 std::set<const Target*>* checked) const; | 116 std::vector<const Target*>* chain) const; |
102 | 117 |
103 // Given a reverse dependency chain (chain[0] is the lower-level target, | 118 // Given a reverse dependency chain (chain[0] is the lower-level target, |
104 // chain[end] is the higher-level target), determines if all direct dependent | 119 // chain[end] is the higher-level target) which does not forward direct |
105 // configs on the lower-level target would apply to the higher-level one. | 120 // dependent configs, determines the index of the target that caused the |
106 // | 121 // config to not apply. |
107 // If configs do not apply, this function returns false and indicates the | 122 static size_t GetDependentConfigChainProblemIndex( |
108 // index of the target that caused the config to not apply by putting it in | 123 const std::vector<const Target*>& chain); |
109 // problematic_index. | |
110 static bool DoDirectDependentConfigsApply( | |
111 const std::vector<const Target*>& chain, | |
112 size_t* problematic_index); | |
113 | 124 |
114 // Non-locked variables ------------------------------------------------------ | 125 // Non-locked variables ------------------------------------------------------ |
115 // | 126 // |
116 // These are initialized during construction (which happens on one thread) | 127 // These are initialized during construction (which happens on one thread) |
117 // and are not modified after, so any thread can read these without locking. | 128 // and are not modified after, so any thread can read these without locking. |
118 | 129 |
119 base::MessageLoop* main_loop_; | 130 base::MessageLoop* main_loop_; |
120 base::RunLoop main_thread_runner_; | 131 base::RunLoop main_thread_runner_; |
121 | 132 |
122 const BuildSettings* build_settings_; | 133 const BuildSettings* build_settings_; |
123 | 134 |
124 // Maps source files to targets it appears in (usually just one target). | 135 // Maps source files to targets it appears in (usually just one target). |
125 typedef std::map<SourceFile, TargetVector> FileMap; | 136 typedef std::map<SourceFile, TargetVector> FileMap; |
126 FileMap file_map_; | 137 FileMap file_map_; |
127 | 138 |
128 // Locked variables ---------------------------------------------------------- | 139 // Locked variables ---------------------------------------------------------- |
129 // | 140 // |
130 // These are mutable during runtime and require locking. | 141 // These are mutable during runtime and require locking. |
131 | 142 |
132 base::Lock lock_; | 143 base::Lock lock_; |
133 | 144 |
134 std::vector<Err> errors_; | 145 std::vector<Err> errors_; |
135 | 146 |
136 DISALLOW_COPY_AND_ASSIGN(HeaderChecker); | 147 DISALLOW_COPY_AND_ASSIGN(HeaderChecker); |
137 }; | 148 }; |
138 | 149 |
139 #endif // TOOLS_GN_HEADER_CHECKER_H_ | 150 #endif // TOOLS_GN_HEADER_CHECKER_H_ |
OLD | NEW |