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 <fstream> | 7 #include <fstream> |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 << GetNinjaRulePrefixForToolchain(settings_) | 188 << GetNinjaRulePrefixForToolchain(settings_) |
189 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); | 189 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); |
190 | 190 |
191 // Script file (if applicable). | 191 // Script file (if applicable). |
192 if (add_script_source_as_dep) { | 192 if (add_script_source_as_dep) { |
193 out_ << " "; | 193 out_ << " "; |
194 path_output_.WriteFile(out_, target_->action_values().script()); | 194 path_output_.WriteFile(out_, target_->action_values().script()); |
195 } | 195 } |
196 | 196 |
197 // Input files are order-only deps. | 197 // Input files are order-only deps. |
198 const Target::FileList& prereqs = target_->inputs(); | 198 for (const auto& input : target_->inputs()) { |
199 for (size_t i = 0; i < prereqs.size(); i++) { | |
200 out_ << " "; | 199 out_ << " "; |
201 path_output_.WriteFile(out_, prereqs[i]); | 200 path_output_.WriteFile(out_, input); |
202 } | 201 } |
203 if (list_sources_as_input_deps) { | 202 if (list_sources_as_input_deps) { |
204 const Target::FileList& sources = target_->sources(); | 203 for (const auto& source : target_->sources()) { |
205 for (size_t i = 0; i < sources.size(); i++) { | |
206 out_ << " "; | 204 out_ << " "; |
207 path_output_.WriteFile(out_, sources[i]); | 205 path_output_.WriteFile(out_, source); |
208 } | 206 } |
209 } | 207 } |
210 | 208 |
211 // 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 |
212 // them (ordering doesn't matter for this case). | 210 // them (ordering doesn't matter for this case). |
213 std::set<const Target*> unique_deps; | 211 std::set<const Target*> unique_deps; |
214 | 212 |
215 // Hard dependencies that are direct or indirect dependencies. | 213 // Hard dependencies that are direct or indirect dependencies. |
216 const std::set<const Target*>& hard_deps = target_->recursive_hard_deps(); | 214 const std::set<const Target*>& hard_deps = target_->recursive_hard_deps(); |
217 for (const auto& dep : hard_deps) | 215 for (const auto& dep : hard_deps) |
218 unique_deps.insert(dep); | 216 unique_deps.insert(dep); |
219 | 217 |
220 // Extra hard dependencies passed in. | 218 // Extra hard dependencies passed in. |
221 unique_deps.insert(extra_hard_deps.begin(), extra_hard_deps.end()); | 219 unique_deps.insert(extra_hard_deps.begin(), extra_hard_deps.end()); |
222 | 220 |
223 // Toolchain dependencies. These must be resolved before doing anything. | 221 // Toolchain dependencies. These must be resolved before doing anything. |
224 // This just writs all toolchain deps for simplicity. If we find that | 222 // This just writs all toolchain deps for simplicity. If we find that |
225 // toolchains often have more than one dependency, we could consider writing | 223 // toolchains often have more than one dependency, we could consider writing |
226 // a toolchain-specific stamp file and only include the stamp here. | 224 // a toolchain-specific stamp file and only include the stamp here. |
227 const LabelTargetVector& toolchain_deps = target_->toolchain()->deps(); | 225 const LabelTargetVector& toolchain_deps = target_->toolchain()->deps(); |
228 for (size_t i = 0; i < toolchain_deps.size(); i++) | 226 for (const auto& toolchain_dep : toolchain_deps) |
229 unique_deps.insert(toolchain_deps[i].ptr); | 227 unique_deps.insert(toolchain_dep.ptr); |
230 | 228 |
231 for (const auto& dep : unique_deps) { | 229 for (const auto& dep : unique_deps) { |
232 DCHECK(!dep->dependency_output_file().value().empty()); | 230 DCHECK(!dep->dependency_output_file().value().empty()); |
233 out_ << " "; | 231 out_ << " "; |
234 path_output_.WriteFile(out_, dep->dependency_output_file()); | 232 path_output_.WriteFile(out_, dep->dependency_output_file()); |
235 } | 233 } |
236 | 234 |
237 out_ << "\n"; | 235 out_ << "\n"; |
238 return input_stamp_file; | 236 return input_stamp_file; |
239 } | 237 } |
(...skipping 16 matching lines...) Expand all Loading... |
256 << GetNinjaRulePrefixForToolchain(settings_) | 254 << GetNinjaRulePrefixForToolchain(settings_) |
257 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); | 255 << Toolchain::ToolTypeToName(Toolchain::TYPE_STAMP); |
258 path_output_.WriteFiles(out_, files); | 256 path_output_.WriteFiles(out_, files); |
259 | 257 |
260 if (!order_only_deps.empty()) { | 258 if (!order_only_deps.empty()) { |
261 out_ << " ||"; | 259 out_ << " ||"; |
262 path_output_.WriteFiles(out_, order_only_deps); | 260 path_output_.WriteFiles(out_, order_only_deps); |
263 } | 261 } |
264 out_ << std::endl; | 262 out_ << std::endl; |
265 } | 263 } |
OLD | NEW |