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 #include "tools/gn/ninja_target_writer.h" | 5 #include "tools/gn/ninja_target_writer.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 path_output_.WriteFile(out_, input); | 200 path_output_.WriteFile(out_, input); |
201 } | 201 } |
202 if (list_sources_as_input_deps) { | 202 if (list_sources_as_input_deps) { |
203 for (const auto& source : target_->sources()) { | 203 for (const auto& source : target_->sources()) { |
204 out_ << " "; | 204 out_ << " "; |
205 path_output_.WriteFile(out_, source); | 205 path_output_.WriteFile(out_, source); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 // The different souces of input deps may duplicate some targets, so uniquify | 209 // The different souces of input deps may duplicate some targets, so uniquify |
210 // them (ordering doesn't matter for this case). | 210 // them. Note that the order matters, or the output is non-deterministic. |
brettw
2015/12/10 21:29:46
Can you rephrase this comment, I feel like it's wo
| |
211 std::set<const Target*> unique_deps; | 211 std::vector<const Target*> sorted_deps; |
212 | 212 |
213 // Hard dependencies that are direct or indirect dependencies. | 213 // Hard dependencies that are direct or indirect dependencies. |
214 const std::set<const Target*>& hard_deps = target_->recursive_hard_deps(); | 214 const std::set<const Target*>& hard_deps(target_->recursive_hard_deps()); |
215 for (const auto& dep : hard_deps) | |
216 unique_deps.insert(dep); | |
217 | 215 |
218 // Extra hard dependencies passed in. | 216 // Extra hard dependencies passed in. |
219 unique_deps.insert(extra_hard_deps.begin(), extra_hard_deps.end()); | 217 for (const Target* target : extra_hard_deps) { |
M-A Ruel
2015/12/08 13:49:29
I think this comment should be added here, it's no
| |
218 if (!hard_deps.count(target)) { | |
brettw
2015/12/10 21:29:46
No {} for single line conditionals (for consistenc
| |
219 sorted_deps.push_back(target); | |
220 } | |
221 } | |
220 | 222 |
221 // Toolchain dependencies. These must be resolved before doing anything. | 223 // Toolchain dependencies. These must be resolved before doing anything. |
222 // This just writs all toolchain deps for simplicity. If we find that | 224 // This just writes all toolchain deps for simplicity. If we find that |
223 // toolchains often have more than one dependency, we could consider writing | 225 // toolchains often have more than one dependency, we could consider writing |
224 // a toolchain-specific stamp file and only include the stamp here. | 226 // a toolchain-specific stamp file and only include the stamp here. |
225 const LabelTargetVector& toolchain_deps = target_->toolchain()->deps(); | 227 const LabelTargetVector& toolchain_deps = target_->toolchain()->deps(); |
226 for (const auto& toolchain_dep : toolchain_deps) | 228 for (const auto& toolchain_dep : toolchain_deps) { |
227 unique_deps.insert(toolchain_dep.ptr); | 229 if (!hard_deps.count(toolchain_dep.ptr)) { |
M-A Ruel
2015/12/08 13:49:29
I guess this assumes toolchains are never passed a
brettw
2015/12/10 21:29:46
You mean "toolchain deps" (these are target depend
| |
230 sorted_deps.push_back(toolchain_dep.ptr); | |
231 } | |
232 } | |
228 | 233 |
229 for (const auto& dep : unique_deps) { | 234 for (const Target* target : hard_deps) { |
235 sorted_deps.push_back(target); | |
236 } | |
237 | |
238 std::sort( | |
239 sorted_deps.begin(), sorted_deps.end(), | |
240 [](const Target* a, const Target* b) { return a->label() < b->label(); }); | |
241 | |
242 for (const auto& dep : sorted_deps) { | |
230 DCHECK(!dep->dependency_output_file().value().empty()); | 243 DCHECK(!dep->dependency_output_file().value().empty()); |
231 out_ << " "; | 244 out_ << " "; |
232 path_output_.WriteFile(out_, dep->dependency_output_file()); | 245 path_output_.WriteFile(out_, dep->dependency_output_file()); |
233 } | 246 } |
234 | 247 |
235 out_ << "\n"; | 248 out_ << "\n"; |
236 return input_stamp_file; | 249 return input_stamp_file; |
237 } | 250 } |
238 | 251 |
239 void NinjaTargetWriter::WriteStampForTarget( | 252 void NinjaTargetWriter::WriteStampForTarget( |
(...skipping 15 matching lines...) Expand all Loading... | |
255 << GetNinjaRulePrefixForToolchain(settings_) | 268 << GetNinjaRulePrefixForToolchain(settings_) |
256 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); | 269 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); |
257 path_output_.WriteFiles(out_, files); | 270 path_output_.WriteFiles(out_, files); |
258 | 271 |
259 if (!order_only_deps.empty()) { | 272 if (!order_only_deps.empty()) { |
260 out_ << " ||"; | 273 out_ << " ||"; |
261 path_output_.WriteFiles(out_, order_only_deps); | 274 path_output_.WriteFiles(out_, order_only_deps); |
262 } | 275 } |
263 out_ << std::endl; | 276 out_ << std::endl; |
264 } | 277 } |
OLD | NEW |