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

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

Issue 572893002: GN: Refine 'complete' static library handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improve complete_static_lib help; other style nitpicks 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 | « tools/gn/ninja_binary_target_writer.cc ('k') | tools/gn/target.h » ('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 <sstream> 7 #include <sstream>
8 #include <utility> 8 #include <utility>
9 9
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 "build obj/foo/libbar.input1.o: cxx ../../foo/input1.cc\n" 172 "build obj/foo/libbar.input1.o: cxx ../../foo/input1.cc\n"
173 "\n" 173 "\n"
174 "build obj/foo/libbar.a: alink obj/foo/libbar.input1.o\n" 174 "build obj/foo/libbar.a: alink obj/foo/libbar.input1.o\n"
175 " arflags = --asdf\n" 175 " arflags = --asdf\n"
176 " output_extension = \n" 176 " output_extension = \n"
177 " output_dir = \n"; 177 " output_dir = \n";
178 std::string out_str = out.str(); 178 std::string out_str = out.str();
179 EXPECT_EQ(expected, out_str); 179 EXPECT_EQ(expected, out_str);
180 } 180 }
181 181
182 TEST(NinjaBinaryTargetWriter, CompleteStaticLibrary) {
183 TestWithScope setup;
184 Err err;
185
186 TestTarget target(setup, "//foo:bar", Target::STATIC_LIBRARY);
187 target.sources().push_back(SourceFile("//foo/input1.cc"));
188 target.config_values().arflags().push_back("--asdf");
189 target.set_complete_static_lib(true);
190
191 TestTarget baz(setup, "//foo:baz", Target::STATIC_LIBRARY);
192 baz.sources().push_back(SourceFile("//foo/input2.cc"));
193
194 target.public_deps().push_back(LabelTargetPair(&baz));
195
196 ASSERT_TRUE(target.OnResolved(&err));
197 ASSERT_TRUE(baz.OnResolved(&err));
198
199 // A complete static library that depends on an incomplete static library
200 // should link in the dependent object files as if the dependent target
201 // were a source set.
202 {
203 std::ostringstream out;
204 NinjaBinaryTargetWriter writer(&target, out);
205 writer.Run();
206
207 const char expected[] =
208 "defines =\n"
209 "include_dirs =\n"
210 "cflags =\n"
211 "cflags_cc =\n"
212 "root_out_dir = .\n"
213 "target_out_dir = obj/foo\n"
214 "target_output_name = libbar\n"
215 "\n"
216 "build obj/foo/libbar.input1.o: cxx ../../foo/input1.cc\n"
217 "\n"
218 "build obj/foo/libbar.a: alink obj/foo/libbar.input1.o "
219 "obj/foo/libbaz.input2.o || obj/foo/libbaz.a\n"
220 " arflags = --asdf\n"
221 " output_extension = \n"
222 " output_dir = \n";
223 std::string out_str = out.str();
224 EXPECT_EQ(expected, out_str);
225 }
226
227 // Make the dependent static library complete.
228 baz.set_complete_static_lib(true);
229
230 // Dependent complete static libraries should not be linked directly.
231 {
232 std::ostringstream out;
233 NinjaBinaryTargetWriter writer(&target, out);
234 writer.Run();
235
236 const char expected[] =
237 "defines =\n"
238 "include_dirs =\n"
239 "cflags =\n"
240 "cflags_cc =\n"
241 "root_out_dir = .\n"
242 "target_out_dir = obj/foo\n"
243 "target_output_name = libbar\n"
244 "\n"
245 "build obj/foo/libbar.input1.o: cxx ../../foo/input1.cc\n"
246 "\n"
247 "build obj/foo/libbar.a: alink obj/foo/libbar.input1.o "
248 "|| obj/foo/libbaz.a\n"
249 " arflags = --asdf\n"
250 " output_extension = \n"
251 " output_dir = \n";
252 std::string out_str = out.str();
253 EXPECT_EQ(expected, out_str);
254 }
255 }
256
182 // This tests that output extension and output dir overrides apply, and input 257 // This tests that output extension and output dir overrides apply, and input
183 // dependencies are applied. 258 // dependencies are applied.
184 TEST(NinjaBinaryTargetWriter, OutputExtensionAndInputDeps) { 259 TEST(NinjaBinaryTargetWriter, OutputExtensionAndInputDeps) {
185 TestWithScope setup; 260 TestWithScope setup;
186 Err err; 261 Err err;
187 262
188 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 263 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
189 264
190 // An action for our library to depend on. 265 // An action for our library to depend on.
191 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); 266 Target action(setup.settings(), Label(SourceDir("//foo/"), "action"));
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 847
773 EXPECT_FALSE(scheduler.is_failed()); 848 EXPECT_FALSE(scheduler.is_failed());
774 849
775 std::ostringstream out; 850 std::ostringstream out;
776 NinjaBinaryTargetWriter writer(&target, out); 851 NinjaBinaryTargetWriter writer(&target, out);
777 writer.Run(); 852 writer.Run();
778 853
779 // Should have issued an error. 854 // Should have issued an error.
780 EXPECT_TRUE(scheduler.is_failed()); 855 EXPECT_TRUE(scheduler.is_failed());
781 } 856 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_binary_target_writer.cc ('k') | tools/gn/target.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698