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

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

Issue 500423003: Enhance GN diagnostic tools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use patterns for gn check 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 | « tools/gn/gn.gyp ('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 15 matching lines...) Expand all
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 HeaderChecker(const BuildSettings* build_settings, 33 HeaderChecker(const BuildSettings* build_settings,
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 // Runs the check. The targets in to_check will be checked. If this list is
37 // error, fills the given vector with the errors and returns false. Returns 37 // empty, all targets will be checked.
38 //
39 // 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
38 // true on success. 41 // true on success.
39 bool Run(std::vector<Err>* errors); 42 bool Run(const std::vector<const Target*>& to_check,
43 std::vector<Err>* errors);
40 44
41 private: 45 private:
42 friend class base::RefCountedThreadSafe<HeaderChecker>; 46 friend class base::RefCountedThreadSafe<HeaderChecker>;
43 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, IsDependencyOf); 47 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, IsDependencyOf);
44 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, 48 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest,
45 IsDependencyOf_ForwardsDirectDependentConfigs); 49 IsDependencyOf_ForwardsDirectDependentConfigs);
46 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, CheckInclude); 50 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, CheckInclude);
47 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest, 51 FRIEND_TEST_ALL_PREFIXES(HeaderCheckerTest,
48 GetDependentConfigChainProblemIndex); 52 GetDependentConfigChainProblemIndex);
49 ~HeaderChecker(); 53 ~HeaderChecker();
50 54
51 struct TargetInfo { 55 struct TargetInfo {
52 TargetInfo() : target(NULL), is_public(false) {} 56 TargetInfo() : target(NULL), is_public(false) {}
53 TargetInfo(const Target* t, bool p) : target(t), is_public(p) {} 57 TargetInfo(const Target* t, bool p) : target(t), is_public(p) {}
54 58
55 const Target* target; 59 const Target* target;
56 bool is_public; 60 bool is_public;
57 }; 61 };
58 62
59 typedef std::vector<TargetInfo> TargetVector; 63 typedef std::vector<TargetInfo> TargetVector;
64 typedef std::map<SourceFile, TargetVector> FileMap;
65
66 // Backend for Run() that takes the list of files to check. The errors_ list
67 // will be populate on failure.
68 void RunCheckOverFiles(const FileMap& flies);
60 69
61 void DoWork(const Target* target, const SourceFile& file); 70 void DoWork(const Target* target, const SourceFile& file);
62 71
63 // Adds the sources and public files from the given target to the file_map_. 72 // Adds the sources and public files from the given target to the given map.
64 // Not threadsafe! Called only during init. 73 static void AddTargetToFileMap(const Target* target, FileMap* dest);
65 void AddTargetToFileMap(const Target* target);
66 74
67 // Returns true if the given file is in the output directory. 75 // Returns true if the given file is in the output directory.
68 bool IsFileInOuputDir(const SourceFile& file) const; 76 bool IsFileInOuputDir(const SourceFile& file) const;
69 77
70 // Resolves the contents of an include to a SourceFile. 78 // Resolves the contents of an include to a SourceFile.
71 SourceFile SourceFileForInclude(const base::StringPiece& input) const; 79 SourceFile SourceFileForInclude(const base::StringPiece& input) const;
72 80
73 // from_target is the target the file was defined from. It will be used in 81 // from_target is the target the file was defined from. It will be used in
74 // error messages. 82 // error messages.
75 bool CheckFile(const Target* from_target, 83 bool CheckFile(const Target* from_target,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // 134 //
127 // These are initialized during construction (which happens on one thread) 135 // These are initialized during construction (which happens on one thread)
128 // and are not modified after, so any thread can read these without locking. 136 // and are not modified after, so any thread can read these without locking.
129 137
130 base::MessageLoop* main_loop_; 138 base::MessageLoop* main_loop_;
131 base::RunLoop main_thread_runner_; 139 base::RunLoop main_thread_runner_;
132 140
133 const BuildSettings* build_settings_; 141 const BuildSettings* build_settings_;
134 142
135 // Maps source files to targets it appears in (usually just one target). 143 // Maps source files to targets it appears in (usually just one target).
136 typedef std::map<SourceFile, TargetVector> FileMap;
137 FileMap file_map_; 144 FileMap file_map_;
138 145
139 // Locked variables ---------------------------------------------------------- 146 // Locked variables ----------------------------------------------------------
140 // 147 //
141 // These are mutable during runtime and require locking. 148 // These are mutable during runtime and require locking.
142 149
143 base::Lock lock_; 150 base::Lock lock_;
144 151
145 std::vector<Err> errors_; 152 std::vector<Err> errors_;
146 153
147 DISALLOW_COPY_AND_ASSIGN(HeaderChecker); 154 DISALLOW_COPY_AND_ASSIGN(HeaderChecker);
148 }; 155 };
149 156
150 #endif // TOOLS_GN_HEADER_CHECKER_H_ 157 #endif // TOOLS_GN_HEADER_CHECKER_H_
OLDNEW
« no previous file with comments | « tools/gn/gn.gyp ('k') | tools/gn/header_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698