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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "tools/gn/ninja_binary_target_writer.h" | 8 #include "tools/gn/ninja_binary_target_writer.h" |
9 #include "tools/gn/scheduler.h" | 9 #include "tools/gn/scheduler.h" |
10 #include "tools/gn/target.h" | 10 #include "tools/gn/target.h" |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 "\n" | 358 "\n" |
359 "build obj/foo/libbar.sources.o: cxx ../../foo/sources.cc\n" | 359 "build obj/foo/libbar.sources.o: cxx ../../foo/sources.cc\n" |
360 "\n" | 360 "\n" |
361 "build ./libbar.so: solink obj/foo/libbar.sources.o | ../../foo/bar.def\n" | 361 "build ./libbar.so: solink obj/foo/libbar.sources.o | ../../foo/bar.def\n" |
362 " ldflags = /DEF:../../foo/bar.def\n" | 362 " ldflags = /DEF:../../foo/bar.def\n" |
363 " libs =\n" | 363 " libs =\n" |
364 " output_extension = .so\n"; | 364 " output_extension = .so\n"; |
365 EXPECT_EQ(expected, out.str()); | 365 EXPECT_EQ(expected, out.str()); |
366 } | 366 } |
367 | 367 |
| 368 TEST(NinjaBinaryTargetWriter, LoadableModule) { |
| 369 TestWithScope setup; |
| 370 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 371 |
| 372 Target loadable_module(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 373 loadable_module.set_output_type(Target::LOADABLE_MODULE); |
| 374 loadable_module.visibility().SetPublic(); |
| 375 loadable_module.SetToolchain(setup.toolchain()); |
| 376 loadable_module.sources().push_back(SourceFile("//foo/sources.cc")); |
| 377 |
| 378 Err err; |
| 379 ASSERT_TRUE(loadable_module.OnResolved(&err)) << err.message(); |
| 380 |
| 381 std::ostringstream out; |
| 382 NinjaBinaryTargetWriter writer(&loadable_module, out); |
| 383 writer.Run(); |
| 384 |
| 385 const char loadable_expected[] = |
| 386 "defines =\n" |
| 387 "include_dirs =\n" |
| 388 "cflags =\n" |
| 389 "cflags_cc =\n" |
| 390 "root_out_dir = .\n" |
| 391 "target_out_dir = obj/foo\n" |
| 392 "target_output_name = libbar\n" |
| 393 "\n" |
| 394 "build obj/foo/libbar.sources.o: cxx ../../foo/sources.cc\n" |
| 395 "\n" |
| 396 "build ./libbar.so: solink_module obj/foo/libbar.sources.o\n" |
| 397 " ldflags =\n" |
| 398 " libs =\n" |
| 399 " output_extension = .so\n"; |
| 400 EXPECT_EQ(loadable_expected, out.str()); |
| 401 |
| 402 // Final target. |
| 403 Target exe(setup.settings(), Label(SourceDir("//foo/"), "exe")); |
| 404 exe.set_output_type(Target::EXECUTABLE); |
| 405 exe.public_deps().push_back(LabelTargetPair(&loadable_module)); |
| 406 exe.SetToolchain(setup.toolchain()); |
| 407 exe.sources().push_back(SourceFile("//foo/final.cc")); |
| 408 ASSERT_TRUE(exe.OnResolved(&err)) << err.message(); |
| 409 |
| 410 std::ostringstream final_out; |
| 411 NinjaBinaryTargetWriter final_writer(&exe, final_out); |
| 412 final_writer.Run(); |
| 413 |
| 414 // The final output depends on the loadable module so should have an |
| 415 // order-only dependency on the loadable modules's output file. |
| 416 const char final_expected[] = |
| 417 "defines =\n" |
| 418 "include_dirs =\n" |
| 419 "cflags =\n" |
| 420 "cflags_cc =\n" |
| 421 "root_out_dir = .\n" |
| 422 "target_out_dir = obj/foo\n" |
| 423 "target_output_name = exe\n" |
| 424 "\n" |
| 425 "build obj/foo/exe.final.o: cxx ../../foo/final.cc\n" |
| 426 "\n" |
| 427 "build ./exe: link obj/foo/exe.final.o || ./libbar.so\n" |
| 428 " ldflags =\n" |
| 429 " libs =\n" |
| 430 " output_extension = \n"; |
| 431 EXPECT_EQ(final_expected, final_out.str()); |
| 432 } |
| 433 |
368 TEST(NinjaBinaryTargetWriter, WinPrecompiledHeaders) { | 434 TEST(NinjaBinaryTargetWriter, WinPrecompiledHeaders) { |
369 Err err; | 435 Err err; |
370 | 436 |
371 // This setup's toolchain does not have precompiled headers defined. | 437 // This setup's toolchain does not have precompiled headers defined. |
372 TestWithScope setup; | 438 TestWithScope setup; |
373 | 439 |
374 // A precompiled header toolchain. | 440 // A precompiled header toolchain. |
375 Settings pch_settings(setup.build_settings(), "withpch/"); | 441 Settings pch_settings(setup.build_settings(), "withpch/"); |
376 Toolchain pch_toolchain(&pch_settings, | 442 Toolchain pch_toolchain(&pch_settings, |
377 Label(SourceDir("//toolchain/"), "withpch")); | 443 Label(SourceDir("//toolchain/"), "withpch")); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 | 696 |
631 EXPECT_FALSE(scheduler.is_failed()); | 697 EXPECT_FALSE(scheduler.is_failed()); |
632 | 698 |
633 std::ostringstream out; | 699 std::ostringstream out; |
634 NinjaBinaryTargetWriter writer(&target, out); | 700 NinjaBinaryTargetWriter writer(&target, out); |
635 writer.Run(); | 701 writer.Run(); |
636 | 702 |
637 // Should have issued an error. | 703 // Should have issued an error. |
638 EXPECT_TRUE(scheduler.is_failed()); | 704 EXPECT_TRUE(scheduler.is_failed()); |
639 } | 705 } |
OLD | NEW |