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

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

Issue 1292983004: [GN]: Precompiled header support for GCC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: switch statement. error handling. some initial docs. Created 5 years, 4 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
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 <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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 "withpch/obj/build/pch_target.precompile.cc.o\n" 454 "withpch/obj/build/pch_target.precompile.cc.o\n"
455 "\n" 455 "\n"
456 "build withpch/obj/foo/pch_target.stamp: " 456 "build withpch/obj/foo/pch_target.stamp: "
457 "stamp withpch/obj/foo/pch_target.input1.o " 457 "stamp withpch/obj/foo/pch_target.input1.o "
458 // The precompiled object file was added to the outputs. 458 // The precompiled object file was added to the outputs.
459 "withpch/obj/build/pch_target.precompile.cc.o\n"; 459 "withpch/obj/build/pch_target.precompile.cc.o\n";
460 EXPECT_EQ(pch_win_expected, out.str()); 460 EXPECT_EQ(pch_win_expected, out.str());
461 } 461 }
462 } 462 }
463 463
464 TEST(NinjaBinaryTargetWriter, GCCPrecompiledHeaders) {
465 Err err;
466
467 // This setup's toolchain does not have precompiled headers defined.
468 TestWithScope setup;
469
470 // A precompiled header toolchain.
471 Settings pch_settings(setup.build_settings(), "withpch/");
472 Toolchain pch_toolchain(&pch_settings,
473 Label(SourceDir("//toolchain/"), "withpch"));
474
475 // Declare a C++ compiler that supports PCH.
476 scoped_ptr<Tool> cxx_tool(new Tool);
477 TestWithScope::SetCommandForTool(
478 "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} "
479 "-o {{output}}",
480 cxx_tool.get());
481 cxx_tool->set_outputs(SubstitutionList::MakeForTest(
482 "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o"));
483 cxx_tool->set_precompiled_header_type(Tool::PCH_GCC);
484 pch_toolchain.SetTool(Toolchain::TYPE_CXX, cxx_tool.Pass());
485 pch_toolchain.ToolchainSetupComplete();
486
487 // This target doesn't specify precompiled headers.
488 {
489 Target no_pch_target(&pch_settings,
490 Label(SourceDir("//foo/"), "no_pch_target"));
491 no_pch_target.set_output_type(Target::SOURCE_SET);
492 no_pch_target.visibility().SetPublic();
493 no_pch_target.sources().push_back(SourceFile("//foo/input1.cc"));
494 no_pch_target.SetToolchain(&pch_toolchain);
495 ASSERT_TRUE(no_pch_target.OnResolved(&err));
496
497 std::ostringstream out;
498 NinjaBinaryTargetWriter writer(&no_pch_target, out);
499 writer.Run();
500
501 const char no_pch_expected[] =
502 "defines =\n"
503 "include_dirs =\n"
504 "cflags =\n"
505 "cflags_cc =\n"
506 "target_output_name = no_pch_target\n"
507 "\n"
508 "build withpch/obj/foo/no_pch_target.input1.o: "
509 "cxx ../../foo/input1.cc\n"
510 "\n"
511 "build withpch/obj/foo/no_pch_target.stamp: "
512 "stamp withpch/obj/foo/no_pch_target.input1.o\n";
513 EXPECT_EQ(no_pch_expected, out.str());
514 }
515
516 // This target specifies PCH.
517 {
518 Target pch_target(&pch_settings,
519 Label(SourceDir("//foo/"), "pch_target"));
520 pch_target.config_values().set_precompiled_header("build/precompile.h");
521 pch_target.config_values().set_precompiled_source(
522 SourceFile("//build/precompile.h"));
523 pch_target.set_output_type(Target::SOURCE_SET);
524 pch_target.visibility().SetPublic();
525 pch_target.sources().push_back(SourceFile("//foo/input1.cc"));
526 pch_target.SetToolchain(&pch_toolchain);
527 ASSERT_TRUE(pch_target.OnResolved(&err));
528
529 std::ostringstream out;
530 NinjaBinaryTargetWriter writer(&pch_target, out);
531 writer.Run();
532
533 const char pch_gcc_expected[] =
534 "defines =\n"
535 "include_dirs =\n"
536 "cflags =\n"
537 "cflags_cc =\n"
538 "target_output_name = pch_target\n"
539 "\n"
540 // Compile the precompiled source with -x <lang>.
541 "build withpch/obj/build/pch_target.precompile.cc.o: "
542 "cxx ../../build/precompile.h\n"
543 " cflags_cc = ${cflags_cc} -x c++-header\n"
544 "\n"
545 "build withpch/obj/foo/pch_target.input1.o: "
546 "cxx ../../foo/input1.cc | "
547 // Explicit dependency on the PCH build step.
548 "withpch/obj/build/pch_target.precompile.cc.o\n"
549 "\n"
550 "build withpch/obj/foo/pch_target.stamp: "
551 "stamp withpch/obj/foo/pch_target.input1.o "
552 // The precompiled object file was added to the outputs.
553 "withpch/obj/build/pch_target.precompile.cc.o\n";
554 EXPECT_EQ(pch_gcc_expected, out.str());
555 }
556 }
557
464 // Should throw an error with the scheduler if a duplicate object file exists. 558 // Should throw an error with the scheduler if a duplicate object file exists.
465 // This is dependent on the toolchain's object file mapping. 559 // This is dependent on the toolchain's object file mapping.
466 TEST(NinjaBinaryTargetWriter, DupeObjFileError) { 560 TEST(NinjaBinaryTargetWriter, DupeObjFileError) {
467 Scheduler scheduler; 561 Scheduler scheduler;
468 562
469 TestWithScope setup; 563 TestWithScope setup;
470 TestTarget target(setup, "//foo:bar", Target::EXECUTABLE); 564 TestTarget target(setup, "//foo:bar", Target::EXECUTABLE);
471 target.sources().push_back(SourceFile("//a.cc")); 565 target.sources().push_back(SourceFile("//a.cc"));
472 target.sources().push_back(SourceFile("//a.cc")); 566 target.sources().push_back(SourceFile("//a.cc"));
473 567
474 EXPECT_FALSE(scheduler.is_failed()); 568 EXPECT_FALSE(scheduler.is_failed());
475 569
476 std::ostringstream out; 570 std::ostringstream out;
477 NinjaBinaryTargetWriter writer(&target, out); 571 NinjaBinaryTargetWriter writer(&target, out);
478 writer.Run(); 572 writer.Run();
479 573
480 // Should have issued an error. 574 // Should have issued an error.
481 EXPECT_TRUE(scheduler.is_failed()); 575 EXPECT_TRUE(scheduler.is_failed());
482 } 576 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698