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_binary_target_writer.h" | 5 #include "tools/gn/ninja_binary_target_writer.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "tools/gn/config_values_extractors.h" | 10 #include "tools/gn/config_values_extractors.h" |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 const LabelTargetVector& datadeps = target_->datadeps(); | 386 const LabelTargetVector& datadeps = target_->datadeps(); |
387 for (size_t i = 0; i < datadeps.size(); i++) | 387 for (size_t i = 0; i < datadeps.size(); i++) |
388 non_linkable_deps->push_back(datadeps[i].ptr); | 388 non_linkable_deps->push_back(datadeps[i].ptr); |
389 } | 389 } |
390 | 390 |
391 void NinjaBinaryTargetWriter::ClassifyDependency( | 391 void NinjaBinaryTargetWriter::ClassifyDependency( |
392 const Target* dep, | 392 const Target* dep, |
393 UniqueVector<OutputFile>* extra_object_files, | 393 UniqueVector<OutputFile>* extra_object_files, |
394 UniqueVector<const Target*>* linkable_deps, | 394 UniqueVector<const Target*>* linkable_deps, |
395 UniqueVector<const Target*>* non_linkable_deps) const { | 395 UniqueVector<const Target*>* non_linkable_deps) const { |
396 // Only these types of outputs have libraries linked into them. Child deps of | 396 // Only the following types of outputs have libraries linked into them: |
397 // static libraries get pushed up the dependency tree until one of these is | 397 // EXECUTABLE |
398 // reached, and source sets don't link at all. | 398 // SHARED_LIBRARY |
399 bool can_link_libs = | 399 // _complete_ STATIC_LIBRARY |
400 (target_->output_type() == Target::EXECUTABLE || | 400 // |
401 target_->output_type() == Target::SHARED_LIBRARY); | 401 // Child deps of intermediate static libraries get pushed up the |
| 402 // dependency tree until one of these is reached, and source sets |
| 403 // don't link at all. |
| 404 bool can_link_libs = target_->IsFinal(); |
402 | 405 |
403 if (dep->output_type() == Target::SOURCE_SET) { | 406 if (dep->output_type() == Target::SOURCE_SET) { |
404 // Source sets have their object files linked into final targets (shared | 407 // Source sets have their object files linked into final targets |
405 // libraries and executables). Intermediate static libraries and other | 408 // (shared libraries, executables, and complete static |
406 // source sets just forward the dependency, otherwise the files in the | 409 // libraries). Intermediate static libraries and other source sets |
407 // source set can easily get linked more than once which will cause | 410 // just forward the dependency, otherwise the files in the source |
| 411 // set can easily get linked more than once which will cause |
408 // multiple definition errors. | 412 // multiple definition errors. |
409 // | 413 if (can_link_libs) { |
410 // In the future, we may need a way to specify a "complete" static library | 414 // Linking in a source set to an executable, shared library, or |
411 // for cases where you want a static library that includes all source sets | 415 // complete static library, so copy its object files. |
412 // (like if you're shipping that to customers to link against). | |
413 if (target_->output_type() != Target::SOURCE_SET && | |
414 target_->output_type() != Target::STATIC_LIBRARY) { | |
415 // Linking in a source set to an executable or shared library, copy its | |
416 // object files. | |
417 std::vector<OutputFile> tool_outputs; // Prevent allocation in loop. | 416 std::vector<OutputFile> tool_outputs; // Prevent allocation in loop. |
418 for (size_t i = 0; i < dep->sources().size(); i++) { | 417 for (size_t i = 0; i < dep->sources().size(); i++) { |
419 Toolchain::ToolType tool_type = Toolchain::TYPE_NONE; | 418 Toolchain::ToolType tool_type = Toolchain::TYPE_NONE; |
420 if (GetOutputFilesForSource(dep, dep->sources()[i], &tool_type, | 419 if (GetOutputFilesForSource(dep, dep->sources()[i], &tool_type, |
421 &tool_outputs)) { | 420 &tool_outputs)) { |
422 // Only link the first output if there are more than one. | 421 // Only link the first output if there are more than one. |
423 extra_object_files->push_back(tool_outputs[0]); | 422 extra_object_files->push_back(tool_outputs[0]); |
424 } | 423 } |
425 } | 424 } |
426 } | 425 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 return false; // No tool for this file (it's a header file or something). | 468 return false; // No tool for this file (it's a header file or something). |
470 const Tool* tool = target->toolchain()->GetTool(*computed_tool_type); | 469 const Tool* tool = target->toolchain()->GetTool(*computed_tool_type); |
471 if (!tool) | 470 if (!tool) |
472 return false; // Tool does not apply for this toolchain.file. | 471 return false; // Tool does not apply for this toolchain.file. |
473 | 472 |
474 // Figure out what output(s) this compiler produces. | 473 // Figure out what output(s) this compiler produces. |
475 SubstitutionWriter::ApplyListToCompilerAsOutputFile( | 474 SubstitutionWriter::ApplyListToCompilerAsOutputFile( |
476 target, source, tool->outputs(), outputs); | 475 target, source, tool->outputs(), outputs); |
477 return !outputs->empty(); | 476 return !outputs->empty(); |
478 } | 477 } |
OLD | NEW |