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/target.h" | 5 #include "tools/gn/target.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 case SOURCE_SET: | 217 case SOURCE_SET: |
218 return "Source set"; | 218 return "Source set"; |
219 case COPY_FILES: | 219 case COPY_FILES: |
220 return "Copy"; | 220 return "Copy"; |
221 case ACTION: | 221 case ACTION: |
222 return "Action"; | 222 return "Action"; |
223 case ACTION_FOREACH: | 223 case ACTION_FOREACH: |
224 return "ActionForEach"; | 224 return "ActionForEach"; |
225 case BUNDLE_DATA: | 225 case BUNDLE_DATA: |
226 return "Bundle data"; | 226 return "Bundle data"; |
| 227 case CREATE_BUNDLE: |
| 228 return "Create bundle"; |
227 default: | 229 default: |
228 return ""; | 230 return ""; |
229 } | 231 } |
230 } | 232 } |
231 | 233 |
232 Target* Target::AsTarget() { | 234 Target* Target::AsTarget() { |
233 return this; | 235 return this; |
234 } | 236 } |
235 | 237 |
236 const Target* Target::AsTarget() const { | 238 const Target* Target::AsTarget() const { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // This needs to happen after we pull dependent target configs for the | 272 // This needs to happen after we pull dependent target configs for the |
271 // public config's libs to be included here. And it needs to happen | 273 // public config's libs to be included here. And it needs to happen |
272 // before pulling the dependent target libs so the libs are in the correct | 274 // before pulling the dependent target libs so the libs are in the correct |
273 // order (local ones first, then the dependency's). | 275 // order (local ones first, then the dependency's). |
274 for (ConfigValuesIterator iter(this); !iter.done(); iter.Next()) { | 276 for (ConfigValuesIterator iter(this); !iter.done(); iter.Next()) { |
275 const ConfigValues& cur = iter.cur(); | 277 const ConfigValues& cur = iter.cur(); |
276 all_lib_dirs_.append(cur.lib_dirs().begin(), cur.lib_dirs().end()); | 278 all_lib_dirs_.append(cur.lib_dirs().begin(), cur.lib_dirs().end()); |
277 all_libs_.append(cur.libs().begin(), cur.libs().end()); | 279 all_libs_.append(cur.libs().begin(), cur.libs().end()); |
278 } | 280 } |
279 | 281 |
| 282 PullRecursiveBundleData(); |
280 PullDependentTargetLibs(); | 283 PullDependentTargetLibs(); |
281 PullRecursiveHardDeps(); | 284 PullRecursiveHardDeps(); |
282 if (!ResolvePrecompiledHeaders(err)) | 285 if (!ResolvePrecompiledHeaders(err)) |
283 return false; | 286 return false; |
284 | 287 |
285 FillOutputFiles(); | 288 FillOutputFiles(); |
286 | 289 |
287 if (settings()->build_settings()->check_for_bad_items()) { | 290 if (settings()->build_settings()->check_for_bad_items()) { |
288 if (!CheckVisibility(err)) | 291 if (!CheckVisibility(err)) |
289 return false; | 292 return false; |
(...skipping 21 matching lines...) Expand all Loading... |
311 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; | 314 return output_type_ == STATIC_LIBRARY || output_type_ == SHARED_LIBRARY; |
312 } | 315 } |
313 | 316 |
314 bool Target::IsFinal() const { | 317 bool Target::IsFinal() const { |
315 return output_type_ == EXECUTABLE || | 318 return output_type_ == EXECUTABLE || |
316 output_type_ == SHARED_LIBRARY || | 319 output_type_ == SHARED_LIBRARY || |
317 output_type_ == LOADABLE_MODULE || | 320 output_type_ == LOADABLE_MODULE || |
318 output_type_ == ACTION || | 321 output_type_ == ACTION || |
319 output_type_ == ACTION_FOREACH || | 322 output_type_ == ACTION_FOREACH || |
320 output_type_ == COPY_FILES || | 323 output_type_ == COPY_FILES || |
| 324 output_type_ == CREATE_BUNDLE || |
321 (output_type_ == STATIC_LIBRARY && complete_static_lib_); | 325 (output_type_ == STATIC_LIBRARY && complete_static_lib_); |
322 } | 326 } |
323 | 327 |
324 DepsIteratorRange Target::GetDeps(DepsIterationType type) const { | 328 DepsIteratorRange Target::GetDeps(DepsIterationType type) const { |
325 if (type == DEPS_LINKED) { | 329 if (type == DEPS_LINKED) { |
326 return DepsIteratorRange(DepsIterator( | 330 return DepsIteratorRange(DepsIterator( |
327 &public_deps_, &private_deps_, nullptr)); | 331 &public_deps_, &private_deps_, nullptr)); |
328 } | 332 } |
329 // All deps. | 333 // All deps. |
330 return DepsIteratorRange(DepsIterator( | 334 return DepsIteratorRange(DepsIterator( |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // Direct hard dependencies. | 473 // Direct hard dependencies. |
470 if (pair.ptr->hard_dep()) | 474 if (pair.ptr->hard_dep()) |
471 recursive_hard_deps_.insert(pair.ptr); | 475 recursive_hard_deps_.insert(pair.ptr); |
472 | 476 |
473 // Recursive hard dependencies of all dependencies. | 477 // Recursive hard dependencies of all dependencies. |
474 recursive_hard_deps_.insert(pair.ptr->recursive_hard_deps().begin(), | 478 recursive_hard_deps_.insert(pair.ptr->recursive_hard_deps().begin(), |
475 pair.ptr->recursive_hard_deps().end()); | 479 pair.ptr->recursive_hard_deps().end()); |
476 } | 480 } |
477 } | 481 } |
478 | 482 |
| 483 void Target::PullRecursiveBundleData() { |
| 484 if (output_type_ != CREATE_BUNDLE) |
| 485 return; |
| 486 |
| 487 std::set<const Target*> visited; |
| 488 std::vector<const Target*> deps; |
| 489 deps.push_back(this); |
| 490 |
| 491 while (!deps.empty()) { |
| 492 const Target* current = deps.back(); |
| 493 deps.pop_back(); |
| 494 |
| 495 if (visited.find(current) != visited.end()) |
| 496 continue; |
| 497 visited.insert(current); |
| 498 |
| 499 if (current->output_type_ == BUNDLE_DATA) |
| 500 bundle_data_.AddFileRuleFromTarget(current); |
| 501 |
| 502 for (const LabelTargetPair& pair : current->GetDeps(DEPS_ALL)) { |
| 503 DCHECK(pair.ptr); |
| 504 DCHECK(pair.ptr->toolchain_); |
| 505 if (visited.find(pair.ptr) != visited.end()) |
| 506 continue; |
| 507 |
| 508 if (pair.ptr->output_type() == CREATE_BUNDLE) |
| 509 continue; |
| 510 |
| 511 deps.push_back(pair.ptr); |
| 512 } |
| 513 } |
| 514 |
| 515 bundle_data_.GetSourceFiles(&sources_); |
| 516 } |
| 517 |
479 void Target::FillOutputFiles() { | 518 void Target::FillOutputFiles() { |
480 const Tool* tool = toolchain_->GetToolForTargetFinalOutput(this); | 519 const Tool* tool = toolchain_->GetToolForTargetFinalOutput(this); |
481 bool check_tool_outputs = false; | 520 bool check_tool_outputs = false; |
482 switch (output_type_) { | 521 switch (output_type_) { |
483 case GROUP: | 522 case GROUP: |
484 case BUNDLE_DATA: | 523 case BUNDLE_DATA: |
| 524 case CREATE_BUNDLE: |
485 case SOURCE_SET: | 525 case SOURCE_SET: |
486 case COPY_FILES: | 526 case COPY_FILES: |
487 case ACTION: | 527 case ACTION: |
488 case ACTION_FOREACH: { | 528 case ACTION_FOREACH: { |
489 // These don't get linked to and use stamps which should be the first | 529 // These don't get linked to and use stamps which should be the first |
490 // entry in the outputs. These stamps are named | 530 // entry in the outputs. These stamps are named |
491 // "<target_out_dir>/<targetname>.stamp". | 531 // "<target_out_dir>/<targetname>.stamp". |
492 dependency_output_file_ = GetTargetOutputDirAsOutputFile(this); | 532 dependency_output_file_ = GetTargetOutputDirAsOutputFile(this); |
493 dependency_output_file_.value().append(GetComputedOutputName(true)); | 533 dependency_output_file_.value().append(GetComputedOutputName(true)); |
494 dependency_output_file_.value().append(".stamp"); | 534 dependency_output_file_.value().append(".stamp"); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 runtime_link_output_file_ = | 580 runtime_link_output_file_ = |
541 SubstitutionWriter::ApplyPatternToLinkerAsOutputFile( | 581 SubstitutionWriter::ApplyPatternToLinkerAsOutputFile( |
542 this, tool, tool->runtime_link_output()); | 582 this, tool, tool->runtime_link_output()); |
543 } | 583 } |
544 break; | 584 break; |
545 case UNKNOWN: | 585 case UNKNOWN: |
546 default: | 586 default: |
547 NOTREACHED(); | 587 NOTREACHED(); |
548 } | 588 } |
549 | 589 |
| 590 // Count anything generated from bundle_data dependencies. |
| 591 if (output_type_ == CREATE_BUNDLE) |
| 592 bundle_data_.GetOutputFiles(settings(), &computed_outputs_); |
| 593 |
550 // Count all outputs from this tool as something generated by this target. | 594 // Count all outputs from this tool as something generated by this target. |
551 if (check_tool_outputs) { | 595 if (check_tool_outputs) { |
552 SubstitutionWriter::ApplyListToLinkerAsOutputFile( | 596 SubstitutionWriter::ApplyListToLinkerAsOutputFile( |
553 this, tool, tool->outputs(), &computed_outputs_); | 597 this, tool, tool->outputs(), &computed_outputs_); |
554 | 598 |
555 // Output names aren't canonicalized in the same way that source files | 599 // Output names aren't canonicalized in the same way that source files |
556 // are. For example, the tool outputs often use | 600 // are. For example, the tool outputs often use |
557 // {{some_var}}/{{output_name}} which expands to "./foo", but this won't | 601 // {{some_var}}/{{output_name}} which expands to "./foo", but this won't |
558 // match "foo" which is what we'll compute when converting a SourceFile to | 602 // match "foo" which is what we'll compute when converting a SourceFile to |
559 // an OutputFile. | 603 // an OutputFile. |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, false, | 764 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, false, |
721 &seen_targets)) { | 765 &seen_targets)) { |
722 // Check object files (much slower and very rare) only if the "normal" | 766 // Check object files (much slower and very rare) only if the "normal" |
723 // output check failed. | 767 // output check failed. |
724 seen_targets.clear(); | 768 seen_targets.clear(); |
725 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, true, | 769 if (!EnsureFileIsGeneratedByDependency(this, out_file, true, true, |
726 &seen_targets)) | 770 &seen_targets)) |
727 g_scheduler->AddUnknownGeneratedInput(this, source); | 771 g_scheduler->AddUnknownGeneratedInput(this, source); |
728 } | 772 } |
729 } | 773 } |
OLD | NEW |