Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
|
brettw
2016/08/25 21:22:30
No (c)
Dirk Pranke
2016/08/26 00:34:14
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef TOOLS_GN_ANALYZER_H_ | |
| 6 #define TOOLS_GN_ANALYZER_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "tools/gn/builder.h" | |
| 13 #include "tools/gn/label.h" | |
| 14 #include "tools/gn/source_file.h" | |
| 15 #include "tools/gn/target.h" | |
| 16 | |
| 17 // An Analyzer can answer questions about a build graph. It is used | |
| 18 // to answer queries for the `refs` and `analyze` commands, where we | |
| 19 // need to look at the graph in ways that can't easily be determined | |
| 20 // from just a single Target. | |
| 21 class Analyzer { | |
| 22 public: | |
| 23 using LabelSet = std::set<Label>; | |
| 24 using SourceFileSet = std::set<const SourceFile*>; | |
| 25 using TargetSet = std::set<const Target*>; | |
| 26 | |
| 27 Analyzer(const Builder& builder); | |
|
brettw
2016/08/25 21:22:30
Prepend "explicit" since this is a one-arg constru
Dirk Pranke
2016/08/26 00:34:13
Done.
| |
| 28 ~Analyzer(); | |
| 29 | |
| 30 // Figures out from a Buider and a JSON-formatted string containing lists | |
| 31 // of files and targets, which targets would be affected by modifications | |
| 32 // to the files . See the help text for the analyze command (kAnalyze_Help) | |
| 33 // for the specification of the input and output string formats and the | |
| 34 // expected behavior of the method. | |
| 35 std::string Analyze(const std::string& input, Err* err); | |
|
brettw
2016/08/25 21:22:30
I don't see any caching in this object any more, s
Dirk Pranke
2016/08/26 00:34:13
Yup, I got rid it (or, rather, pushed it into the
| |
| 36 | |
| 37 private: | |
| 38 using DepMap = std::multimap<const Target*, const Target*>; | |
| 39 | |
| 40 // Returns the roots of the build graph: the set of targets that | |
| 41 // no other target depends on. | |
| 42 TargetSet& roots() { return roots_; }; | |
| 43 | |
| 44 // Returns the set of all targets that might be affected, directly or | |
| 45 // indirectly, by modifications to the given source files. | |
| 46 TargetSet AllAffectedTargets(const SourceFileSet& source_files); | |
| 47 | |
| 48 // Returns the set of labels that do not refer to objects in the graph. | |
| 49 LabelSet InvalidLabels(const LabelSet& labels); | |
| 50 | |
| 51 // Returns the set of all targets that have a label in the given set. | |
| 52 // Invalid (or missing) labels will be ignored. | |
| 53 TargetSet TargetsFor(const LabelSet& labels); | |
| 54 | |
| 55 // Returns a filtered set of the given targets, meaning that for each of the | |
| 56 // given targets, | |
| 57 // - if the target is not a group, add it to the set | |
| 58 // - if the target is a group, recursively filter each dependency and add | |
| 59 // its filtered results to the set. | |
| 60 // | |
| 61 // For example, if we had: | |
| 62 // | |
| 63 // group("foobar") { deps = [ ":foo", ":bar" ] } | |
| 64 // group("bar") { deps = [ ":baz", ":quux" ] } | |
| 65 // executable("foo") { ... } | |
| 66 // executable("baz") { ... } | |
| 67 // executable("quux") { ... } | |
| 68 // | |
| 69 // Then the filtered version of {"foobar"} would be {":foo", ":baz", | |
| 70 // ":quux"}. This is used by the analyze command in order to only build | |
| 71 // the affected dependencies of a group (and not also build the unaffected | |
| 72 // ones). | |
| 73 // | |
| 74 // This filtering behavior is also known as "pruning" the list of targets. | |
| 75 TargetSet Filter(const TargetSet& targets); | |
|
brettw
2016/08/25 21:22:30
Would "CollapseGroups" or "FlattenGroups" be a bet
Dirk Pranke
2016/08/26 00:34:13
No, I don't think those are better. If the concern
| |
| 76 | |
| 77 // Filter an individual target and adds the results to filtered | |
| 78 // (see Filter(), above). | |
| 79 void FilterTarget(const Target*, TargetSet* seen, TargetSet* filtered); | |
| 80 | |
| 81 bool TargetRefersToFile(const Target* target, const SourceFile* file); | |
| 82 | |
| 83 void AddTargetsDirectlyReferringToFileTo(const SourceFile* file, | |
| 84 TargetSet* matches); | |
| 85 | |
| 86 void AddAllRefsTo(const Target* target, TargetSet* matches); | |
| 87 | |
| 88 std::vector<const Target*> all_targets_; | |
| 89 std::map<const Label, const Target*> labels_to_targets_; | |
| 90 Label default_toolchain_; | |
| 91 std::set<const Target*> roots_; | |
| 92 | |
| 93 // Maps targets to the list of targets that depend on them. | |
| 94 DepMap dep_map_; | |
| 95 }; | |
| 96 | |
| 97 #endif // TOOLS_GN_ANALYZER_H_ | |
| OLD | NEW |