| Index: tools/gn/ninja_binary_target_writer_unittest.cc
|
| diff --git a/tools/gn/ninja_binary_target_writer_unittest.cc b/tools/gn/ninja_binary_target_writer_unittest.cc
|
| index 5438c4dc6bd463db230cf98c94ad79bfb30fa81c..fbd21982e7b5329684ae27413bb870a6fc753ad0 100644
|
| --- a/tools/gn/ninja_binary_target_writer_unittest.cc
|
| +++ b/tools/gn/ninja_binary_target_writer_unittest.cc
|
| @@ -461,6 +461,100 @@ TEST(NinjaBinaryTargetWriter, WinPrecompiledHeaders) {
|
| }
|
| }
|
|
|
| +TEST(NinjaBinaryTargetWriter, GCCPrecompiledHeaders) {
|
| + Err err;
|
| +
|
| + // This setup's toolchain does not have precompiled headers defined.
|
| + TestWithScope setup;
|
| +
|
| + // A precompiled header toolchain.
|
| + Settings pch_settings(setup.build_settings(), "withpch/");
|
| + Toolchain pch_toolchain(&pch_settings,
|
| + Label(SourceDir("//toolchain/"), "withpch"));
|
| +
|
| + // Declare a C++ compiler that supports PCH.
|
| + scoped_ptr<Tool> cxx_tool(new Tool);
|
| + TestWithScope::SetCommandForTool(
|
| + "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} "
|
| + "-o {{output}}",
|
| + cxx_tool.get());
|
| + cxx_tool->set_outputs(SubstitutionList::MakeForTest(
|
| + "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o"));
|
| + cxx_tool->set_precompiled_header_type(Tool::PCH_GCC);
|
| + pch_toolchain.SetTool(Toolchain::TYPE_CXX, cxx_tool.Pass());
|
| + pch_toolchain.ToolchainSetupComplete();
|
| +
|
| + // This target doesn't specify precompiled headers.
|
| + {
|
| + Target no_pch_target(&pch_settings,
|
| + Label(SourceDir("//foo/"), "no_pch_target"));
|
| + no_pch_target.set_output_type(Target::SOURCE_SET);
|
| + no_pch_target.visibility().SetPublic();
|
| + no_pch_target.sources().push_back(SourceFile("//foo/input1.cc"));
|
| + no_pch_target.SetToolchain(&pch_toolchain);
|
| + ASSERT_TRUE(no_pch_target.OnResolved(&err));
|
| +
|
| + std::ostringstream out;
|
| + NinjaBinaryTargetWriter writer(&no_pch_target, out);
|
| + writer.Run();
|
| +
|
| + const char no_pch_expected[] =
|
| + "defines =\n"
|
| + "include_dirs =\n"
|
| + "cflags =\n"
|
| + "cflags_cc =\n"
|
| + "target_output_name = no_pch_target\n"
|
| + "\n"
|
| + "build withpch/obj/foo/no_pch_target.input1.o: "
|
| + "cxx ../../foo/input1.cc\n"
|
| + "\n"
|
| + "build withpch/obj/foo/no_pch_target.stamp: "
|
| + "stamp withpch/obj/foo/no_pch_target.input1.o\n";
|
| + EXPECT_EQ(no_pch_expected, out.str());
|
| + }
|
| +
|
| + // This target specifies PCH.
|
| + {
|
| + Target pch_target(&pch_settings,
|
| + Label(SourceDir("//foo/"), "pch_target"));
|
| + pch_target.config_values().set_precompiled_header("build/precompile.h");
|
| + pch_target.config_values().set_precompiled_source(
|
| + SourceFile("//build/precompile.h"));
|
| + pch_target.set_output_type(Target::SOURCE_SET);
|
| + pch_target.visibility().SetPublic();
|
| + pch_target.sources().push_back(SourceFile("//foo/input1.cc"));
|
| + pch_target.SetToolchain(&pch_toolchain);
|
| + ASSERT_TRUE(pch_target.OnResolved(&err));
|
| +
|
| + std::ostringstream out;
|
| + NinjaBinaryTargetWriter writer(&pch_target, out);
|
| + writer.Run();
|
| +
|
| + const char pch_gcc_expected[] =
|
| + "defines =\n"
|
| + "include_dirs =\n"
|
| + "cflags =\n"
|
| + "cflags_cc =\n"
|
| + "target_output_name = pch_target\n"
|
| + "\n"
|
| + // Compile the precompiled source with -x <lang>.
|
| + "build withpch/obj/build/pch_target.precompile.cc.o: "
|
| + "cxx ../../build/precompile.h\n"
|
| + " cflags_cc = ${cflags_cc} -x c++-header\n"
|
| + "\n"
|
| + "build withpch/obj/foo/pch_target.input1.o: "
|
| + "cxx ../../foo/input1.cc | "
|
| + // Explicit dependency on the PCH build step.
|
| + "withpch/obj/build/pch_target.precompile.cc.o\n"
|
| + "\n"
|
| + "build withpch/obj/foo/pch_target.stamp: "
|
| + "stamp withpch/obj/foo/pch_target.input1.o "
|
| + // The precompiled object file was added to the outputs.
|
| + "withpch/obj/build/pch_target.precompile.cc.o\n";
|
| + EXPECT_EQ(pch_gcc_expected, out.str());
|
| + }
|
| +}
|
| +
|
| // Should throw an error with the scheduler if a duplicate object file exists.
|
| // This is dependent on the toolchain's object file mapping.
|
| TEST(NinjaBinaryTargetWriter, DupeObjFileError) {
|
|
|