| OLD | NEW | 
|---|
| 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" | 
| 11 #include "tools/gn/scheduler.h" | 11 #include "tools/gn/scheduler.h" | 
| 12 #include "tools/gn/target.h" | 12 #include "tools/gn/target.h" | 
| 13 #include "tools/gn/test_with_scope.h" | 13 #include "tools/gn/test_with_scope.h" | 
| 14 | 14 | 
| 15 TEST(NinjaBinaryTargetWriter, SourceSet) { | 15 TEST(NinjaBinaryTargetWriter, SourceSet) { | 
| 16   Err err; | 16   Err err; | 
| 17   TestWithScope setup; | 17   TestWithScope setup; | 
| 18 | 18 | 
| 19   Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 19   Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); | 
| 20   target.set_output_type(Target::SOURCE_SET); | 20   target.set_output_type(Target::SOURCE_SET); | 
| 21   target.visibility().SetPublic(); | 21   target.visibility().SetPublic(); | 
| 22   target.sources().push_back(SourceFile("//foo/input1.cc")); | 22   target.sources().push_back(SourceFile("//foo/input1.cc")); | 
| 23   target.sources().push_back(SourceFile("//foo/input2.cc")); | 23   target.sources().push_back(SourceFile("//foo/input2.cc")); | 
| 24   // Also test object files, which should be just passed through to the | 24   // Also test object files, which should be just passed through to the | 
| 25   // dependents to link. | 25   // dependents to link. | 
| 26   target.sources().push_back(SourceFile("//foo/input3.o")); | 26   target.sources().push_back(SourceFile("//foo/input3.o")); | 
| 27   target.sources().push_back(SourceFile("//foo/input4.obj")); | 27   target.sources().push_back(SourceFile("//foo/input4.obj")); | 
| 28   target.SetToolchain(setup.toolchain()); | 28   target.SetToolchain(setup.toolchain()); | 
| 29   ASSERT_TRUE(target.OnResolved(&err)); | 29   ASSERT_TRUE(target.OnResolved(&err)); | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 46         "build obj/foo/bar.input1.o: cxx ../../foo/input1.cc\n" | 46         "build obj/foo/bar.input1.o: cxx ../../foo/input1.cc\n" | 
| 47         "build obj/foo/bar.input2.o: cxx ../../foo/input2.cc\n" | 47         "build obj/foo/bar.input2.o: cxx ../../foo/input2.cc\n" | 
| 48         "\n" | 48         "\n" | 
| 49         "build obj/foo/bar.stamp: stamp obj/foo/bar.input1.o " | 49         "build obj/foo/bar.stamp: stamp obj/foo/bar.input1.o " | 
| 50             "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj\n"; | 50             "obj/foo/bar.input2.o ../../foo/input3.o ../../foo/input4.obj\n"; | 
| 51     std::string out_str = out.str(); | 51     std::string out_str = out.str(); | 
| 52     EXPECT_EQ(expected, out_str); | 52     EXPECT_EQ(expected, out_str); | 
| 53   } | 53   } | 
| 54 | 54 | 
| 55   // A shared library that depends on the source set. | 55   // A shared library that depends on the source set. | 
| 56   Target shlib_target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); | 56   Target shlib_target(setup.settings(), Label(SourceDir("//foo/"), "shlib"), | 
|  | 57                       {}); | 
| 57   shlib_target.set_output_type(Target::SHARED_LIBRARY); | 58   shlib_target.set_output_type(Target::SHARED_LIBRARY); | 
| 58   shlib_target.public_deps().push_back(LabelTargetPair(&target)); | 59   shlib_target.public_deps().push_back(LabelTargetPair(&target)); | 
| 59   shlib_target.SetToolchain(setup.toolchain()); | 60   shlib_target.SetToolchain(setup.toolchain()); | 
| 60   ASSERT_TRUE(shlib_target.OnResolved(&err)); | 61   ASSERT_TRUE(shlib_target.OnResolved(&err)); | 
| 61 | 62 | 
| 62   { | 63   { | 
| 63     std::ostringstream out; | 64     std::ostringstream out; | 
| 64     NinjaBinaryTargetWriter writer(&shlib_target, out); | 65     NinjaBinaryTargetWriter writer(&shlib_target, out); | 
| 65     writer.Run(); | 66     writer.Run(); | 
| 66 | 67 | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 80             "|| obj/foo/bar.stamp\n" | 81             "|| obj/foo/bar.stamp\n" | 
| 81         "  ldflags =\n" | 82         "  ldflags =\n" | 
| 82         "  libs =\n" | 83         "  libs =\n" | 
| 83         "  output_extension = .so\n" | 84         "  output_extension = .so\n" | 
| 84         "  output_dir = \n"; | 85         "  output_dir = \n"; | 
| 85     std::string out_str = out.str(); | 86     std::string out_str = out.str(); | 
| 86     EXPECT_EQ(expected, out_str); | 87     EXPECT_EQ(expected, out_str); | 
| 87   } | 88   } | 
| 88 | 89 | 
| 89   // A static library that depends on the source set (should not link it). | 90   // A static library that depends on the source set (should not link it). | 
| 90   Target stlib_target(setup.settings(), Label(SourceDir("//foo/"), "stlib")); | 91   Target stlib_target(setup.settings(), Label(SourceDir("//foo/"), "stlib"), | 
|  | 92                       {}); | 
| 91   stlib_target.set_output_type(Target::STATIC_LIBRARY); | 93   stlib_target.set_output_type(Target::STATIC_LIBRARY); | 
| 92   stlib_target.public_deps().push_back(LabelTargetPair(&target)); | 94   stlib_target.public_deps().push_back(LabelTargetPair(&target)); | 
| 93   stlib_target.SetToolchain(setup.toolchain()); | 95   stlib_target.SetToolchain(setup.toolchain()); | 
| 94   ASSERT_TRUE(stlib_target.OnResolved(&err)); | 96   ASSERT_TRUE(stlib_target.OnResolved(&err)); | 
| 95 | 97 | 
| 96   { | 98   { | 
| 97     std::ostringstream out; | 99     std::ostringstream out; | 
| 98     NinjaBinaryTargetWriter writer(&stlib_target, out); | 100     NinjaBinaryTargetWriter writer(&stlib_target, out); | 
| 99     writer.Run(); | 101     writer.Run(); | 
| 100 | 102 | 
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 252   } | 254   } | 
| 253 } | 255 } | 
| 254 | 256 | 
| 255 // 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 | 
| 256 // dependencies are applied. | 258 // dependencies are applied. | 
| 257 TEST(NinjaBinaryTargetWriter, OutputExtensionAndInputDeps) { | 259 TEST(NinjaBinaryTargetWriter, OutputExtensionAndInputDeps) { | 
| 258   Err err; | 260   Err err; | 
| 259   TestWithScope setup; | 261   TestWithScope setup; | 
| 260 | 262 | 
| 261   // An action for our library to depend on. | 263   // An action for our library to depend on. | 
| 262   Target action(setup.settings(), Label(SourceDir("//foo/"), "action")); | 264   Target action(setup.settings(), Label(SourceDir("//foo/"), "action"), {}); | 
| 263   action.set_output_type(Target::ACTION_FOREACH); | 265   action.set_output_type(Target::ACTION_FOREACH); | 
| 264   action.visibility().SetPublic(); | 266   action.visibility().SetPublic(); | 
| 265   action.SetToolchain(setup.toolchain()); | 267   action.SetToolchain(setup.toolchain()); | 
| 266   ASSERT_TRUE(action.OnResolved(&err)); | 268   ASSERT_TRUE(action.OnResolved(&err)); | 
| 267 | 269 | 
| 268   // A shared library w/ the output_extension set to a custom value. | 270   // A shared library w/ the output_extension set to a custom value. | 
| 269   Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); | 271   Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib"), {}); | 
| 270   target.set_output_type(Target::SHARED_LIBRARY); | 272   target.set_output_type(Target::SHARED_LIBRARY); | 
| 271   target.set_output_extension(std::string("so.6")); | 273   target.set_output_extension(std::string("so.6")); | 
| 272   target.set_output_dir(SourceDir("//out/Debug/foo/")); | 274   target.set_output_dir(SourceDir("//out/Debug/foo/")); | 
| 273   target.sources().push_back(SourceFile("//foo/input1.cc")); | 275   target.sources().push_back(SourceFile("//foo/input1.cc")); | 
| 274   target.sources().push_back(SourceFile("//foo/input2.cc")); | 276   target.sources().push_back(SourceFile("//foo/input2.cc")); | 
| 275   target.public_deps().push_back(LabelTargetPair(&action)); | 277   target.public_deps().push_back(LabelTargetPair(&action)); | 
| 276   target.SetToolchain(setup.toolchain()); | 278   target.SetToolchain(setup.toolchain()); | 
| 277   ASSERT_TRUE(target.OnResolved(&err)); | 279   ASSERT_TRUE(target.OnResolved(&err)); | 
| 278 | 280 | 
| 279   std::ostringstream out; | 281   std::ostringstream out; | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 307   std::string out_str = out.str(); | 309   std::string out_str = out.str(); | 
| 308   EXPECT_EQ(expected, out_str); | 310   EXPECT_EQ(expected, out_str); | 
| 309 } | 311 } | 
| 310 | 312 | 
| 311 // Tests libs are applied. | 313 // Tests libs are applied. | 
| 312 TEST(NinjaBinaryTargetWriter, LibsAndLibDirs) { | 314 TEST(NinjaBinaryTargetWriter, LibsAndLibDirs) { | 
| 313   Err err; | 315   Err err; | 
| 314   TestWithScope setup; | 316   TestWithScope setup; | 
| 315 | 317 | 
| 316   // A shared library w/ libs and lib_dirs. | 318   // A shared library w/ libs and lib_dirs. | 
| 317   Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); | 319   Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib"), {}); | 
| 318   target.set_output_type(Target::SHARED_LIBRARY); | 320   target.set_output_type(Target::SHARED_LIBRARY); | 
| 319   target.config_values().libs().push_back(LibFile(SourceFile("//foo/lib1.a"))); | 321   target.config_values().libs().push_back(LibFile(SourceFile("//foo/lib1.a"))); | 
| 320   target.config_values().libs().push_back(LibFile("foo")); | 322   target.config_values().libs().push_back(LibFile("foo")); | 
| 321   target.config_values().lib_dirs().push_back(SourceDir("//foo/bar/")); | 323   target.config_values().lib_dirs().push_back(SourceDir("//foo/bar/")); | 
| 322   target.SetToolchain(setup.toolchain()); | 324   target.SetToolchain(setup.toolchain()); | 
| 323   ASSERT_TRUE(target.OnResolved(&err)); | 325   ASSERT_TRUE(target.OnResolved(&err)); | 
| 324 | 326 | 
| 325   std::ostringstream out; | 327   std::ostringstream out; | 
| 326   NinjaBinaryTargetWriter writer(&target, out); | 328   NinjaBinaryTargetWriter writer(&target, out); | 
| 327   writer.Run(); | 329   writer.Run(); | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 344   EXPECT_EQ(expected, out_str); | 346   EXPECT_EQ(expected, out_str); | 
| 345 } | 347 } | 
| 346 | 348 | 
| 347 TEST(NinjaBinaryTargetWriter, EmptyOutputExtension) { | 349 TEST(NinjaBinaryTargetWriter, EmptyOutputExtension) { | 
| 348   Err err; | 350   Err err; | 
| 349   TestWithScope setup; | 351   TestWithScope setup; | 
| 350 | 352 | 
| 351   // This test is the same as OutputExtensionAndInputDeps, except that we call | 353   // This test is the same as OutputExtensionAndInputDeps, except that we call | 
| 352   // set_output_extension("") and ensure that we get an empty one and override | 354   // set_output_extension("") and ensure that we get an empty one and override | 
| 353   // the output prefix so that the name matches the target exactly. | 355   // the output prefix so that the name matches the target exactly. | 
| 354   Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib")); | 356   Target target(setup.settings(), Label(SourceDir("//foo/"), "shlib"), {}); | 
| 355   target.set_output_type(Target::SHARED_LIBRARY); | 357   target.set_output_type(Target::SHARED_LIBRARY); | 
| 356   target.set_output_prefix_override(true); | 358   target.set_output_prefix_override(true); | 
| 357   target.set_output_extension(std::string()); | 359   target.set_output_extension(std::string()); | 
| 358   target.sources().push_back(SourceFile("//foo/input1.cc")); | 360   target.sources().push_back(SourceFile("//foo/input1.cc")); | 
| 359   target.sources().push_back(SourceFile("//foo/input2.cc")); | 361   target.sources().push_back(SourceFile("//foo/input2.cc")); | 
| 360 | 362 | 
| 361   target.SetToolchain(setup.toolchain()); | 363   target.SetToolchain(setup.toolchain()); | 
| 362   ASSERT_TRUE(target.OnResolved(&err)); | 364   ASSERT_TRUE(target.OnResolved(&err)); | 
| 363 | 365 | 
| 364   std::ostringstream out; | 366   std::ostringstream out; | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 386 | 388 | 
| 387   std::string out_str = out.str(); | 389   std::string out_str = out.str(); | 
| 388   EXPECT_EQ(expected, out_str); | 390   EXPECT_EQ(expected, out_str); | 
| 389 } | 391 } | 
| 390 | 392 | 
| 391 TEST(NinjaBinaryTargetWriter, SourceSetDataDeps) { | 393 TEST(NinjaBinaryTargetWriter, SourceSetDataDeps) { | 
| 392   Err err; | 394   Err err; | 
| 393   TestWithScope setup; | 395   TestWithScope setup; | 
| 394 | 396 | 
| 395   // This target is a data (runtime) dependency of the intermediate target. | 397   // This target is a data (runtime) dependency of the intermediate target. | 
| 396   Target data(setup.settings(), Label(SourceDir("//foo/"), "data_target")); | 398   Target data(setup.settings(), Label(SourceDir("//foo/"), "data_target"), {}); | 
| 397   data.set_output_type(Target::EXECUTABLE); | 399   data.set_output_type(Target::EXECUTABLE); | 
| 398   data.visibility().SetPublic(); | 400   data.visibility().SetPublic(); | 
| 399   data.SetToolchain(setup.toolchain()); | 401   data.SetToolchain(setup.toolchain()); | 
| 400   ASSERT_TRUE(data.OnResolved(&err)); | 402   ASSERT_TRUE(data.OnResolved(&err)); | 
| 401 | 403 | 
| 402   // Intermediate source set target. | 404   // Intermediate source set target. | 
| 403   Target inter(setup.settings(), Label(SourceDir("//foo/"), "inter")); | 405   Target inter(setup.settings(), Label(SourceDir("//foo/"), "inter"), {}); | 
| 404   inter.set_output_type(Target::SOURCE_SET); | 406   inter.set_output_type(Target::SOURCE_SET); | 
| 405   inter.visibility().SetPublic(); | 407   inter.visibility().SetPublic(); | 
| 406   inter.data_deps().push_back(LabelTargetPair(&data)); | 408   inter.data_deps().push_back(LabelTargetPair(&data)); | 
| 407   inter.SetToolchain(setup.toolchain()); | 409   inter.SetToolchain(setup.toolchain()); | 
| 408   inter.sources().push_back(SourceFile("//foo/inter.cc")); | 410   inter.sources().push_back(SourceFile("//foo/inter.cc")); | 
| 409   ASSERT_TRUE(inter.OnResolved(&err)) << err.message(); | 411   ASSERT_TRUE(inter.OnResolved(&err)) << err.message(); | 
| 410 | 412 | 
| 411   // Write out the intermediate target. | 413   // Write out the intermediate target. | 
| 412   std::ostringstream inter_out; | 414   std::ostringstream inter_out; | 
| 413   NinjaBinaryTargetWriter inter_writer(&inter, inter_out); | 415   NinjaBinaryTargetWriter inter_writer(&inter, inter_out); | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 425       "target_out_dir = obj/foo\n" | 427       "target_out_dir = obj/foo\n" | 
| 426       "target_output_name = inter\n" | 428       "target_output_name = inter\n" | 
| 427       "\n" | 429       "\n" | 
| 428       "build obj/foo/inter.inter.o: cxx ../../foo/inter.cc\n" | 430       "build obj/foo/inter.inter.o: cxx ../../foo/inter.cc\n" | 
| 429       "\n" | 431       "\n" | 
| 430       "build obj/foo/inter.stamp: stamp obj/foo/inter.inter.o || " | 432       "build obj/foo/inter.stamp: stamp obj/foo/inter.inter.o || " | 
| 431           "./data_target\n"; | 433           "./data_target\n"; | 
| 432   EXPECT_EQ(inter_expected, inter_out.str()); | 434   EXPECT_EQ(inter_expected, inter_out.str()); | 
| 433 | 435 | 
| 434   // Final target. | 436   // Final target. | 
| 435   Target exe(setup.settings(), Label(SourceDir("//foo/"), "exe")); | 437   Target exe(setup.settings(), Label(SourceDir("//foo/"), "exe"), {}); | 
| 436   exe.set_output_type(Target::EXECUTABLE); | 438   exe.set_output_type(Target::EXECUTABLE); | 
| 437   exe.public_deps().push_back(LabelTargetPair(&inter)); | 439   exe.public_deps().push_back(LabelTargetPair(&inter)); | 
| 438   exe.SetToolchain(setup.toolchain()); | 440   exe.SetToolchain(setup.toolchain()); | 
| 439   exe.sources().push_back(SourceFile("//foo/final.cc")); | 441   exe.sources().push_back(SourceFile("//foo/final.cc")); | 
| 440   ASSERT_TRUE(exe.OnResolved(&err)); | 442   ASSERT_TRUE(exe.OnResolved(&err)); | 
| 441 | 443 | 
| 442   std::ostringstream final_out; | 444   std::ostringstream final_out; | 
| 443   NinjaBinaryTargetWriter final_writer(&exe, final_out); | 445   NinjaBinaryTargetWriter final_writer(&exe, final_out); | 
| 444   final_writer.Run(); | 446   final_writer.Run(); | 
| 445 | 447 | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 465       "  libs =\n" | 467       "  libs =\n" | 
| 466       "  output_extension = \n" | 468       "  output_extension = \n" | 
| 467       "  output_dir = \n"; | 469       "  output_dir = \n"; | 
| 468   EXPECT_EQ(final_expected, final_out.str()); | 470   EXPECT_EQ(final_expected, final_out.str()); | 
| 469 } | 471 } | 
| 470 | 472 | 
| 471 TEST(NinjaBinaryTargetWriter, SharedLibraryModuleDefinitionFile) { | 473 TEST(NinjaBinaryTargetWriter, SharedLibraryModuleDefinitionFile) { | 
| 472   Err err; | 474   Err err; | 
| 473   TestWithScope setup; | 475   TestWithScope setup; | 
| 474 | 476 | 
| 475   Target shared_lib(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 477   Target shared_lib(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); | 
| 476   shared_lib.set_output_type(Target::SHARED_LIBRARY); | 478   shared_lib.set_output_type(Target::SHARED_LIBRARY); | 
| 477   shared_lib.SetToolchain(setup.toolchain()); | 479   shared_lib.SetToolchain(setup.toolchain()); | 
| 478   shared_lib.sources().push_back(SourceFile("//foo/sources.cc")); | 480   shared_lib.sources().push_back(SourceFile("//foo/sources.cc")); | 
| 479   shared_lib.sources().push_back(SourceFile("//foo/bar.def")); | 481   shared_lib.sources().push_back(SourceFile("//foo/bar.def")); | 
| 480   ASSERT_TRUE(shared_lib.OnResolved(&err)); | 482   ASSERT_TRUE(shared_lib.OnResolved(&err)); | 
| 481 | 483 | 
| 482   std::ostringstream out; | 484   std::ostringstream out; | 
| 483   NinjaBinaryTargetWriter writer(&shared_lib, out); | 485   NinjaBinaryTargetWriter writer(&shared_lib, out); | 
| 484   writer.Run(); | 486   writer.Run(); | 
| 485 | 487 | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 499       "  libs =\n" | 501       "  libs =\n" | 
| 500       "  output_extension = .so\n" | 502       "  output_extension = .so\n" | 
| 501       "  output_dir = \n"; | 503       "  output_dir = \n"; | 
| 502   EXPECT_EQ(expected, out.str()); | 504   EXPECT_EQ(expected, out.str()); | 
| 503 } | 505 } | 
| 504 | 506 | 
| 505 TEST(NinjaBinaryTargetWriter, LoadableModule) { | 507 TEST(NinjaBinaryTargetWriter, LoadableModule) { | 
| 506   Err err; | 508   Err err; | 
| 507   TestWithScope setup; | 509   TestWithScope setup; | 
| 508 | 510 | 
| 509   Target loadable_module(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 511   Target loadable_module(setup.settings(), Label(SourceDir("//foo/"), "bar"), | 
|  | 512                          {}); | 
| 510   loadable_module.set_output_type(Target::LOADABLE_MODULE); | 513   loadable_module.set_output_type(Target::LOADABLE_MODULE); | 
| 511   loadable_module.visibility().SetPublic(); | 514   loadable_module.visibility().SetPublic(); | 
| 512   loadable_module.SetToolchain(setup.toolchain()); | 515   loadable_module.SetToolchain(setup.toolchain()); | 
| 513   loadable_module.sources().push_back(SourceFile("//foo/sources.cc")); | 516   loadable_module.sources().push_back(SourceFile("//foo/sources.cc")); | 
| 514   ASSERT_TRUE(loadable_module.OnResolved(&err)) << err.message(); | 517   ASSERT_TRUE(loadable_module.OnResolved(&err)) << err.message(); | 
| 515 | 518 | 
| 516   std::ostringstream out; | 519   std::ostringstream out; | 
| 517   NinjaBinaryTargetWriter writer(&loadable_module, out); | 520   NinjaBinaryTargetWriter writer(&loadable_module, out); | 
| 518   writer.Run(); | 521   writer.Run(); | 
| 519 | 522 | 
| 520   const char loadable_expected[] = | 523   const char loadable_expected[] = | 
| 521       "defines =\n" | 524       "defines =\n" | 
| 522       "include_dirs =\n" | 525       "include_dirs =\n" | 
| 523       "cflags =\n" | 526       "cflags =\n" | 
| 524       "cflags_cc =\n" | 527       "cflags_cc =\n" | 
| 525       "root_out_dir = .\n" | 528       "root_out_dir = .\n" | 
| 526       "target_out_dir = obj/foo\n" | 529       "target_out_dir = obj/foo\n" | 
| 527       "target_output_name = libbar\n" | 530       "target_output_name = libbar\n" | 
| 528       "\n" | 531       "\n" | 
| 529       "build obj/foo/libbar.sources.o: cxx ../../foo/sources.cc\n" | 532       "build obj/foo/libbar.sources.o: cxx ../../foo/sources.cc\n" | 
| 530       "\n" | 533       "\n" | 
| 531       "build ./libbar.so: solink_module obj/foo/libbar.sources.o\n" | 534       "build ./libbar.so: solink_module obj/foo/libbar.sources.o\n" | 
| 532       "  ldflags =\n" | 535       "  ldflags =\n" | 
| 533       "  libs =\n" | 536       "  libs =\n" | 
| 534       "  output_extension = .so\n" | 537       "  output_extension = .so\n" | 
| 535       "  output_dir = \n"; | 538       "  output_dir = \n"; | 
| 536   EXPECT_EQ(loadable_expected, out.str()); | 539   EXPECT_EQ(loadable_expected, out.str()); | 
| 537 | 540 | 
| 538   // Final target. | 541   // Final target. | 
| 539   Target exe(setup.settings(), Label(SourceDir("//foo/"), "exe")); | 542   Target exe(setup.settings(), Label(SourceDir("//foo/"), "exe"), {}); | 
| 540   exe.set_output_type(Target::EXECUTABLE); | 543   exe.set_output_type(Target::EXECUTABLE); | 
| 541   exe.public_deps().push_back(LabelTargetPair(&loadable_module)); | 544   exe.public_deps().push_back(LabelTargetPair(&loadable_module)); | 
| 542   exe.SetToolchain(setup.toolchain()); | 545   exe.SetToolchain(setup.toolchain()); | 
| 543   exe.sources().push_back(SourceFile("//foo/final.cc")); | 546   exe.sources().push_back(SourceFile("//foo/final.cc")); | 
| 544   ASSERT_TRUE(exe.OnResolved(&err)) << err.message(); | 547   ASSERT_TRUE(exe.OnResolved(&err)) << err.message(); | 
| 545 | 548 | 
| 546   std::ostringstream final_out; | 549   std::ostringstream final_out; | 
| 547   NinjaBinaryTargetWriter final_writer(&exe, final_out); | 550   NinjaBinaryTargetWriter final_writer(&exe, final_out); | 
| 548   final_writer.Run(); | 551   final_writer.Run(); | 
| 549 | 552 | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 570 | 573 | 
| 571 TEST(NinjaBinaryTargetWriter, WinPrecompiledHeaders) { | 574 TEST(NinjaBinaryTargetWriter, WinPrecompiledHeaders) { | 
| 572   Err err; | 575   Err err; | 
| 573 | 576 | 
| 574   // This setup's toolchain does not have precompiled headers defined. | 577   // This setup's toolchain does not have precompiled headers defined. | 
| 575   TestWithScope setup; | 578   TestWithScope setup; | 
| 576 | 579 | 
| 577   // A precompiled header toolchain. | 580   // A precompiled header toolchain. | 
| 578   Settings pch_settings(setup.build_settings(), "withpch/"); | 581   Settings pch_settings(setup.build_settings(), "withpch/"); | 
| 579   Toolchain pch_toolchain(&pch_settings, | 582   Toolchain pch_toolchain(&pch_settings, | 
| 580                           Label(SourceDir("//toolchain/"), "withpch")); | 583                           Label(SourceDir("//toolchain/"), "withpch"), {}); | 
| 581   pch_settings.set_toolchain_label(pch_toolchain.label()); | 584   pch_settings.set_toolchain_label(pch_toolchain.label()); | 
| 582   pch_settings.set_default_toolchain_label(setup.toolchain()->label()); | 585   pch_settings.set_default_toolchain_label(setup.toolchain()->label()); | 
| 583 | 586 | 
| 584   // Declare a C++ compiler that supports PCH. | 587   // Declare a C++ compiler that supports PCH. | 
| 585   std::unique_ptr<Tool> cxx_tool(new Tool); | 588   std::unique_ptr<Tool> cxx_tool(new Tool); | 
| 586   TestWithScope::SetCommandForTool( | 589   TestWithScope::SetCommandForTool( | 
| 587       "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} " | 590       "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} " | 
| 588       "-o {{output}}", | 591       "-o {{output}}", | 
| 589       cxx_tool.get()); | 592       cxx_tool.get()); | 
| 590   cxx_tool->set_outputs(SubstitutionList::MakeForTest( | 593   cxx_tool->set_outputs(SubstitutionList::MakeForTest( | 
| 591       "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o")); | 594       "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o")); | 
| 592   cxx_tool->set_precompiled_header_type(Tool::PCH_MSVC); | 595   cxx_tool->set_precompiled_header_type(Tool::PCH_MSVC); | 
| 593   pch_toolchain.SetTool(Toolchain::TYPE_CXX, std::move(cxx_tool)); | 596   pch_toolchain.SetTool(Toolchain::TYPE_CXX, std::move(cxx_tool)); | 
| 594 | 597 | 
| 595   // Add a C compiler as well. | 598   // Add a C compiler as well. | 
| 596   std::unique_ptr<Tool> cc_tool(new Tool); | 599   std::unique_ptr<Tool> cc_tool(new Tool); | 
| 597   TestWithScope::SetCommandForTool( | 600   TestWithScope::SetCommandForTool( | 
| 598       "cc {{source}} {{cflags}} {{cflags_c}} {{defines}} {{include_dirs}} " | 601       "cc {{source}} {{cflags}} {{cflags_c}} {{defines}} {{include_dirs}} " | 
| 599       "-o {{output}}", | 602       "-o {{output}}", | 
| 600       cc_tool.get()); | 603       cc_tool.get()); | 
| 601   cc_tool->set_outputs(SubstitutionList::MakeForTest( | 604   cc_tool->set_outputs(SubstitutionList::MakeForTest( | 
| 602       "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o")); | 605       "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o")); | 
| 603   cc_tool->set_precompiled_header_type(Tool::PCH_MSVC); | 606   cc_tool->set_precompiled_header_type(Tool::PCH_MSVC); | 
| 604   pch_toolchain.SetTool(Toolchain::TYPE_CC, std::move(cc_tool)); | 607   pch_toolchain.SetTool(Toolchain::TYPE_CC, std::move(cc_tool)); | 
| 605   pch_toolchain.ToolchainSetupComplete(); | 608   pch_toolchain.ToolchainSetupComplete(); | 
| 606 | 609 | 
| 607   // This target doesn't specify precompiled headers. | 610   // This target doesn't specify precompiled headers. | 
| 608   { | 611   { | 
| 609     Target no_pch_target(&pch_settings, | 612     Target no_pch_target(&pch_settings, | 
| 610                          Label(SourceDir("//foo/"), "no_pch_target")); | 613                          Label(SourceDir("//foo/"), "no_pch_target"), {}); | 
| 611     no_pch_target.set_output_type(Target::SOURCE_SET); | 614     no_pch_target.set_output_type(Target::SOURCE_SET); | 
| 612     no_pch_target.visibility().SetPublic(); | 615     no_pch_target.visibility().SetPublic(); | 
| 613     no_pch_target.sources().push_back(SourceFile("//foo/input1.cc")); | 616     no_pch_target.sources().push_back(SourceFile("//foo/input1.cc")); | 
| 614     no_pch_target.sources().push_back(SourceFile("//foo/input2.c")); | 617     no_pch_target.sources().push_back(SourceFile("//foo/input2.c")); | 
| 615     no_pch_target.config_values().cflags_c().push_back("-std=c99"); | 618     no_pch_target.config_values().cflags_c().push_back("-std=c99"); | 
| 616     no_pch_target.SetToolchain(&pch_toolchain); | 619     no_pch_target.SetToolchain(&pch_toolchain); | 
| 617     ASSERT_TRUE(no_pch_target.OnResolved(&err)); | 620     ASSERT_TRUE(no_pch_target.OnResolved(&err)); | 
| 618 | 621 | 
| 619     std::ostringstream out; | 622     std::ostringstream out; | 
| 620     NinjaBinaryTargetWriter writer(&no_pch_target, out); | 623     NinjaBinaryTargetWriter writer(&no_pch_target, out); | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 634                "withpch_cc ../../foo/input2.c\n" | 637                "withpch_cc ../../foo/input2.c\n" | 
| 635         "\n" | 638         "\n" | 
| 636         "build withpch/obj/foo/no_pch_target.stamp: " | 639         "build withpch/obj/foo/no_pch_target.stamp: " | 
| 637                "withpch_stamp withpch/obj/foo/no_pch_target.input1.o " | 640                "withpch_stamp withpch/obj/foo/no_pch_target.input1.o " | 
| 638                "withpch/obj/foo/no_pch_target.input2.o\n"; | 641                "withpch/obj/foo/no_pch_target.input2.o\n"; | 
| 639     EXPECT_EQ(no_pch_expected, out.str()); | 642     EXPECT_EQ(no_pch_expected, out.str()); | 
| 640   } | 643   } | 
| 641 | 644 | 
| 642   // This target specifies PCH. | 645   // This target specifies PCH. | 
| 643   { | 646   { | 
| 644     Target pch_target(&pch_settings, | 647     Target pch_target(&pch_settings, Label(SourceDir("//foo/"), "pch_target"), | 
| 645                       Label(SourceDir("//foo/"), "pch_target")); | 648                       {}); | 
| 646     pch_target.config_values().set_precompiled_header("build/precompile.h"); | 649     pch_target.config_values().set_precompiled_header("build/precompile.h"); | 
| 647     pch_target.config_values().set_precompiled_source( | 650     pch_target.config_values().set_precompiled_source( | 
| 648         SourceFile("//build/precompile.cc")); | 651         SourceFile("//build/precompile.cc")); | 
| 649     pch_target.set_output_type(Target::SOURCE_SET); | 652     pch_target.set_output_type(Target::SOURCE_SET); | 
| 650     pch_target.visibility().SetPublic(); | 653     pch_target.visibility().SetPublic(); | 
| 651     pch_target.sources().push_back(SourceFile("//foo/input1.cc")); | 654     pch_target.sources().push_back(SourceFile("//foo/input1.cc")); | 
| 652     pch_target.sources().push_back(SourceFile("//foo/input2.c")); | 655     pch_target.sources().push_back(SourceFile("//foo/input2.c")); | 
| 653     pch_target.SetToolchain(&pch_toolchain); | 656     pch_target.SetToolchain(&pch_toolchain); | 
| 654     ASSERT_TRUE(pch_target.OnResolved(&err)); | 657     ASSERT_TRUE(pch_target.OnResolved(&err)); | 
| 655 | 658 | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 698 | 701 | 
| 699 TEST(NinjaBinaryTargetWriter, GCCPrecompiledHeaders) { | 702 TEST(NinjaBinaryTargetWriter, GCCPrecompiledHeaders) { | 
| 700   Err err; | 703   Err err; | 
| 701 | 704 | 
| 702   // This setup's toolchain does not have precompiled headers defined. | 705   // This setup's toolchain does not have precompiled headers defined. | 
| 703   TestWithScope setup; | 706   TestWithScope setup; | 
| 704 | 707 | 
| 705   // A precompiled header toolchain. | 708   // A precompiled header toolchain. | 
| 706   Settings pch_settings(setup.build_settings(), "withpch/"); | 709   Settings pch_settings(setup.build_settings(), "withpch/"); | 
| 707   Toolchain pch_toolchain(&pch_settings, | 710   Toolchain pch_toolchain(&pch_settings, | 
| 708                           Label(SourceDir("//toolchain/"), "withpch")); | 711                           Label(SourceDir("//toolchain/"), "withpch"), {}); | 
| 709   pch_settings.set_toolchain_label(pch_toolchain.label()); | 712   pch_settings.set_toolchain_label(pch_toolchain.label()); | 
| 710   pch_settings.set_default_toolchain_label(setup.toolchain()->label()); | 713   pch_settings.set_default_toolchain_label(setup.toolchain()->label()); | 
| 711 | 714 | 
| 712   // Declare a C++ compiler that supports PCH. | 715   // Declare a C++ compiler that supports PCH. | 
| 713   std::unique_ptr<Tool> cxx_tool(new Tool); | 716   std::unique_ptr<Tool> cxx_tool(new Tool); | 
| 714   TestWithScope::SetCommandForTool( | 717   TestWithScope::SetCommandForTool( | 
| 715       "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} " | 718       "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} " | 
| 716       "-o {{output}}", | 719       "-o {{output}}", | 
| 717       cxx_tool.get()); | 720       cxx_tool.get()); | 
| 718   cxx_tool->set_outputs(SubstitutionList::MakeForTest( | 721   cxx_tool->set_outputs(SubstitutionList::MakeForTest( | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 729       cc_tool.get()); | 732       cc_tool.get()); | 
| 730   cc_tool->set_outputs(SubstitutionList::MakeForTest( | 733   cc_tool->set_outputs(SubstitutionList::MakeForTest( | 
| 731       "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o")); | 734       "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o")); | 
| 732   cc_tool->set_precompiled_header_type(Tool::PCH_GCC); | 735   cc_tool->set_precompiled_header_type(Tool::PCH_GCC); | 
| 733   pch_toolchain.SetTool(Toolchain::TYPE_CC, std::move(cc_tool)); | 736   pch_toolchain.SetTool(Toolchain::TYPE_CC, std::move(cc_tool)); | 
| 734   pch_toolchain.ToolchainSetupComplete(); | 737   pch_toolchain.ToolchainSetupComplete(); | 
| 735 | 738 | 
| 736   // This target doesn't specify precompiled headers. | 739   // This target doesn't specify precompiled headers. | 
| 737   { | 740   { | 
| 738     Target no_pch_target(&pch_settings, | 741     Target no_pch_target(&pch_settings, | 
| 739                          Label(SourceDir("//foo/"), "no_pch_target")); | 742                          Label(SourceDir("//foo/"), "no_pch_target"), {}); | 
| 740     no_pch_target.set_output_type(Target::SOURCE_SET); | 743     no_pch_target.set_output_type(Target::SOURCE_SET); | 
| 741     no_pch_target.visibility().SetPublic(); | 744     no_pch_target.visibility().SetPublic(); | 
| 742     no_pch_target.sources().push_back(SourceFile("//foo/input1.cc")); | 745     no_pch_target.sources().push_back(SourceFile("//foo/input1.cc")); | 
| 743     no_pch_target.sources().push_back(SourceFile("//foo/input2.c")); | 746     no_pch_target.sources().push_back(SourceFile("//foo/input2.c")); | 
| 744     no_pch_target.config_values().cflags_c().push_back("-std=c99"); | 747     no_pch_target.config_values().cflags_c().push_back("-std=c99"); | 
| 745     no_pch_target.SetToolchain(&pch_toolchain); | 748     no_pch_target.SetToolchain(&pch_toolchain); | 
| 746     ASSERT_TRUE(no_pch_target.OnResolved(&err)); | 749     ASSERT_TRUE(no_pch_target.OnResolved(&err)); | 
| 747 | 750 | 
| 748     std::ostringstream out; | 751     std::ostringstream out; | 
| 749     NinjaBinaryTargetWriter writer(&no_pch_target, out); | 752     NinjaBinaryTargetWriter writer(&no_pch_target, out); | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 763                "withpch_cc ../../foo/input2.c\n" | 766                "withpch_cc ../../foo/input2.c\n" | 
| 764         "\n" | 767         "\n" | 
| 765         "build withpch/obj/foo/no_pch_target.stamp: " | 768         "build withpch/obj/foo/no_pch_target.stamp: " | 
| 766                "withpch_stamp withpch/obj/foo/no_pch_target.input1.o " | 769                "withpch_stamp withpch/obj/foo/no_pch_target.input1.o " | 
| 767                "withpch/obj/foo/no_pch_target.input2.o\n"; | 770                "withpch/obj/foo/no_pch_target.input2.o\n"; | 
| 768     EXPECT_EQ(no_pch_expected, out.str()); | 771     EXPECT_EQ(no_pch_expected, out.str()); | 
| 769   } | 772   } | 
| 770 | 773 | 
| 771   // This target specifies PCH. | 774   // This target specifies PCH. | 
| 772   { | 775   { | 
| 773     Target pch_target(&pch_settings, | 776     Target pch_target(&pch_settings, Label(SourceDir("//foo/"), "pch_target"), | 
| 774                       Label(SourceDir("//foo/"), "pch_target")); | 777                       {}); | 
| 775     pch_target.config_values().set_precompiled_source( | 778     pch_target.config_values().set_precompiled_source( | 
| 776         SourceFile("//build/precompile.h")); | 779         SourceFile("//build/precompile.h")); | 
| 777     pch_target.config_values().cflags_c().push_back("-std=c99"); | 780     pch_target.config_values().cflags_c().push_back("-std=c99"); | 
| 778     pch_target.set_output_type(Target::SOURCE_SET); | 781     pch_target.set_output_type(Target::SOURCE_SET); | 
| 779     pch_target.visibility().SetPublic(); | 782     pch_target.visibility().SetPublic(); | 
| 780     pch_target.sources().push_back(SourceFile("//foo/input1.cc")); | 783     pch_target.sources().push_back(SourceFile("//foo/input1.cc")); | 
| 781     pch_target.sources().push_back(SourceFile("//foo/input2.c")); | 784     pch_target.sources().push_back(SourceFile("//foo/input2.c")); | 
| 782     pch_target.SetToolchain(&pch_toolchain); | 785     pch_target.SetToolchain(&pch_toolchain); | 
| 783     ASSERT_TRUE(pch_target.OnResolved(&err)); | 786     ASSERT_TRUE(pch_target.OnResolved(&err)); | 
| 784 | 787 | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 841 } | 844 } | 
| 842 | 845 | 
| 843 // This tests that output extension and output dir overrides apply, and input | 846 // This tests that output extension and output dir overrides apply, and input | 
| 844 // dependencies are applied. | 847 // dependencies are applied. | 
| 845 TEST(NinjaBinaryTargetWriter, InputFiles) { | 848 TEST(NinjaBinaryTargetWriter, InputFiles) { | 
| 846   Err err; | 849   Err err; | 
| 847   TestWithScope setup; | 850   TestWithScope setup; | 
| 848 | 851 | 
| 849   // This target has one input. | 852   // This target has one input. | 
| 850   { | 853   { | 
| 851     Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 854     Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); | 
| 852     target.set_output_type(Target::SOURCE_SET); | 855     target.set_output_type(Target::SOURCE_SET); | 
| 853     target.visibility().SetPublic(); | 856     target.visibility().SetPublic(); | 
| 854     target.sources().push_back(SourceFile("//foo/input1.cc")); | 857     target.sources().push_back(SourceFile("//foo/input1.cc")); | 
| 855     target.sources().push_back(SourceFile("//foo/input2.cc")); | 858     target.sources().push_back(SourceFile("//foo/input2.cc")); | 
| 856     target.inputs().push_back(SourceFile("//foo/input.data")); | 859     target.inputs().push_back(SourceFile("//foo/input.data")); | 
| 857     target.SetToolchain(setup.toolchain()); | 860     target.SetToolchain(setup.toolchain()); | 
| 858     ASSERT_TRUE(target.OnResolved(&err)); | 861     ASSERT_TRUE(target.OnResolved(&err)); | 
| 859 | 862 | 
| 860     std::ostringstream out; | 863     std::ostringstream out; | 
| 861     NinjaBinaryTargetWriter writer(&target, out); | 864     NinjaBinaryTargetWriter writer(&target, out); | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 876           " | ../../foo/input.data\n" | 879           " | ../../foo/input.data\n" | 
| 877         "\n" | 880         "\n" | 
| 878         "build obj/foo/bar.stamp: stamp obj/foo/bar.input1.o " | 881         "build obj/foo/bar.stamp: stamp obj/foo/bar.input1.o " | 
| 879             "obj/foo/bar.input2.o\n"; | 882             "obj/foo/bar.input2.o\n"; | 
| 880 | 883 | 
| 881     EXPECT_EQ(expected, out.str()); | 884     EXPECT_EQ(expected, out.str()); | 
| 882   } | 885   } | 
| 883 | 886 | 
| 884   // This target has multiple inputs. | 887   // This target has multiple inputs. | 
| 885   { | 888   { | 
| 886     Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 889     Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); | 
| 887     target.set_output_type(Target::SOURCE_SET); | 890     target.set_output_type(Target::SOURCE_SET); | 
| 888     target.visibility().SetPublic(); | 891     target.visibility().SetPublic(); | 
| 889     target.sources().push_back(SourceFile("//foo/input1.cc")); | 892     target.sources().push_back(SourceFile("//foo/input1.cc")); | 
| 890     target.sources().push_back(SourceFile("//foo/input2.cc")); | 893     target.sources().push_back(SourceFile("//foo/input2.cc")); | 
| 891     target.inputs().push_back(SourceFile("//foo/input1.data")); | 894     target.inputs().push_back(SourceFile("//foo/input1.data")); | 
| 892     target.inputs().push_back(SourceFile("//foo/input2.data")); | 895     target.inputs().push_back(SourceFile("//foo/input2.data")); | 
| 893     target.SetToolchain(setup.toolchain()); | 896     target.SetToolchain(setup.toolchain()); | 
| 894     ASSERT_TRUE(target.OnResolved(&err)); | 897     ASSERT_TRUE(target.OnResolved(&err)); | 
| 895 | 898 | 
| 896     std::ostringstream out; | 899     std::ostringstream out; | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 912           " | obj/foo/bar.inputs.stamp\n" | 915           " | obj/foo/bar.inputs.stamp\n" | 
| 913         "build obj/foo/bar.input2.o: cxx ../../foo/input2.cc" | 916         "build obj/foo/bar.input2.o: cxx ../../foo/input2.cc" | 
| 914           " | obj/foo/bar.inputs.stamp\n" | 917           " | obj/foo/bar.inputs.stamp\n" | 
| 915         "\n" | 918         "\n" | 
| 916         "build obj/foo/bar.stamp: stamp obj/foo/bar.input1.o " | 919         "build obj/foo/bar.stamp: stamp obj/foo/bar.input1.o " | 
| 917             "obj/foo/bar.input2.o\n"; | 920             "obj/foo/bar.input2.o\n"; | 
| 918 | 921 | 
| 919     EXPECT_EQ(expected, out.str()); | 922     EXPECT_EQ(expected, out.str()); | 
| 920   } | 923   } | 
| 921 } | 924 } | 
| OLD | NEW | 
|---|