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

Side by Side Diff: tools/gn/target.cc

Issue 48523006: GN: Separately track labels and origins for lists of stuff (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « tools/gn/target.h ('k') | tools/gn/target_generator.h » ('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 (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 #include "tools/gn/target.h" 5 #include "tools/gn/target.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "tools/gn/config_values_extractors.h" 8 #include "tools/gn/config_values_extractors.h"
9 #include "tools/gn/scheduler.h" 9 #include "tools/gn/scheduler.h"
10 10
11 namespace { 11 namespace {
12 12
13 typedef std::set<const Config*> ConfigSet; 13 typedef std::set<const Config*> ConfigSet;
14 14
15 void TargetResolvedThunk(const base::Callback<void(const Target*)>& cb, 15 void TargetResolvedThunk(const base::Callback<void(const Target*)>& cb,
16 const Target* t) { 16 const Target* t) {
17 cb.Run(t); 17 cb.Run(t);
18 } 18 }
19 19
20 // Merges the dependent configs from the given target to the given config list. 20 // Merges the dependent configs from the given target to the given config list.
21 // The unique_configs list is used for de-duping so values already added will 21 // The unique_configs list is used for de-duping so values already added will
22 // not be added again. 22 // not be added again.
23 void MergeDirectDependentConfigsFrom(const Target* from_target, 23 void MergeDirectDependentConfigsFrom(const Target* from_target,
24 ConfigSet* unique_configs, 24 ConfigSet* unique_configs,
25 std::vector<const Config*>* dest) { 25 LabelConfigVector* dest) {
26 const std::vector<const Config*>& direct = 26 const LabelConfigVector& direct = from_target->direct_dependent_configs();
27 from_target->direct_dependent_configs();
28 for (size_t i = 0; i < direct.size(); i++) { 27 for (size_t i = 0; i < direct.size(); i++) {
29 if (unique_configs->find(direct[i]) == unique_configs->end()) { 28 if (unique_configs->find(direct[i].ptr) == unique_configs->end()) {
30 unique_configs->insert(direct[i]); 29 unique_configs->insert(direct[i].ptr);
31 dest->push_back(direct[i]); 30 dest->push_back(direct[i]);
32 } 31 }
33 } 32 }
34 } 33 }
35 34
36 // Like MergeDirectDependentConfigsFrom above except does the "all dependent" 35 // Like MergeDirectDependentConfigsFrom above except does the "all dependent"
37 // ones. This additionally adds all configs to the all_dependent_configs_ of 36 // ones. This additionally adds all configs to the all_dependent_configs_ of
38 // the dest target given in *all_dest. 37 // the dest target given in *all_dest.
39 void MergeAllDependentConfigsFrom(const Target* from_target, 38 void MergeAllDependentConfigsFrom(const Target* from_target,
40 ConfigSet* unique_configs, 39 ConfigSet* unique_configs,
41 std::vector<const Config*>* dest, 40 LabelConfigVector* dest,
42 std::vector<const Config*>* all_dest) { 41 LabelConfigVector* all_dest) {
43 const std::vector<const Config*>& all = 42 const LabelConfigVector& all = from_target->all_dependent_configs();
44 from_target->all_dependent_configs();
45 for (size_t i = 0; i < all.size(); i++) { 43 for (size_t i = 0; i < all.size(); i++) {
46 // Always add it to all_dependent_configs_ since it might not be in that 44 // Always add it to all_dependent_configs_ since it might not be in that
47 // list even if we've seen it applied to this target before. This may 45 // list even if we've seen it applied to this target before. This may
48 // introduce some duplicates in all_dependent_configs_, but those will 46 // introduce some duplicates in all_dependent_configs_, but those will
49 // we removed when they're actually applied to a target. 47 // we removed when they're actually applied to a target.
50 all_dest->push_back(all[i]); 48 all_dest->push_back(all[i]);
51 if (unique_configs->find(all[i]) == unique_configs->end()) { 49 if (unique_configs->find(all[i].ptr) == unique_configs->end()) {
52 // One we haven't seen yet, also apply it to ourselves. 50 // One we haven't seen yet, also apply it to ourselves.
53 dest->push_back(all[i]); 51 dest->push_back(all[i]);
54 unique_configs->insert(all[i]); 52 unique_configs->insert(all[i].ptr);
55 } 53 }
56 } 54 }
57 } 55 }
58 56
59 } // namespace 57 } // namespace
60 58
61 Target::Target(const Settings* settings, const Label& label) 59 Target::Target(const Settings* settings, const Label& label)
62 : Item(label), 60 : Item(label),
63 settings_(settings), 61 settings_(settings),
64 output_type_(UNKNOWN), 62 output_type_(UNKNOWN),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 101
104 void Target::OnResolved() { 102 void Target::OnResolved() {
105 DCHECK(output_type_ != UNKNOWN); 103 DCHECK(output_type_ != UNKNOWN);
106 104
107 // Convert any groups we depend on to just direct dependencies on that 105 // Convert any groups we depend on to just direct dependencies on that
108 // group's deps. We insert the new deps immediately after the group so that 106 // group's deps. We insert the new deps immediately after the group so that
109 // the ordering is preserved. We need to keep the original group so that any 107 // the ordering is preserved. We need to keep the original group so that any
110 // flags, etc. that it specifies itself are applied to us. 108 // flags, etc. that it specifies itself are applied to us.
111 size_t original_deps_size = deps_.size(); 109 size_t original_deps_size = deps_.size();
112 for (size_t i = 0; i < original_deps_size; i++) { 110 for (size_t i = 0; i < original_deps_size; i++) {
113 const Target* dep = deps_[i]; 111 const Target* dep = deps_[i].ptr;
114 if (dep->output_type_ == GROUP) { 112 if (dep->output_type_ == GROUP) {
115 deps_.insert(deps_.begin() + i + 1, dep->deps_.begin(), dep->deps_.end()); 113 deps_.insert(deps_.begin() + i + 1, dep->deps_.begin(), dep->deps_.end());
116 i += dep->deps_.size(); 114 i += dep->deps_.size();
117 } 115 }
118 } 116 }
119 117
120 // Only add each config once. First remember the target's configs. 118 // Only add each config once. First remember the target's configs.
121 ConfigSet unique_configs; 119 ConfigSet unique_configs;
122 for (size_t i = 0; i < configs_.size(); i++) 120 for (size_t i = 0; i < configs_.size(); i++)
123 unique_configs.insert(configs_[i]); 121 unique_configs.insert(configs_[i].ptr);
124 122
125 // Copy our own dependent configs to the list of configs applying to us. 123 // Copy our own dependent configs to the list of configs applying to us.
126 for (size_t i = 0; i < all_dependent_configs_.size(); i++) { 124 for (size_t i = 0; i < all_dependent_configs_.size(); i++) {
127 const Config* cur = all_dependent_configs_[i]; 125 if (unique_configs.find(all_dependent_configs_[i].ptr) ==
128 if (unique_configs.find(cur) == unique_configs.end()) { 126 unique_configs.end()) {
129 unique_configs.insert(cur); 127 unique_configs.insert(all_dependent_configs_[i].ptr);
130 configs_.push_back(cur); 128 configs_.push_back(all_dependent_configs_[i]);
131 } 129 }
132 } 130 }
133 for (size_t i = 0; i < direct_dependent_configs_.size(); i++) { 131 for (size_t i = 0; i < direct_dependent_configs_.size(); i++) {
134 const Config* cur = direct_dependent_configs_[i]; 132 if (unique_configs.find(direct_dependent_configs_[i].ptr) ==
135 if (unique_configs.find(cur) == unique_configs.end()) { 133 unique_configs.end()) {
136 unique_configs.insert(cur); 134 unique_configs.insert(direct_dependent_configs_[i].ptr);
137 configs_.push_back(cur); 135 configs_.push_back(direct_dependent_configs_[i]);
138 } 136 }
139 } 137 }
140 138
141 // Copy our own libs and lib_dirs to the final set. This will be from our 139 // Copy our own libs and lib_dirs to the final set. This will be from our
142 // target and all of our configs. We do this specially since these must be 140 // target and all of our configs. We do this specially since these must be
143 // inherited through the dependency tree (other flags don't work this way). 141 // inherited through the dependency tree (other flags don't work this way).
144 for (ConfigValuesIterator iter(this); !iter.done(); iter.Next()) { 142 for (ConfigValuesIterator iter(this); !iter.done(); iter.Next()) {
145 const ConfigValues& cur = iter.cur(); 143 const ConfigValues& cur = iter.cur();
146 all_lib_dirs_.append(cur.lib_dirs().begin(), cur.lib_dirs().end()); 144 all_lib_dirs_.append(cur.lib_dirs().begin(), cur.lib_dirs().end());
147 all_libs_.append(cur.libs().begin(), cur.libs().end()); 145 all_libs_.append(cur.libs().begin(), cur.libs().end());
(...skipping 26 matching lines...) Expand all
174 generator_function_ = token; 172 generator_function_ = token;
175 } 173 }
176 174
177 bool Target::IsLinkable() const { 175 bool Target::IsLinkable() const {
178 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; 176 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY;
179 } 177 }
180 178
181 void Target::PullDependentTargetInfo(std::set<const Config*>* unique_configs) { 179 void Target::PullDependentTargetInfo(std::set<const Config*>* unique_configs) {
182 // Gather info from our dependents we need. 180 // Gather info from our dependents we need.
183 for (size_t dep_i = 0; dep_i < deps_.size(); dep_i++) { 181 for (size_t dep_i = 0; dep_i < deps_.size(); dep_i++) {
184 const Target* dep = deps_[dep_i]; 182 const Target* dep = deps_[dep_i].ptr;
185 MergeAllDependentConfigsFrom(dep, unique_configs, &configs_, 183 MergeAllDependentConfigsFrom(dep, unique_configs, &configs_,
186 &all_dependent_configs_); 184 &all_dependent_configs_);
187 MergeDirectDependentConfigsFrom(dep, unique_configs, &configs_); 185 MergeDirectDependentConfigsFrom(dep, unique_configs, &configs_);
188 186
189 // Direct dependent libraries. 187 // Direct dependent libraries.
190 if (dep->output_type() == STATIC_LIBRARY || 188 if (dep->output_type() == STATIC_LIBRARY ||
191 dep->output_type() == SHARED_LIBRARY || 189 dep->output_type() == SHARED_LIBRARY ||
192 dep->output_type() == SOURCE_SET) 190 dep->output_type() == SOURCE_SET)
193 inherited_libraries_.insert(dep); 191 inherited_libraries_.insert(dep);
194 192
(...skipping 10 matching lines...) Expand all
205 inherited_libraries_.insert(*i); 203 inherited_libraries_.insert(*i);
206 204
207 // Inherited library settings. 205 // Inherited library settings.
208 all_lib_dirs_.append(dep->all_lib_dirs()); 206 all_lib_dirs_.append(dep->all_lib_dirs());
209 all_libs_.append(dep->all_libs()); 207 all_libs_.append(dep->all_libs());
210 } 208 }
211 } 209 }
212 210
213 // Forward direct dependent configs if requested. 211 // Forward direct dependent configs if requested.
214 for (size_t dep = 0; dep < forward_dependent_configs_.size(); dep++) { 212 for (size_t dep = 0; dep < forward_dependent_configs_.size(); dep++) {
215 const Target* from_target = forward_dependent_configs_[dep]; 213 const Target* from_target = forward_dependent_configs_[dep].ptr;
216 214
217 // The forward_dependent_configs_ must be in the deps already, so we 215 // The forward_dependent_configs_ must be in the deps already, so we
218 // don't need to bother copying to our configs, only forwarding. 216 // don't need to bother copying to our configs, only forwarding.
219 DCHECK(std::find(deps_.begin(), deps_.end(), from_target) != 217 DCHECK(std::find_if(deps_.begin(), deps_.end(),
218 LabelPtrPtrEquals<Target>(from_target)) !=
220 deps_.end()); 219 deps_.end());
221 const std::vector<const Config*>& direct = 220 direct_dependent_configs_.insert(
222 from_target->direct_dependent_configs(); 221 direct_dependent_configs_.end(),
223 for (size_t i = 0; i < direct.size(); i++) 222 from_target->direct_dependent_configs().begin(),
224 direct_dependent_configs_.push_back(direct[i]); 223 from_target->direct_dependent_configs().end());
225 } 224 }
226 } 225 }
OLDNEW
« no previous file with comments | « tools/gn/target.h ('k') | tools/gn/target_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698