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

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

Issue 1887533003: Add an output_dir override to GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: const 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/substitution_type.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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 "\n" 75 "\n"
76 "\n" 76 "\n"
77 // Ordering of the obj files here should come out in the order 77 // Ordering of the obj files here should come out in the order
78 // specified, with the target's first, followed by the source set's, in 78 // specified, with the target's first, followed by the source set's, in
79 // order. 79 // order.
80 "build ./libshlib.so: solink obj/foo/bar.input1.o " 80 "build ./libshlib.so: solink obj/foo/bar.input1.o "
81 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj " 81 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj "
82 "|| obj/foo/bar.stamp\n" 82 "|| obj/foo/bar.stamp\n"
83 " ldflags =\n" 83 " ldflags =\n"
84 " libs =\n" 84 " libs =\n"
85 " output_extension = .so\n"; 85 " output_extension = .so\n"
86 " output_dir = \n";
86 std::string out_str = out.str(); 87 std::string out_str = out.str();
87 EXPECT_EQ(expected, out_str); 88 EXPECT_EQ(expected, out_str);
88 } 89 }
89 90
90 // A static library that depends on the source set (should not link it). 91 // A static library that depends on the source set (should not link it).
91 Target stlib_target(setup.settings(), Label(SourceDir("//foo/"), "stlib")); 92 Target stlib_target(setup.settings(), Label(SourceDir("//foo/"), "stlib"));
92 stlib_target.set_output_type(Target::STATIC_LIBRARY); 93 stlib_target.set_output_type(Target::STATIC_LIBRARY);
93 stlib_target.public_deps().push_back(LabelTargetPair(&target)); 94 stlib_target.public_deps().push_back(LabelTargetPair(&target));
94 stlib_target.SetToolchain(setup.toolchain()); 95 stlib_target.SetToolchain(setup.toolchain());
95 ASSERT_TRUE(stlib_target.OnResolved(&err)); 96 ASSERT_TRUE(stlib_target.OnResolved(&err));
96 97
97 { 98 {
98 std::ostringstream out; 99 std::ostringstream out;
99 NinjaBinaryTargetWriter writer(&stlib_target, out); 100 NinjaBinaryTargetWriter writer(&stlib_target, out);
100 writer.Run(); 101 writer.Run();
101 102
102 const char expected[] = 103 const char expected[] =
103 "defines =\n" 104 "defines =\n"
104 "include_dirs =\n" 105 "include_dirs =\n"
105 "root_out_dir = .\n" 106 "root_out_dir = .\n"
106 "target_out_dir = obj/foo\n" 107 "target_out_dir = obj/foo\n"
107 "target_output_name = libstlib\n" 108 "target_output_name = libstlib\n"
108 "\n" 109 "\n"
109 "\n" 110 "\n"
110 // There are no sources so there are no params to alink. (In practice 111 // There are no sources so there are no params to alink. (In practice
111 // this will probably fail in the archive tool.) 112 // this will probably fail in the archive tool.)
112 "build obj/foo/libstlib.a: alink || obj/foo/bar.stamp\n" 113 "build obj/foo/libstlib.a: alink || obj/foo/bar.stamp\n"
113 " output_extension = \n"; 114 " output_extension = \n"
115 " output_dir = \n";
114 std::string out_str = out.str(); 116 std::string out_str = out.str();
115 EXPECT_EQ(expected, out_str); 117 EXPECT_EQ(expected, out_str);
116 } 118 }
117 119
118 // Make the static library 'complete', which means it should be linked. 120 // Make the static library 'complete', which means it should be linked.
119 stlib_target.set_complete_static_lib(true); 121 stlib_target.set_complete_static_lib(true);
120 { 122 {
121 std::ostringstream out; 123 std::ostringstream out;
122 NinjaBinaryTargetWriter writer(&stlib_target, out); 124 NinjaBinaryTargetWriter writer(&stlib_target, out);
123 writer.Run(); 125 writer.Run();
124 126
125 const char expected[] = 127 const char expected[] =
126 "defines =\n" 128 "defines =\n"
127 "include_dirs =\n" 129 "include_dirs =\n"
128 "root_out_dir = .\n" 130 "root_out_dir = .\n"
129 "target_out_dir = obj/foo\n" 131 "target_out_dir = obj/foo\n"
130 "target_output_name = libstlib\n" 132 "target_output_name = libstlib\n"
131 "\n" 133 "\n"
132 "\n" 134 "\n"
133 // Ordering of the obj files here should come out in the order 135 // Ordering of the obj files here should come out in the order
134 // specified, with the target's first, followed by the source set's, in 136 // specified, with the target's first, followed by the source set's, in
135 // order. 137 // order.
136 "build obj/foo/libstlib.a: alink obj/foo/bar.input1.o " 138 "build obj/foo/libstlib.a: alink obj/foo/bar.input1.o "
137 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj " 139 "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj "
138 "|| obj/foo/bar.stamp\n" 140 "|| obj/foo/bar.stamp\n"
139 " output_extension = \n"; 141 " output_extension = \n"
142 " output_dir = \n";
140 std::string out_str = out.str(); 143 std::string out_str = out.str();
141 EXPECT_EQ(expected, out_str); 144 EXPECT_EQ(expected, out_str);
142 } 145 }
143 } 146 }
144 147
145 // This tests that output extension overrides apply, and input dependencies 148 // This tests that output extension and output dir overrides apply, and input
146 // are applied. 149 // dependencies are applied.
147 TEST(NinjaBinaryTargetWriter, ProductExtensionAndInputDeps) { 150 TEST(NinjaBinaryTargetWriter, OutputExtensionAndInputDeps) {
148 TestWithScope setup; 151 TestWithScope setup;
149 Err err; 152 Err err;
150 153
151 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 154 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
152 155
153 // An action for our library to depend on. 156 // An action for our library to depend on.
154 Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); 157 Target action(setup.settings(), Label(SourceDir("//foo/"), "action"));
155 action.set_output_type(Target::ACTION_FOREACH); 158 action.set_output_type(Target::ACTION_FOREACH);
156 action.visibility().SetPublic(); 159 action.visibility().SetPublic();
157 action.SetToolchain(setup.toolchain()); 160 action.SetToolchain(setup.toolchain());
158 ASSERT_TRUE(action.OnResolved(&err)); 161 ASSERT_TRUE(action.OnResolved(&err));
159 162
160 // A shared library w/ the product_extension set to a custom value. 163 // A shared library w/ the output_extension set to a custom value.
161 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); 164 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib"));
162 target.set_output_type(Target::SHARED_LIBRARY); 165 target.set_output_type(Target::SHARED_LIBRARY);
163 target.set_output_extension(std::string("so.6")); 166 target.set_output_extension(std::string("so.6"));
167 target.set_output_dir(SourceDir("//out/Debug/foo/"));
164 target.sources().push_back(SourceFile("//foo/input1.cc")); 168 target.sources().push_back(SourceFile("//foo/input1.cc"));
165 target.sources().push_back(SourceFile("//foo/input2.cc")); 169 target.sources().push_back(SourceFile("//foo/input2.cc"));
166 target.public_deps().push_back(LabelTargetPair(&action)); 170 target.public_deps().push_back(LabelTargetPair(&action));
167 target.SetToolchain(setup.toolchain()); 171 target.SetToolchain(setup.toolchain());
168 ASSERT_TRUE(target.OnResolved(&err)); 172 ASSERT_TRUE(target.OnResolved(&err));
169 173
170 std::ostringstream out; 174 std::ostringstream out;
171 NinjaBinaryTargetWriter writer(&target, out); 175 NinjaBinaryTargetWriter writer(&target, out);
172 writer.Run(); 176 writer.Run();
173 177
(...skipping 11 matching lines...) Expand all
185 "build obj/foo/libshlib.input2.o: cxx ../../foo/input2.cc" 189 "build obj/foo/libshlib.input2.o: cxx ../../foo/input2.cc"
186 " || obj/foo/action.stamp\n" 190 " || obj/foo/action.stamp\n"
187 "\n" 191 "\n"
188 "build ./libshlib.so.6: solink obj/foo/libshlib.input1.o " 192 "build ./libshlib.so.6: solink obj/foo/libshlib.input1.o "
189 // The order-only dependency here is stricly unnecessary since the 193 // The order-only dependency here is stricly unnecessary since the
190 // sources list this as an order-only dep. See discussion in the code 194 // sources list this as an order-only dep. See discussion in the code
191 // that writes this. 195 // that writes this.
192 "obj/foo/libshlib.input2.o || obj/foo/action.stamp\n" 196 "obj/foo/libshlib.input2.o || obj/foo/action.stamp\n"
193 " ldflags =\n" 197 " ldflags =\n"
194 " libs =\n" 198 " libs =\n"
195 " output_extension = .so.6\n"; 199 " output_extension = .so.6\n"
200 " output_dir = foo\n";
196 201
197 std::string out_str = out.str(); 202 std::string out_str = out.str();
198 EXPECT_EQ(expected, out_str); 203 EXPECT_EQ(expected, out_str);
199 } 204 }
200 205
201 // Tests libs are applied. 206 // Tests libs are applied.
202 TEST(NinjaBinaryTargetWriter, LibsAndLibDirs) { 207 TEST(NinjaBinaryTargetWriter, LibsAndLibDirs) {
203 TestWithScope setup; 208 TestWithScope setup;
204 Err err; 209 Err err;
205 210
(...skipping 16 matching lines...) Expand all
222 "defines =\n" 227 "defines =\n"
223 "include_dirs =\n" 228 "include_dirs =\n"
224 "root_out_dir = .\n" 229 "root_out_dir = .\n"
225 "target_out_dir = obj/foo\n" 230 "target_out_dir = obj/foo\n"
226 "target_output_name = libshlib\n" 231 "target_output_name = libshlib\n"
227 "\n" 232 "\n"
228 "\n" 233 "\n"
229 "build ./libshlib.so: solink | ../../foo/lib1.a\n" 234 "build ./libshlib.so: solink | ../../foo/lib1.a\n"
230 " ldflags = -L../../foo/bar\n" 235 " ldflags = -L../../foo/bar\n"
231 " libs = ../../foo/lib1.a -lfoo\n" 236 " libs = ../../foo/lib1.a -lfoo\n"
232 " output_extension = .so\n"; 237 " output_extension = .so\n"
238 " output_dir = \n";
233 239
234 std::string out_str = out.str(); 240 std::string out_str = out.str();
235 EXPECT_EQ(expected, out_str); 241 EXPECT_EQ(expected, out_str);
236 } 242 }
237 243
238 TEST(NinjaBinaryTargetWriter, EmptyProductExtension) { 244 TEST(NinjaBinaryTargetWriter, EmptyOutputExtension) {
239 TestWithScope setup; 245 TestWithScope setup;
240 Err err; 246 Err err;
241 247
242 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 248 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
243 249
244 // This test is the same as ProductExtension, except that we call 250 // This test is the same as OutputExtensionAndInputDeps, except that we call
245 // set_output_extension("") and ensure that we get an empty one and override 251 // set_output_extension("") and ensure that we get an empty one and override
246 // the output prefix so that the name matches the target exactly. 252 // the output prefix so that the name matches the target exactly.
247 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); 253 Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib"));
248 target.set_output_type(Target::SHARED_LIBRARY); 254 target.set_output_type(Target::SHARED_LIBRARY);
249 target.set_output_prefix_override(true); 255 target.set_output_prefix_override(true);
250 target.set_output_extension(std::string()); 256 target.set_output_extension(std::string());
251 target.sources().push_back(SourceFile("//foo/input1.cc")); 257 target.sources().push_back(SourceFile("//foo/input1.cc"));
252 target.sources().push_back(SourceFile("//foo/input2.cc")); 258 target.sources().push_back(SourceFile("//foo/input2.cc"));
253 259
254 target.SetToolchain(setup.toolchain()); 260 target.SetToolchain(setup.toolchain());
(...skipping 12 matching lines...) Expand all
267 "target_out_dir = obj/foo\n" 273 "target_out_dir = obj/foo\n"
268 "target_output_name = shlib\n" 274 "target_output_name = shlib\n"
269 "\n" 275 "\n"
270 "build obj/foo/shlib.input1.o: cxx ../../foo/input1.cc\n" 276 "build obj/foo/shlib.input1.o: cxx ../../foo/input1.cc\n"
271 "build obj/foo/shlib.input2.o: cxx ../../foo/input2.cc\n" 277 "build obj/foo/shlib.input2.o: cxx ../../foo/input2.cc\n"
272 "\n" 278 "\n"
273 "build ./shlib: solink obj/foo/shlib.input1.o " 279 "build ./shlib: solink obj/foo/shlib.input1.o "
274 "obj/foo/shlib.input2.o\n" 280 "obj/foo/shlib.input2.o\n"
275 " ldflags =\n" 281 " ldflags =\n"
276 " libs =\n" 282 " libs =\n"
277 " output_extension = \n"; 283 " output_extension = \n"
284 " output_dir = \n";
278 285
279 std::string out_str = out.str(); 286 std::string out_str = out.str();
280 EXPECT_EQ(expected, out_str); 287 EXPECT_EQ(expected, out_str);
281 } 288 }
282 289
283 TEST(NinjaBinaryTargetWriter, SourceSetDataDeps) { 290 TEST(NinjaBinaryTargetWriter, SourceSetDataDeps) {
284 TestWithScope setup; 291 TestWithScope setup;
285 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 292 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
286 293
287 Err err; 294 Err err;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 "root_out_dir = .\n" 357 "root_out_dir = .\n"
351 "target_out_dir = obj/foo\n" 358 "target_out_dir = obj/foo\n"
352 "target_output_name = exe\n" 359 "target_output_name = exe\n"
353 "\n" 360 "\n"
354 "build obj/foo/exe.final.o: cxx ../../foo/final.cc\n" 361 "build obj/foo/exe.final.o: cxx ../../foo/final.cc\n"
355 "\n" 362 "\n"
356 "build ./exe: link obj/foo/exe.final.o obj/foo/inter.inter.o || " 363 "build ./exe: link obj/foo/exe.final.o obj/foo/inter.inter.o || "
357 "obj/foo/inter.stamp\n" 364 "obj/foo/inter.stamp\n"
358 " ldflags =\n" 365 " ldflags =\n"
359 " libs =\n" 366 " libs =\n"
360 " output_extension = \n"; 367 " output_extension = \n"
368 " output_dir = \n";
361 EXPECT_EQ(final_expected, final_out.str()); 369 EXPECT_EQ(final_expected, final_out.str());
362 } 370 }
363 371
364 TEST(NinjaBinaryTargetWriter, SharedLibraryModuleDefinitionFile) { 372 TEST(NinjaBinaryTargetWriter, SharedLibraryModuleDefinitionFile) {
365 TestWithScope setup; 373 TestWithScope setup;
366 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 374 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
367 375
368 Target shared_lib(setup.settings(), Label(SourceDir("//foo/"), "bar")); 376 Target shared_lib(setup.settings(), Label(SourceDir("//foo/"), "bar"));
369 shared_lib.set_output_type(Target::SHARED_LIBRARY); 377 shared_lib.set_output_type(Target::SHARED_LIBRARY);
370 shared_lib.SetToolchain(setup.toolchain()); 378 shared_lib.SetToolchain(setup.toolchain());
(...skipping 14 matching lines...) Expand all
385 "cflags_cc =\n" 393 "cflags_cc =\n"
386 "root_out_dir = .\n" 394 "root_out_dir = .\n"
387 "target_out_dir = obj/foo\n" 395 "target_out_dir = obj/foo\n"
388 "target_output_name = libbar\n" 396 "target_output_name = libbar\n"
389 "\n" 397 "\n"
390 "build obj/foo/libbar.sources.o: cxx ../../foo/sources.cc\n" 398 "build obj/foo/libbar.sources.o: cxx ../../foo/sources.cc\n"
391 "\n" 399 "\n"
392 "build ./libbar.so: solink obj/foo/libbar.sources.o | ../../foo/bar.def\n" 400 "build ./libbar.so: solink obj/foo/libbar.sources.o | ../../foo/bar.def\n"
393 " ldflags = /DEF:../../foo/bar.def\n" 401 " ldflags = /DEF:../../foo/bar.def\n"
394 " libs =\n" 402 " libs =\n"
395 " output_extension = .so\n"; 403 " output_extension = .so\n"
404 " output_dir = \n";
396 EXPECT_EQ(expected, out.str()); 405 EXPECT_EQ(expected, out.str());
397 } 406 }
398 407
399 TEST(NinjaBinaryTargetWriter, LoadableModule) { 408 TEST(NinjaBinaryTargetWriter, LoadableModule) {
400 TestWithScope setup; 409 TestWithScope setup;
401 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 410 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
402 411
403 Target loadable_module(setup.settings(), Label(SourceDir("//foo/"), "bar")); 412 Target loadable_module(setup.settings(), Label(SourceDir("//foo/"), "bar"));
404 loadable_module.set_output_type(Target::LOADABLE_MODULE); 413 loadable_module.set_output_type(Target::LOADABLE_MODULE);
405 loadable_module.visibility().SetPublic(); 414 loadable_module.visibility().SetPublic();
(...skipping 14 matching lines...) Expand all
420 "cflags_cc =\n" 429 "cflags_cc =\n"
421 "root_out_dir = .\n" 430 "root_out_dir = .\n"
422 "target_out_dir = obj/foo\n" 431 "target_out_dir = obj/foo\n"
423 "target_output_name = libbar\n" 432 "target_output_name = libbar\n"
424 "\n" 433 "\n"
425 "build obj/foo/libbar.sources.o: cxx ../../foo/sources.cc\n" 434 "build obj/foo/libbar.sources.o: cxx ../../foo/sources.cc\n"
426 "\n" 435 "\n"
427 "build ./libbar.so: solink_module obj/foo/libbar.sources.o\n" 436 "build ./libbar.so: solink_module obj/foo/libbar.sources.o\n"
428 " ldflags =\n" 437 " ldflags =\n"
429 " libs =\n" 438 " libs =\n"
430 " output_extension = .so\n"; 439 " output_extension = .so\n"
440 " output_dir = \n";
431 EXPECT_EQ(loadable_expected, out.str()); 441 EXPECT_EQ(loadable_expected, out.str());
432 442
433 // Final target. 443 // Final target.
434 Target exe(setup.settings(), Label(SourceDir("//foo/"), "exe")); 444 Target exe(setup.settings(), Label(SourceDir("//foo/"), "exe"));
435 exe.set_output_type(Target::EXECUTABLE); 445 exe.set_output_type(Target::EXECUTABLE);
436 exe.public_deps().push_back(LabelTargetPair(&loadable_module)); 446 exe.public_deps().push_back(LabelTargetPair(&loadable_module));
437 exe.SetToolchain(setup.toolchain()); 447 exe.SetToolchain(setup.toolchain());
438 exe.sources().push_back(SourceFile("//foo/final.cc")); 448 exe.sources().push_back(SourceFile("//foo/final.cc"));
439 ASSERT_TRUE(exe.OnResolved(&err)) << err.message(); 449 ASSERT_TRUE(exe.OnResolved(&err)) << err.message();
440 450
(...skipping 10 matching lines...) Expand all
451 "cflags_cc =\n" 461 "cflags_cc =\n"
452 "root_out_dir = .\n" 462 "root_out_dir = .\n"
453 "target_out_dir = obj/foo\n" 463 "target_out_dir = obj/foo\n"
454 "target_output_name = exe\n" 464 "target_output_name = exe\n"
455 "\n" 465 "\n"
456 "build obj/foo/exe.final.o: cxx ../../foo/final.cc\n" 466 "build obj/foo/exe.final.o: cxx ../../foo/final.cc\n"
457 "\n" 467 "\n"
458 "build ./exe: link obj/foo/exe.final.o || ./libbar.so\n" 468 "build ./exe: link obj/foo/exe.final.o || ./libbar.so\n"
459 " ldflags =\n" 469 " ldflags =\n"
460 " libs =\n" 470 " libs =\n"
461 " output_extension = \n"; 471 " output_extension = \n"
472 " output_dir = \n";
462 EXPECT_EQ(final_expected, final_out.str()); 473 EXPECT_EQ(final_expected, final_out.str());
463 } 474 }
464 475
465 TEST(NinjaBinaryTargetWriter, WinPrecompiledHeaders) { 476 TEST(NinjaBinaryTargetWriter, WinPrecompiledHeaders) {
466 Err err; 477 Err err;
467 478
468 // This setup's toolchain does not have precompiled headers defined. 479 // This setup's toolchain does not have precompiled headers defined.
469 TestWithScope setup; 480 TestWithScope setup;
470 481
471 // A precompiled header toolchain. 482 // A precompiled header toolchain.
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 738
728 EXPECT_FALSE(scheduler.is_failed()); 739 EXPECT_FALSE(scheduler.is_failed());
729 740
730 std::ostringstream out; 741 std::ostringstream out;
731 NinjaBinaryTargetWriter writer(&target, out); 742 NinjaBinaryTargetWriter writer(&target, out);
732 writer.Run(); 743 writer.Run();
733 744
734 // Should have issued an error. 745 // Should have issued an error.
735 EXPECT_TRUE(scheduler.is_failed()); 746 EXPECT_TRUE(scheduler.is_failed());
736 } 747 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_binary_target_writer.cc ('k') | tools/gn/substitution_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698