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

Side by Side Diff: tools/gn/ninja_binary_target_writer.cc

Issue 572893002: GN: Refine 'complete' static library handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add tests and refine help. Created 4 years, 8 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
« no previous file with comments | « no previous file | tools/gn/ninja_binary_target_writer_unittest.cc » ('j') | tools/gn/target.cc » ('J')
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 <stddef.h> 7 #include <stddef.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <cstring> 10 #include <cstring>
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 // Only the following types of outputs have libraries linked into them: 931 // Only the following types of outputs have libraries linked into them:
932 // EXECUTABLE 932 // EXECUTABLE
933 // SHARED_LIBRARY 933 // SHARED_LIBRARY
934 // _complete_ STATIC_LIBRARY 934 // _complete_ STATIC_LIBRARY
935 // 935 //
936 // Child deps of intermediate static libraries get pushed up the 936 // Child deps of intermediate static libraries get pushed up the
937 // dependency tree until one of these is reached, and source sets 937 // dependency tree until one of these is reached, and source sets
938 // don't link at all. 938 // don't link at all.
939 bool can_link_libs = target_->IsFinal(); 939 bool can_link_libs = target_->IsFinal();
940 940
941 if (dep->output_type() == Target::SOURCE_SET) { 941 if (dep->output_type() == Target::SOURCE_SET ||
942 // If a complete static library depends on an incomplete static library,
943 // manually link in the object files of the dependent library as if it
944 // were a source set. This avoids problems with braindead tools such as
945 // ar which don't properly link dependent static libraries.
946 (target_->complete_static_lib() &&
947 dep->output_type() == Target::STATIC_LIBRARY &&
948 !dep->complete_static_lib())) {
942 // Source sets have their object files linked into final targets 949 // Source sets have their object files linked into final targets
943 // (shared libraries, executables, loadable modules, and complete static 950 // (shared libraries, executables, loadable modules, and complete static
944 // libraries). Intermediate static libraries and other source sets 951 // libraries). Intermediate static libraries and other source sets
945 // just forward the dependency, otherwise the files in the source 952 // just forward the dependency, otherwise the files in the source
946 // set can easily get linked more than once which will cause 953 // set can easily get linked more than once which will cause
947 // multiple definition errors. 954 // multiple definition errors.
948 if (can_link_libs) 955 if (can_link_libs)
949 AddSourceSetObjectFiles(dep, extra_object_files); 956 AddSourceSetObjectFiles(dep, extra_object_files);
950
brettw 2016/04/21 20:47:00 I liked this blank line here as it was before.
951 // Add the source set itself as a non-linkable dependency on the current 957 // Add the source set itself as a non-linkable dependency on the current
952 // target. This will make sure that anything the source set's stamp file 958 // target. This will make sure that anything the source set's stamp file
953 // depends on (like data deps) are also built before the current target 959 // depends on (like data deps) are also built before the current target
954 // can be complete. Otherwise, these will be skipped since this target 960 // can be complete. Otherwise, these will be skipped since this target
955 // will depend only on the source set's object files. 961 // will depend only on the source set's object files.
956 non_linkable_deps->push_back(dep); 962 non_linkable_deps->push_back(dep);
963 } else if (target_->complete_static_lib() && dep->IsFinal()) {
964 non_linkable_deps->push_back(dep);
957 } else if (can_link_libs && dep->IsLinkable()) { 965 } else if (can_link_libs && dep->IsLinkable()) {
958 linkable_deps->push_back(dep); 966 linkable_deps->push_back(dep);
959 } else { 967 } else {
960 non_linkable_deps->push_back(dep); 968 non_linkable_deps->push_back(dep);
961 } 969 }
962 } 970 }
963 971
964 void NinjaBinaryTargetWriter::WriteOrderOnlyDependencies( 972 void NinjaBinaryTargetWriter::WriteOrderOnlyDependencies(
965 const UniqueVector<const Target*>& non_linkable_deps) { 973 const UniqueVector<const Target*>& non_linkable_deps) {
966 if (!non_linkable_deps.empty()) { 974 if (!non_linkable_deps.empty()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 "\n" 1014 "\n"
1007 "In the latter case, either rename one of the files or move one of\n" 1015 "In the latter case, either rename one of the files or move one of\n"
1008 "the sources to a separate source_set to avoid them both being in\n" 1016 "the sources to a separate source_set to avoid them both being in\n"
1009 "the same target."); 1017 "the same target.");
1010 g_scheduler->FailWithError(err); 1018 g_scheduler->FailWithError(err);
1011 return false; 1019 return false;
1012 } 1020 }
1013 } 1021 }
1014 return true; 1022 return true;
1015 } 1023 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/ninja_binary_target_writer_unittest.cc » ('j') | tools/gn/target.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698