Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: tools/gn/ninja_binary_target_writer.cc

Issue 302033004: GN: Don't link source sets into static libraries (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/gn/ninja_binary_target_writer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1204d4f473a6b40b4dda7578c5f3b7f3da302d92..b6456241f7bacfd0e23e4da2c63b370d4378c858 100644
--- a/tools/gn/ninja_binary_target_writer.cc
+++ b/tools/gn/ninja_binary_target_writer.cc
@@ -426,14 +426,19 @@ void NinjaBinaryTargetWriter::ClassifyDependency(
target_->output_type() == Target::SHARED_LIBRARY);
if (dep->output_type() == Target::SOURCE_SET) {
- if (target_->output_type() == Target::SOURCE_SET) {
- // When a source set depends on another source set, add it as a data
- // dependency so if the user says "ninja second_source_set" it will
- // also compile the first (what you would expect) even though we'll
- // never do anything with the first one's files.
- non_linkable_deps->push_back(dep);
- } else {
- // Linking in a source set, copy its object files.
+ // Source sets have their object files linked into final targets (shared
+ // libraries and executables). Intermediate static libraries and other
+ // source sets just forward the dependency, otherwise the files in the
+ // source set can easily get linked more than once which will cause
+ // multiple definition errors.
+ //
+ // In the future, we may need a way to specify a "complete" static library
+ // for cases where you want a static library that includes all source sets
+ // (like if you're shipping that to customers to link against).
+ if (target_->output_type() != Target::SOURCE_SET &&
+ target_->output_type() != Target::STATIC_LIBRARY) {
+ // Linking in a source set to an executable or shared library, copy its
+ // object files.
for (size_t i = 0; i < dep->sources().size(); i++) {
SourceFileType input_file_type = GetSourceFileType(dep->sources()[i]);
if (input_file_type != SOURCE_UNKNOWN &&
« no previous file with comments | « no previous file | tools/gn/ninja_binary_target_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698