Index: tools/gn/ninja_binary_target_writer.cc |
diff --git a/tools/gn/ninja_binary_target_writer.cc b/tools/gn/ninja_binary_target_writer.cc |
index 88a6eb2d546ac6e025a52df9f1d322091a27b864..bf446b32ba7ebf67296a9c7802a25905bb98e9ff 100644 |
--- a/tools/gn/ninja_binary_target_writer.cc |
+++ b/tools/gn/ninja_binary_target_writer.cc |
@@ -409,7 +409,14 @@ void NinjaBinaryTargetWriter::ClassifyDependency( |
// don't link at all. |
bool can_link_libs = target_->IsFinal(); |
- if (dep->output_type() == Target::SOURCE_SET) { |
+ if (dep->output_type() == Target::SOURCE_SET || |
+ // If a complete static library depends on an incomplete static library, |
+ // manually link in the object files of the dependent library as if it |
+ // were a source set. This avoids problems with braindead tools such as |
+ // ar which don't properly link dependent static libraries. |
+ (target_->complete_static_lib() && |
+ dep->output_type() == Target::STATIC_LIBRARY && |
+ !dep->complete_static_lib())) { |
// Source sets have their object files linked into final targets |
// (shared libraries, executables, and complete static |
// libraries). Intermediate static libraries and other source sets |
@@ -428,13 +435,14 @@ void NinjaBinaryTargetWriter::ClassifyDependency( |
} |
} |
} |
- |
// Add the source set itself as a non-linkable dependency on the current |
// target. This will make sure that anything the source set's stamp file |
// depends on (like data deps) are also built before the current target |
// can be complete. Otherwise, these will be skipped since this target |
// will depend only on the source set's object files. |
non_linkable_deps->push_back(dep); |
+ } else if (target_->complete_static_lib() && dep->IsFinal()) { |
+ non_linkable_deps->push_back(dep); |
} else if (can_link_libs && dep->IsLinkable()) { |
linkable_deps->push_back(dep); |
} else { |