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

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: merge 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
« no previous file with comments | « sync/BUILD.gn ('k') | tools/gn/header_checker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
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 //
43 // force_check, if true, will override targets opting out of header checking 60 // force_check, if true, will override targets opting out of header checking
44 // with "check_includes = false" and will check them anyway. 61 // with "check_includes = false" and will check them anyway.
45 bool Run(const std::vector<const Target*>& to_check, 62 bool Run(const std::vector<const Target*>& to_check,
46 bool force_check, 63 bool force_check,
47 std::vector<Err>* errors); 64 std::vector<Err>* errors);
48 65
49 private: 66 private:
50 friend class base::RefCountedThreadSafe<HeaderChecker>; 67 friend class base::RefCountedThreadSafe<HeaderChecker>;
51 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, IsDependencyOf); 68 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, IsDependencyOf);
52 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest,
53 IsDependencyOf_ForwardsDirectDependentConfigs);
54 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, CheckInclude); 69 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, CheckInclude);
70 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, PublicFirst);
55 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, CheckIncludeAllowCircular); 71 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, CheckIncludeAllowCircular);
56 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest,
57 GetDependentConfigChainProblemIndex);
58 ~HeaderChecker(); 72 ~HeaderChecker();
59 73
60 struct TargetInfo { 74 struct TargetInfo {
61 TargetInfo() : target(NULL), is_public(false), is_generated(false) {} 75 TargetInfo() : target(NULL), is_public(false), is_generated(false) {}
62 TargetInfo(const Target* t, bool is_pub, bool is_gen) 76 TargetInfo(const Target* t, bool is_pub, bool is_gen)
63 : target(t), 77 : target(t),
64 is_public(is_pub), 78 is_public(is_pub),
65 is_generated(is_gen) { 79 is_generated(is_gen) {
66 } 80 }
67 81
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 const LocationRange& range, 122 const LocationRange& range,
109 Err* err) const; 123 Err* err) const;
110 124
111 // Returns true if the given search_for target is a dependency of 125 // Returns true if the given search_for target is a dependency of
112 // search_from. 126 // search_from.
113 // 127 //
114 // If found, the vector given in "chain" will be filled with the reverse 128 // 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 129 // dependency chain from the dest target (chain[0] = search_for) to the src
116 // target (chain[chain.size() - 1] = search_from). 130 // target (chain[chain.size() - 1] = search_from).
117 // 131 //
118 // Chains with public dependencies will be considered first. If a public 132 // 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 133 // 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 134 // indirect, non-public dependencies will only be considered if there are no
121 // this case, *is_public will be false. 135 // public or direct chains. In this case, *is_permitted will be false.
136 //
137 // A permitted dependency is a sequence of public dependencies. The first
138 // one may be private, since a direct dependency always allows headers to be
139 // included.
122 bool IsDependencyOf(const Target* search_for, 140 bool IsDependencyOf(const Target* search_for,
123 const Target* search_from, 141 const Target* search_from,
124 std::vector<const Target*>* chain, 142 Chain* chain,
125 bool* is_public) const; 143 bool* is_permitted) const;
126 144
127 // For internal use by the previous override of IsDependencyOf. If 145 // For internal use by the previous override of IsDependencyOf. If
128 // require_public is true, only public dependency chains are searched. 146 // require_public is true, only public dependency chains are searched.
129 bool IsDependencyOf(const Target* search_for, 147 bool IsDependencyOf(const Target* search_for,
130 const Target* search_from, 148 const Target* search_from,
131 bool require_public, 149 bool require_permitted,
132 std::vector<const Target*>* chain) const; 150 Chain* chain) const;
133 151
134 // Non-locked variables ------------------------------------------------------ 152 // Non-locked variables ------------------------------------------------------
135 // 153 //
136 // These are initialized during construction (which happens on one thread) 154 // These are initialized during construction (which happens on one thread)
137 // and are not modified after, so any thread can read these without locking. 155 // and are not modified after, so any thread can read these without locking.
138 156
139 base::MessageLoop* main_loop_; 157 base::MessageLoop* main_loop_;
140 base::RunLoop main_thread_runner_; 158 base::RunLoop main_thread_runner_;
141 159
142 const BuildSettings* build_settings_; 160 const BuildSettings* build_settings_;
143 161
144 // Maps source files to targets it appears in (usually just one target). 162 // Maps source files to targets it appears in (usually just one target).
145 FileMap file_map_; 163 FileMap file_map_;
146 164
147 // Locked variables ---------------------------------------------------------- 165 // Locked variables ----------------------------------------------------------
148 // 166 //
149 // These are mutable during runtime and require locking. 167 // These are mutable during runtime and require locking.
150 168
151 base::Lock lock_; 169 base::Lock lock_;
152 170
153 std::vector<Err> errors_; 171 std::vector<Err> errors_;
154 172
155 DISALLOW_COPY_AND_ASSIGN(HeaderChecker); 173 DISALLOW_COPY_AND_ASSIGN(HeaderChecker);
156 }; 174 };
157 175
158 #endif // TOOLS_GN_HEADER_CHECKER_H_ 176 #endif // TOOLS_GN_HEADER_CHECKER_H_
OLDNEW
« no previous file with comments | « sync/BUILD.gn ('k') | tools/gn/header_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698