OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_BUILDER_H_ | 5 #ifndef TOOLS_GN_BUILDER_H_ |
6 #define TOOLS_GN_BUILDER_H_ | 6 #define TOOLS_GN_BUILDER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "tools/gn/builder_record.h" | 12 #include "tools/gn/builder_record.h" |
13 #include "tools/gn/label.h" | 13 #include "tools/gn/label.h" |
14 #include "tools/gn/label_ptr.h" | 14 #include "tools/gn/label_ptr.h" |
| 15 #include "tools/gn/unique_vector.h" |
15 | 16 |
16 class Config; | 17 class Config; |
17 class Err; | 18 class Err; |
18 class Loader; | 19 class Loader; |
19 class ParseNode; | 20 class ParseNode; |
20 | 21 |
21 class Builder : public base::RefCountedThreadSafe<Builder> { | 22 class Builder : public base::RefCountedThreadSafe<Builder> { |
22 public: | 23 public: |
23 typedef base::Callback<void(const BuilderRecord*)> ResolvedCallback; | 24 typedef base::Callback<void(const BuilderRecord*)> ResolvedCallback; |
24 | 25 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // will be set. request_from is used as the source of the error. | 78 // will be set. request_from is used as the source of the error. |
78 BuilderRecord* GetResolvedRecordOfType(const Label& label, | 79 BuilderRecord* GetResolvedRecordOfType(const Label& label, |
79 const ParseNode* request_from, | 80 const ParseNode* request_from, |
80 BuilderRecord::ItemType type, | 81 BuilderRecord::ItemType type, |
81 Err* err); | 82 Err* err); |
82 | 83 |
83 bool AddDeps(BuilderRecord* record, | 84 bool AddDeps(BuilderRecord* record, |
84 const LabelConfigVector& configs, | 85 const LabelConfigVector& configs, |
85 Err* err); | 86 Err* err); |
86 bool AddDeps(BuilderRecord* record, | 87 bool AddDeps(BuilderRecord* record, |
| 88 const UniqueVector<LabelConfigPair>& configs, |
| 89 Err* err); |
| 90 bool AddDeps(BuilderRecord* record, |
87 const LabelTargetVector& targets, | 91 const LabelTargetVector& targets, |
88 Err* err); | 92 Err* err); |
89 bool AddToolchainDep(BuilderRecord* record, | 93 bool AddToolchainDep(BuilderRecord* record, |
90 const Target* target, | 94 const Target* target, |
91 Err* err); | 95 Err* err); |
92 | 96 |
93 // Given a target, sets the "should generate" bit and pushes it through the | 97 // Given a target, sets the "should generate" bit and pushes it through the |
94 // dependency tree. Any time the bit it set, we ensure that the given item is | 98 // dependency tree. Any time the bit it set, we ensure that the given item is |
95 // scheduled to be loaded. | 99 // scheduled to be loaded. |
96 // | 100 // |
97 // If the force flag is set, we'll ignore the current state of the record's | 101 // If the force flag is set, we'll ignore the current state of the record's |
98 // should_generate flag, and set it on the dependents every time. This is | 102 // should_generate flag, and set it on the dependents every time. This is |
99 // used when defining a target: the "should generate" may have been set | 103 // used when defining a target: the "should generate" may have been set |
100 // before the item was defined (if it is required by something that is | 104 // before the item was defined (if it is required by something that is |
101 // required). In this case, we need to re-push the "should generate" flag | 105 // required). In this case, we need to re-push the "should generate" flag |
102 // to the item's dependencies. | 106 // to the item's dependencies. |
103 void RecursiveSetShouldGenerate(BuilderRecord* record, bool force); | 107 void RecursiveSetShouldGenerate(BuilderRecord* record, bool force); |
104 | 108 |
105 void ScheduleItemLoadIfNecessary(BuilderRecord* record); | 109 void ScheduleItemLoadIfNecessary(BuilderRecord* record); |
106 | 110 |
107 // This takes a BuilderRecord with resolved depdencies, and fills in the | 111 // This takes a BuilderRecord with resolved depdencies, and fills in the |
108 // target's Label*Vectors with the resolved pointers. | 112 // target's Label*Vectors with the resolved pointers. |
109 bool ResolveItem(BuilderRecord* record, Err* err); | 113 bool ResolveItem(BuilderRecord* record, Err* err); |
110 | 114 |
111 // Fills in the pointers in the given vector based on the labels. We assume | 115 // Fills in the pointers in the given vector based on the labels. We assume |
112 // that everything should be resolved by this point, so will return an error | 116 // that everything should be resolved by this point, so will return an error |
113 // if anything isn't found or if the type doesn't match. | 117 // if anything isn't found or if the type doesn't match. |
114 bool ResolveDeps(LabelTargetVector* deps, Err* err); | 118 bool ResolveDeps(LabelTargetVector* deps, Err* err); |
115 bool ResolveConfigs(LabelConfigVector* configs, Err* err); | 119 bool ResolveConfigs(UniqueVector<LabelConfigPair>* configs, Err* err); |
116 bool ResolveForwardDependentConfigs(Target* target, Err* err); | 120 bool ResolveForwardDependentConfigs(Target* target, Err* err); |
117 | 121 |
118 // Given a list of unresolved records, tries to find any circular | 122 // Given a list of unresolved records, tries to find any circular |
119 // dependencies and returns the string describing the problem. If no circular | 123 // dependencies and returns the string describing the problem. If no circular |
120 // deps were found, returns the empty string. | 124 // deps were found, returns the empty string. |
121 std::string CheckForCircularDependencies( | 125 std::string CheckForCircularDependencies( |
122 const std::vector<const BuilderRecord*>& bad_records) const; | 126 const std::vector<const BuilderRecord*>& bad_records) const; |
123 | 127 |
124 // Non owning pointer. | 128 // Non owning pointer. |
125 Loader* loader_; | 129 Loader* loader_; |
126 | 130 |
127 // Owning pointers. | 131 // Owning pointers. |
128 typedef base::hash_map<Label, BuilderRecord*> RecordMap; | 132 typedef base::hash_map<Label, BuilderRecord*> RecordMap; |
129 RecordMap records_; | 133 RecordMap records_; |
130 | 134 |
131 ResolvedCallback resolved_callback_; | 135 ResolvedCallback resolved_callback_; |
132 | 136 |
133 DISALLOW_COPY_AND_ASSIGN(Builder); | 137 DISALLOW_COPY_AND_ASSIGN(Builder); |
134 }; | 138 }; |
135 | 139 |
136 #endif // TOOLS_GN_BUILDER_H_ | 140 #endif // TOOLS_GN_BUILDER_H_ |
OLD | NEW |