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

Side by Side 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, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/gn/ninja_binary_target_writer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 std::vector<const Target*>* linkable_deps, 419 std::vector<const Target*>* linkable_deps,
420 std::vector<const Target*>* non_linkable_deps) const { 420 std::vector<const Target*>* non_linkable_deps) const {
421 // Only these types of outputs have libraries linked into them. Child deps of 421 // Only these types of outputs have libraries linked into them. Child deps of
422 // static libraries get pushed up the dependency tree until one of these is 422 // static libraries get pushed up the dependency tree until one of these is
423 // reached, and source sets don't link at all. 423 // reached, and source sets don't link at all.
424 bool can_link_libs = 424 bool can_link_libs =
425 (target_->output_type() == Target::EXECUTABLE || 425 (target_->output_type() == Target::EXECUTABLE ||
426 target_->output_type() == Target::SHARED_LIBRARY); 426 target_->output_type() == Target::SHARED_LIBRARY);
427 427
428 if (dep->output_type() == Target::SOURCE_SET) { 428 if (dep->output_type() == Target::SOURCE_SET) {
429 if (target_->output_type() == Target::SOURCE_SET) { 429 // Source sets have their object files linked into final targets (shared
430 // When a source set depends on another source set, add it as a data 430 // libraries and executables). Intermediate static libraries and other
431 // dependency so if the user says "ninja second_source_set" it will 431 // source sets just forward the dependency, otherwise the files in the
432 // also compile the first (what you would expect) even though we'll 432 // source set can easily get linked more than once which will cause
433 // never do anything with the first one's files. 433 // multiple definition errors.
434 non_linkable_deps->push_back(dep); 434 //
435 } else { 435 // In the future, we may need a way to specify a "complete" static library
436 // Linking in a source set, copy its object files. 436 // for cases where you want a static library that includes all source sets
437 // (like if you're shipping that to customers to link against).
438 if (target_->output_type() != Target::SOURCE_SET &&
439 target_->output_type() != Target::STATIC_LIBRARY) {
440 // Linking in a source set to an executable or shared library, copy its
441 // object files.
437 for (size_t i = 0; i < dep->sources().size(); i++) { 442 for (size_t i = 0; i < dep->sources().size(); i++) {
438 SourceFileType input_file_type = GetSourceFileType(dep->sources()[i]); 443 SourceFileType input_file_type = GetSourceFileType(dep->sources()[i]);
439 if (input_file_type != SOURCE_UNKNOWN && 444 if (input_file_type != SOURCE_UNKNOWN &&
440 input_file_type != SOURCE_H) { 445 input_file_type != SOURCE_H) {
441 // Note we need to specify the target as the source_set target 446 // Note we need to specify the target as the source_set target
442 // itself, since this is used to prefix the object file name. 447 // itself, since this is used to prefix the object file name.
443 extra_object_files->insert(helper_.GetOutputFileForSource( 448 extra_object_files->insert(helper_.GetOutputFileForSource(
444 dep, dep->sources()[i], input_file_type)); 449 dep, dep->sources()[i], input_file_type));
445 } 450 }
446 } 451 }
(...skipping 19 matching lines...) Expand all
466 } 471 }
467 472
468 // Data files. 473 // Data files.
469 const std::vector<SourceFile>& data = target_->data(); 474 const std::vector<SourceFile>& data = target_->data();
470 for (size_t i = 0; i < data.size(); i++) { 475 for (size_t i = 0; i < data.size(); i++) {
471 out_ << " "; 476 out_ << " ";
472 path_output_.WriteFile(out_, data[i]); 477 path_output_.WriteFile(out_, data[i]);
473 } 478 }
474 } 479 }
475 } 480 }
OLDNEW
« 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