Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: tools/gn/header_checker.h

Issue 584683002: Improve GN header checker, make //ui pass. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the adnoid Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 class LocationRange; 23 class LocationRange;
24 class SourceFile; 24 class SourceFile;
25 class Target; 25 class Target;
26 26
27 namespace base { 27 namespace base {
28 class MessageLoop; 28 class MessageLoop;
29 } 29 }
30 30
31 class HeaderChecker : public base::RefCountedThreadSafe<HeaderChecker> { 31 class HeaderChecker : public base::RefCountedThreadSafe<HeaderChecker> {
32 public: 32 public:
33 // Represents a dependency chain.
34 struct ChainLink {
35 ChainLink() : target(NULL), is_public(false) {}
36 ChainLink(const Target* t, bool p) : target(t), is_public(p) {}
37
38 const Target* target;
39
40 // True when the dependency on this target is public.
41 bool is_public;
scottmg 2014/09/18 22:33:52 should this be is_permitted too? i'm a little conf
42
43 // Used for testing.
44 bool operator==(const ChainLink& other) const {
45 return target == other.target && is_public == other.is_public;
46 }
47 };
48 typedef std::vector<ChainLink> Chain;
49
33 HeaderChecker(const BuildSettings* build_settings, 50 HeaderChecker(const BuildSettings* build_settings,
34 const std::vector<const Target*>& targets); 51 const std::vector<const Target*>& targets);
35 52
36 // Runs the check. The targets in to_check will be checked. If this list is 53 // Runs the check. The targets in to_check will be checked. If this list is
37 // empty, all targets will be checked. 54 // empty, all targets will be checked.
38 // 55 //
39 // This assumes that the current thread already has a message loop. On 56 // This assumes that the current thread already has a message loop. On
40 // error, fills the given vector with the errors and returns false. Returns 57 // error, fills the given vector with the errors and returns false. Returns
41 // true on success. 58 // true on success.
42 // 59 //
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 const LocationRange& range, 125 const LocationRange& range,
109 Err* err) const; 126 Err* err) const;
110 127
111 // Returns true if the given search_for target is a dependency of 128 // Returns true if the given search_for target is a dependency of
112 // search_from. 129 // search_from.
113 // 130 //
114 // If found, the vector given in "chain" will be filled with the reverse 131 // If found, the vector given in "chain" will be filled with the reverse
115 // dependency chain from the dest target (chain[0] = search_for) to the src 132 // dependency chain from the dest target (chain[0] = search_for) to the src
116 // target (chain[chain.size() - 1] = search_from). 133 // target (chain[chain.size() - 1] = search_from).
117 // 134 //
118 // Chains with public dependencies will be considered first. If a public 135 // Chains with permitted dependencies will be considered first. If a
119 // match is found, *is_public will be set to true. A chain with non-public 136 // permitted match is found, *is_permitted will be set to true. A chain with
120 // dependencies will only be considered if there are no public chains. In 137 // indirect, non-public dependencies will only be considered if there are no
121 // this case, *is_public will be false. 138 // public or direct chains. In this case, *is_permitted will be false.
139 //
140 // A permitted dependency is a sequence of public dependencies. The first
141 // one may be private, since a direct dependency always allows headers to be
142 // included.
122 bool IsDependencyOf(const Target* search_for, 143 bool IsDependencyOf(const Target* search_for,
123 const Target* search_from, 144 const Target* search_from,
124 std::vector<const Target*>* chain, 145 Chain* chain,
125 bool* is_public) const; 146 bool* is_permitted) const;
126 147
127 // For internal use by the previous override of IsDependencyOf. If 148 // For internal use by the previous override of IsDependencyOf. If
128 // require_public is true, only public dependency chains are searched. 149 // require_public is true, only public dependency chains are searched.
129 bool IsDependencyOf(const Target* search_for, 150 bool IsDependencyOf(const Target* search_for,
130 const Target* search_from, 151 const Target* search_from,
131 bool require_public, 152 bool require_permitted,
132 std::vector<const Target*>* chain) const; 153 Chain* chain) const;
133 154
134 // Non-locked variables ------------------------------------------------------ 155 // Non-locked variables ------------------------------------------------------
135 // 156 //
136 // These are initialized during construction (which happens on one thread) 157 // These are initialized during construction (which happens on one thread)
137 // and are not modified after, so any thread can read these without locking. 158 // and are not modified after, so any thread can read these without locking.
138 159
139 base::MessageLoop* main_loop_; 160 base::MessageLoop* main_loop_;
140 base::RunLoop main_thread_runner_; 161 base::RunLoop main_thread_runner_;
141 162
142 const BuildSettings* build_settings_; 163 const BuildSettings* build_settings_;
143 164
144 // Maps source files to targets it appears in (usually just one target). 165 // Maps source files to targets it appears in (usually just one target).
145 FileMap file_map_; 166 FileMap file_map_;
146 167
147 // Locked variables ---------------------------------------------------------- 168 // Locked variables ----------------------------------------------------------
148 // 169 //
149 // These are mutable during runtime and require locking. 170 // These are mutable during runtime and require locking.
150 171
151 base::Lock lock_; 172 base::Lock lock_;
152 173
153 std::vector<Err> errors_; 174 std::vector<Err> errors_;
154 175
155 DISALLOW_COPY_AND_ASSIGN(HeaderChecker); 176 DISALLOW_COPY_AND_ASSIGN(HeaderChecker);
156 }; 177 };
157 178
158 #endif // TOOLS_GN_HEADER_CHECKER_H_ 179 #endif // TOOLS_GN_HEADER_CHECKER_H_
OLDNEW
« no previous file with comments | « sync/BUILD.gn ('k') | tools/gn/header_checker.cc » ('j') | tools/gn/header_checker_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698