| 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 TEST(NinjaBinaryTargetWriter, WinPrecompiledHeaders) { | 368 TEST(NinjaBinaryTargetWriter, WinPrecompiledHeaders) { |
| 369 Err err; | 369 Err err; |
| 370 | 370 |
| 371 // This setup's toolchain does not have precompiled headers defined. | 371 // This setup's toolchain does not have precompiled headers defined. |
| 372 TestWithScope setup; | 372 TestWithScope setup; |
| 373 | 373 |
| 374 // A precompiled header toolchain. | 374 // A precompiled header toolchain. |
| 375 Settings pch_settings(setup.build_settings(), "withpch/"); | 375 Settings pch_settings(setup.build_settings(), "withpch/"); |
| 376 Toolchain pch_toolchain(&pch_settings, | 376 Toolchain pch_toolchain(&pch_settings, |
| 377 Label(SourceDir("//toolchain/"), "withpch")); | 377 Label(SourceDir("//toolchain/"), "withpch")); |
| 378 pch_settings.set_toolchain_label(pch_toolchain.label()); |
| 379 pch_settings.set_default_toolchain_label(setup.toolchain()->label()); |
| 378 | 380 |
| 379 // Declare a C++ compiler that supports PCH. | 381 // Declare a C++ compiler that supports PCH. |
| 380 scoped_ptr<Tool> cxx_tool(new Tool); | 382 scoped_ptr<Tool> cxx_tool(new Tool); |
| 381 TestWithScope::SetCommandForTool( | 383 TestWithScope::SetCommandForTool( |
| 382 "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} " | 384 "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} " |
| 383 "-o {{output}}", | 385 "-o {{output}}", |
| 384 cxx_tool.get()); | 386 cxx_tool.get()); |
| 385 cxx_tool->set_outputs(SubstitutionList::MakeForTest( | 387 cxx_tool->set_outputs(SubstitutionList::MakeForTest( |
| 386 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o")); | 388 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o")); |
| 387 cxx_tool->set_precompiled_header_type(Tool::PCH_MSVC); | 389 cxx_tool->set_precompiled_header_type(Tool::PCH_MSVC); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 403 writer.Run(); | 405 writer.Run(); |
| 404 | 406 |
| 405 const char no_pch_expected[] = | 407 const char no_pch_expected[] = |
| 406 "defines =\n" | 408 "defines =\n" |
| 407 "include_dirs =\n" | 409 "include_dirs =\n" |
| 408 "cflags =\n" | 410 "cflags =\n" |
| 409 "cflags_cc =\n" | 411 "cflags_cc =\n" |
| 410 "target_output_name = no_pch_target\n" | 412 "target_output_name = no_pch_target\n" |
| 411 "\n" | 413 "\n" |
| 412 "build withpch/obj/foo/no_pch_target.input1.o: " | 414 "build withpch/obj/foo/no_pch_target.input1.o: " |
| 413 "cxx ../../foo/input1.cc\n" | 415 "withpch_cxx ../../foo/input1.cc\n" |
| 414 "\n" | 416 "\n" |
| 415 "build withpch/obj/foo/no_pch_target.stamp: " | 417 "build withpch/obj/foo/no_pch_target.stamp: " |
| 416 "stamp withpch/obj/foo/no_pch_target.input1.o\n"; | 418 "withpch_stamp withpch/obj/foo/no_pch_target.input1.o\n"; |
| 417 EXPECT_EQ(no_pch_expected, out.str()); | 419 EXPECT_EQ(no_pch_expected, out.str()); |
| 418 } | 420 } |
| 419 | 421 |
| 420 // This target specifies PCH. | 422 // This target specifies PCH. |
| 421 { | 423 { |
| 422 Target pch_target(&pch_settings, | 424 Target pch_target(&pch_settings, |
| 423 Label(SourceDir("//foo/"), "pch_target")); | 425 Label(SourceDir("//foo/"), "pch_target")); |
| 424 pch_target.config_values().set_precompiled_header("build/precompile.h"); | 426 pch_target.config_values().set_precompiled_header("build/precompile.h"); |
| 425 pch_target.config_values().set_precompiled_source( | 427 pch_target.config_values().set_precompiled_source( |
| 426 SourceFile("//build/precompile.cc")); | 428 SourceFile("//build/precompile.cc")); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 438 "defines =\n" | 440 "defines =\n" |
| 439 "include_dirs =\n" | 441 "include_dirs =\n" |
| 440 "cflags =\n" | 442 "cflags =\n" |
| 441 // There should only be one .pch file created, for C++ files. | 443 // There should only be one .pch file created, for C++ files. |
| 442 "cflags_cc = /Fpwithpch/obj/foo/pch_target_cc.pch " | 444 "cflags_cc = /Fpwithpch/obj/foo/pch_target_cc.pch " |
| 443 "/Yubuild/precompile.h\n" | 445 "/Yubuild/precompile.h\n" |
| 444 "target_output_name = pch_target\n" | 446 "target_output_name = pch_target\n" |
| 445 "\n" | 447 "\n" |
| 446 // Compile the precompiled source file with /Yc. | 448 // Compile the precompiled source file with /Yc. |
| 447 "build withpch/obj/build/pch_target.precompile.cc.o: " | 449 "build withpch/obj/build/pch_target.precompile.cc.o: " |
| 448 "cxx ../../build/precompile.cc\n" | 450 "withpch_cxx ../../build/precompile.cc\n" |
| 449 " cflags_cc = ${cflags_cc} /Ycbuild/precompile.h\n" | 451 " cflags_cc = ${cflags_cc} /Ycbuild/precompile.h\n" |
| 450 "\n" | 452 "\n" |
| 451 "build withpch/obj/foo/pch_target.input1.o: " | 453 "build withpch/obj/foo/pch_target.input1.o: " |
| 452 "cxx ../../foo/input1.cc | " | 454 "withpch_cxx ../../foo/input1.cc | " |
| 453 // Explicit dependency on the PCH build step. | 455 // Explicit dependency on the PCH build step. |
| 454 "withpch/obj/build/pch_target.precompile.cc.o\n" | 456 "withpch/obj/build/pch_target.precompile.cc.o\n" |
| 455 "\n" | 457 "\n" |
| 456 "build withpch/obj/foo/pch_target.stamp: " | 458 "build withpch/obj/foo/pch_target.stamp: " |
| 457 "stamp withpch/obj/foo/pch_target.input1.o " | 459 "withpch_stamp withpch/obj/foo/pch_target.input1.o " |
| 458 // The precompiled object file was added to the outputs. | 460 // The precompiled object file was added to the outputs. |
| 459 "withpch/obj/build/pch_target.precompile.cc.o\n"; | 461 "withpch/obj/build/pch_target.precompile.cc.o\n"; |
| 460 EXPECT_EQ(pch_win_expected, out.str()); | 462 EXPECT_EQ(pch_win_expected, out.str()); |
| 461 } | 463 } |
| 462 } | 464 } |
| 463 | 465 |
| 464 // Should throw an error with the scheduler if a duplicate object file exists. | 466 // Should throw an error with the scheduler if a duplicate object file exists. |
| 465 // This is dependent on the toolchain's object file mapping. | 467 // This is dependent on the toolchain's object file mapping. |
| 466 TEST(NinjaBinaryTargetWriter, DupeObjFileError) { | 468 TEST(NinjaBinaryTargetWriter, DupeObjFileError) { |
| 467 Scheduler scheduler; | 469 Scheduler scheduler; |
| 468 | 470 |
| 469 TestWithScope setup; | 471 TestWithScope setup; |
| 470 TestTarget target(setup, "//foo:bar", Target::EXECUTABLE); | 472 TestTarget target(setup, "//foo:bar", Target::EXECUTABLE); |
| 471 target.sources().push_back(SourceFile("//a.cc")); | 473 target.sources().push_back(SourceFile("//a.cc")); |
| 472 target.sources().push_back(SourceFile("//a.cc")); | 474 target.sources().push_back(SourceFile("//a.cc")); |
| 473 | 475 |
| 474 EXPECT_FALSE(scheduler.is_failed()); | 476 EXPECT_FALSE(scheduler.is_failed()); |
| 475 | 477 |
| 476 std::ostringstream out; | 478 std::ostringstream out; |
| 477 NinjaBinaryTargetWriter writer(&target, out); | 479 NinjaBinaryTargetWriter writer(&target, out); |
| 478 writer.Run(); | 480 writer.Run(); |
| 479 | 481 |
| 480 // Should have issued an error. | 482 // Should have issued an error. |
| 481 EXPECT_TRUE(scheduler.is_failed()); | 483 EXPECT_TRUE(scheduler.is_failed()); |
| 482 } | 484 } |
| OLD | NEW |