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/target.h" | 5 #include "tools/gn/target.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "tools/gn/build_settings.h" | 10 #include "tools/gn/build_settings.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 Err err; | 84 Err err; |
85 | 85 |
86 // Set up a dependency chain of a -> b -> c | 86 // Set up a dependency chain of a -> b -> c |
87 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); | 87 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); |
88 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY); | 88 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY); |
89 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY); | 89 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY); |
90 a.private_deps().push_back(LabelTargetPair(&b)); | 90 a.private_deps().push_back(LabelTargetPair(&b)); |
91 b.private_deps().push_back(LabelTargetPair(&c)); | 91 b.private_deps().push_back(LabelTargetPair(&c)); |
92 | 92 |
93 // Normal non-inherited config. | 93 // Normal non-inherited config. |
94 Config config(setup.settings(), Label(SourceDir("//foo/"), "config")); | 94 Config config(setup.settings(), Label(SourceDir("//foo/"), "config"), {}); |
95 ASSERT_TRUE(config.OnResolved(&err)); | 95 ASSERT_TRUE(config.OnResolved(&err)); |
96 c.configs().push_back(LabelConfigPair(&config)); | 96 c.configs().push_back(LabelConfigPair(&config)); |
97 | 97 |
98 // All dependent config. | 98 // All dependent config. |
99 Config all(setup.settings(), Label(SourceDir("//foo/"), "all")); | 99 Config all(setup.settings(), Label(SourceDir("//foo/"), "all"), {}); |
100 ASSERT_TRUE(all.OnResolved(&err)); | 100 ASSERT_TRUE(all.OnResolved(&err)); |
101 c.all_dependent_configs().push_back(LabelConfigPair(&all)); | 101 c.all_dependent_configs().push_back(LabelConfigPair(&all)); |
102 | 102 |
103 // Direct dependent config. | 103 // Direct dependent config. |
104 Config direct(setup.settings(), Label(SourceDir("//foo/"), "direct")); | 104 Config direct(setup.settings(), Label(SourceDir("//foo/"), "direct"), {}); |
105 ASSERT_TRUE(direct.OnResolved(&err)); | 105 ASSERT_TRUE(direct.OnResolved(&err)); |
106 c.public_configs().push_back(LabelConfigPair(&direct)); | 106 c.public_configs().push_back(LabelConfigPair(&direct)); |
107 | 107 |
108 ASSERT_TRUE(c.OnResolved(&err)); | 108 ASSERT_TRUE(c.OnResolved(&err)); |
109 ASSERT_TRUE(b.OnResolved(&err)); | 109 ASSERT_TRUE(b.OnResolved(&err)); |
110 ASSERT_TRUE(a.OnResolved(&err)); | 110 ASSERT_TRUE(a.OnResolved(&err)); |
111 | 111 |
112 // B should have gotten both dependent configs from C. | 112 // B should have gotten both dependent configs from C. |
113 ASSERT_EQ(2u, b.configs().size()); | 113 ASSERT_EQ(2u, b.configs().size()); |
114 EXPECT_EQ(&all, b.configs()[0].ptr); | 114 EXPECT_EQ(&all, b.configs()[0].ptr); |
(...skipping 22 matching lines...) Expand all Loading... |
137 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr); | 137 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr); |
138 } | 138 } |
139 | 139 |
140 // Tests that dependent configs don't propagate between toolchains. | 140 // Tests that dependent configs don't propagate between toolchains. |
141 TEST(Target, NoDependentConfigsBetweenToolchains) { | 141 TEST(Target, NoDependentConfigsBetweenToolchains) { |
142 TestWithScope setup; | 142 TestWithScope setup; |
143 Err err; | 143 Err err; |
144 | 144 |
145 // Create another toolchain. | 145 // Create another toolchain. |
146 Toolchain other_toolchain(setup.settings(), | 146 Toolchain other_toolchain(setup.settings(), |
147 Label(SourceDir("//other/"), "toolchain")); | 147 Label(SourceDir("//other/"), "toolchain"), {}); |
148 TestWithScope::SetupToolchain(&other_toolchain); | 148 TestWithScope::SetupToolchain(&other_toolchain); |
149 | 149 |
150 // Set up a dependency chain of |a| -> |b| -> |c| where |a| has a different | 150 // Set up a dependency chain of |a| -> |b| -> |c| where |a| has a different |
151 // toolchain. | 151 // toolchain. |
152 Target a(setup.settings(), | 152 Target a(setup.settings(), |
153 Label(SourceDir("//foo/"), "a", other_toolchain.label().dir(), | 153 Label(SourceDir("//foo/"), "a", other_toolchain.label().dir(), |
154 other_toolchain.label().name())); | 154 other_toolchain.label().name()), |
| 155 {}); |
155 a.set_output_type(Target::EXECUTABLE); | 156 a.set_output_type(Target::EXECUTABLE); |
156 EXPECT_TRUE(a.SetToolchain(&other_toolchain, &err)); | 157 EXPECT_TRUE(a.SetToolchain(&other_toolchain, &err)); |
157 TestTarget b(setup, "//foo:b", Target::EXECUTABLE); | 158 TestTarget b(setup, "//foo:b", Target::EXECUTABLE); |
158 TestTarget c(setup, "//foo:c", Target::SOURCE_SET); | 159 TestTarget c(setup, "//foo:c", Target::SOURCE_SET); |
159 a.private_deps().push_back(LabelTargetPair(&b)); | 160 a.private_deps().push_back(LabelTargetPair(&b)); |
160 b.private_deps().push_back(LabelTargetPair(&c)); | 161 b.private_deps().push_back(LabelTargetPair(&c)); |
161 | 162 |
162 // All dependent config. | 163 // All dependent config. |
163 Config all_dependent(setup.settings(), Label(SourceDir("//foo/"), "all")); | 164 Config all_dependent(setup.settings(), Label(SourceDir("//foo/"), "all"), {}); |
164 ASSERT_TRUE(all_dependent.OnResolved(&err)); | 165 ASSERT_TRUE(all_dependent.OnResolved(&err)); |
165 c.all_dependent_configs().push_back(LabelConfigPair(&all_dependent)); | 166 c.all_dependent_configs().push_back(LabelConfigPair(&all_dependent)); |
166 | 167 |
167 // Public config. | 168 // Public config. |
168 Config public_config(setup.settings(), Label(SourceDir("//foo/"), "public")); | 169 Config public_config(setup.settings(), Label(SourceDir("//foo/"), "public"), |
| 170 {}); |
169 ASSERT_TRUE(public_config.OnResolved(&err)); | 171 ASSERT_TRUE(public_config.OnResolved(&err)); |
170 c.public_configs().push_back(LabelConfigPair(&public_config)); | 172 c.public_configs().push_back(LabelConfigPair(&public_config)); |
171 | 173 |
172 // Another public config. | 174 // Another public config. |
173 Config public_config2(setup.settings(), | 175 Config public_config2(setup.settings(), Label(SourceDir("//foo/"), "public2"), |
174 Label(SourceDir("//foo/"), "public2")); | 176 {}); |
175 ASSERT_TRUE(public_config2.OnResolved(&err)); | 177 ASSERT_TRUE(public_config2.OnResolved(&err)); |
176 b.public_configs().push_back(LabelConfigPair(&public_config2)); | 178 b.public_configs().push_back(LabelConfigPair(&public_config2)); |
177 | 179 |
178 ASSERT_TRUE(c.OnResolved(&err)); | 180 ASSERT_TRUE(c.OnResolved(&err)); |
179 ASSERT_TRUE(b.OnResolved(&err)); | 181 ASSERT_TRUE(b.OnResolved(&err)); |
180 ASSERT_TRUE(a.OnResolved(&err)); | 182 ASSERT_TRUE(a.OnResolved(&err)); |
181 | 183 |
182 // B should have gotten the configs from C. | 184 // B should have gotten the configs from C. |
183 ASSERT_EQ(3u, b.configs().size()); | 185 ASSERT_EQ(3u, b.configs().size()); |
184 EXPECT_EQ(&public_config2, b.configs()[0].ptr); | 186 EXPECT_EQ(&public_config2, b.configs()[0].ptr); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 product.set_testonly(false); | 478 product.set_testonly(false); |
477 product.private_deps().push_back(LabelTargetPair(&testlib)); | 479 product.private_deps().push_back(LabelTargetPair(&testlib)); |
478 ASSERT_FALSE(product.OnResolved(&err)); | 480 ASSERT_FALSE(product.OnResolved(&err)); |
479 } | 481 } |
480 | 482 |
481 TEST(Target, PublicConfigs) { | 483 TEST(Target, PublicConfigs) { |
482 TestWithScope setup; | 484 TestWithScope setup; |
483 Err err; | 485 Err err; |
484 | 486 |
485 Label pub_config_label(SourceDir("//a/"), "pubconfig"); | 487 Label pub_config_label(SourceDir("//a/"), "pubconfig"); |
486 Config pub_config(setup.settings(), pub_config_label); | 488 Config pub_config(setup.settings(), pub_config_label, {}); |
487 LibFile lib_name("testlib"); | 489 LibFile lib_name("testlib"); |
488 pub_config.own_values().libs().push_back(lib_name); | 490 pub_config.own_values().libs().push_back(lib_name); |
489 ASSERT_TRUE(pub_config.OnResolved(&err)); | 491 ASSERT_TRUE(pub_config.OnResolved(&err)); |
490 | 492 |
491 // This is the destination target that has a public config. | 493 // This is the destination target that has a public config. |
492 TestTarget dest(setup, "//a:a", Target::SOURCE_SET); | 494 TestTarget dest(setup, "//a:a", Target::SOURCE_SET); |
493 dest.public_configs().push_back(LabelConfigPair(&pub_config)); | 495 dest.public_configs().push_back(LabelConfigPair(&pub_config)); |
494 ASSERT_TRUE(dest.OnResolved(&err)); | 496 ASSERT_TRUE(dest.OnResolved(&err)); |
495 | 497 |
496 // This target has a public dependency on dest. | 498 // This target has a public dependency on dest. |
(...skipping 21 matching lines...) Expand all Loading... |
518 } | 520 } |
519 | 521 |
520 // Tests that configs are ordered properly between local and pulled ones. | 522 // Tests that configs are ordered properly between local and pulled ones. |
521 TEST(Target, ConfigOrdering) { | 523 TEST(Target, ConfigOrdering) { |
522 TestWithScope setup; | 524 TestWithScope setup; |
523 Err err; | 525 Err err; |
524 | 526 |
525 // Make Dep1. It has all_dependent_configs and public_configs. | 527 // Make Dep1. It has all_dependent_configs and public_configs. |
526 TestTarget dep1(setup, "//:dep1", Target::SOURCE_SET); | 528 TestTarget dep1(setup, "//:dep1", Target::SOURCE_SET); |
527 Label dep1_all_config_label(SourceDir("//"), "dep1_all_config"); | 529 Label dep1_all_config_label(SourceDir("//"), "dep1_all_config"); |
528 Config dep1_all_config(setup.settings(), dep1_all_config_label); | 530 Config dep1_all_config(setup.settings(), dep1_all_config_label, {}); |
529 ASSERT_TRUE(dep1_all_config.OnResolved(&err)); | 531 ASSERT_TRUE(dep1_all_config.OnResolved(&err)); |
530 dep1.all_dependent_configs().push_back(LabelConfigPair(&dep1_all_config)); | 532 dep1.all_dependent_configs().push_back(LabelConfigPair(&dep1_all_config)); |
531 | 533 |
532 Label dep1_public_config_label(SourceDir("//"), "dep1_public_config"); | 534 Label dep1_public_config_label(SourceDir("//"), "dep1_public_config"); |
533 Config dep1_public_config(setup.settings(), dep1_public_config_label); | 535 Config dep1_public_config(setup.settings(), dep1_public_config_label, {}); |
534 ASSERT_TRUE(dep1_public_config.OnResolved(&err)); | 536 ASSERT_TRUE(dep1_public_config.OnResolved(&err)); |
535 dep1.public_configs().push_back(LabelConfigPair(&dep1_public_config)); | 537 dep1.public_configs().push_back(LabelConfigPair(&dep1_public_config)); |
536 ASSERT_TRUE(dep1.OnResolved(&err)); | 538 ASSERT_TRUE(dep1.OnResolved(&err)); |
537 | 539 |
538 // Make Dep2 with the same structure. | 540 // Make Dep2 with the same structure. |
539 TestTarget dep2(setup, "//:dep2", Target::SOURCE_SET); | 541 TestTarget dep2(setup, "//:dep2", Target::SOURCE_SET); |
540 Label dep2_all_config_label(SourceDir("//"), "dep2_all_config"); | 542 Label dep2_all_config_label(SourceDir("//"), "dep2_all_config"); |
541 Config dep2_all_config(setup.settings(), dep2_all_config_label); | 543 Config dep2_all_config(setup.settings(), dep2_all_config_label, {}); |
542 ASSERT_TRUE(dep2_all_config.OnResolved(&err)); | 544 ASSERT_TRUE(dep2_all_config.OnResolved(&err)); |
543 dep2.all_dependent_configs().push_back(LabelConfigPair(&dep2_all_config)); | 545 dep2.all_dependent_configs().push_back(LabelConfigPair(&dep2_all_config)); |
544 | 546 |
545 Label dep2_public_config_label(SourceDir("//"), "dep2_public_config"); | 547 Label dep2_public_config_label(SourceDir("//"), "dep2_public_config"); |
546 Config dep2_public_config(setup.settings(), dep2_public_config_label); | 548 Config dep2_public_config(setup.settings(), dep2_public_config_label, {}); |
547 ASSERT_TRUE(dep2_public_config.OnResolved(&err)); | 549 ASSERT_TRUE(dep2_public_config.OnResolved(&err)); |
548 dep2.public_configs().push_back(LabelConfigPair(&dep2_public_config)); | 550 dep2.public_configs().push_back(LabelConfigPair(&dep2_public_config)); |
549 ASSERT_TRUE(dep2.OnResolved(&err)); | 551 ASSERT_TRUE(dep2.OnResolved(&err)); |
550 | 552 |
551 // This target depends on both previous targets. | 553 // This target depends on both previous targets. |
552 TestTarget target(setup, "//:foo", Target::SOURCE_SET); | 554 TestTarget target(setup, "//:foo", Target::SOURCE_SET); |
553 target.private_deps().push_back(LabelTargetPair(&dep1)); | 555 target.private_deps().push_back(LabelTargetPair(&dep1)); |
554 target.private_deps().push_back(LabelTargetPair(&dep2)); | 556 target.private_deps().push_back(LabelTargetPair(&dep2)); |
555 | 557 |
556 // It also has a private and public config. | 558 // It also has a private and public config. |
557 Label public_config_label(SourceDir("//"), "public"); | 559 Label public_config_label(SourceDir("//"), "public"); |
558 Config public_config(setup.settings(), public_config_label); | 560 Config public_config(setup.settings(), public_config_label, {}); |
559 ASSERT_TRUE(public_config.OnResolved(&err)); | 561 ASSERT_TRUE(public_config.OnResolved(&err)); |
560 target.public_configs().push_back(LabelConfigPair(&public_config)); | 562 target.public_configs().push_back(LabelConfigPair(&public_config)); |
561 | 563 |
562 Label private_config_label(SourceDir("//"), "private"); | 564 Label private_config_label(SourceDir("//"), "private"); |
563 Config private_config(setup.settings(), private_config_label); | 565 Config private_config(setup.settings(), private_config_label, {}); |
564 ASSERT_TRUE(private_config.OnResolved(&err)); | 566 ASSERT_TRUE(private_config.OnResolved(&err)); |
565 target.configs().push_back(LabelConfigPair(&private_config)); | 567 target.configs().push_back(LabelConfigPair(&private_config)); |
566 | 568 |
567 // Resolve to get the computed list of configs applying. | 569 // Resolve to get the computed list of configs applying. |
568 ASSERT_TRUE(target.OnResolved(&err)); | 570 ASSERT_TRUE(target.OnResolved(&err)); |
569 const auto& computed = target.configs(); | 571 const auto& computed = target.configs(); |
570 | 572 |
571 // Order should be: | 573 // Order should be: |
572 // 1. local private | 574 // 1. local private |
573 // 2. local public | 575 // 2. local public |
574 // 3. inherited all dependent | 576 // 3. inherited all dependent |
575 // 4. inherited public | 577 // 4. inherited public |
576 ASSERT_EQ(6u, computed.size()); | 578 ASSERT_EQ(6u, computed.size()); |
577 EXPECT_EQ(private_config_label, computed[0].label); | 579 EXPECT_EQ(private_config_label, computed[0].label); |
578 EXPECT_EQ(public_config_label, computed[1].label); | 580 EXPECT_EQ(public_config_label, computed[1].label); |
579 EXPECT_EQ(dep1_all_config_label, computed[2].label); | 581 EXPECT_EQ(dep1_all_config_label, computed[2].label); |
580 EXPECT_EQ(dep2_all_config_label, computed[3].label); | 582 EXPECT_EQ(dep2_all_config_label, computed[3].label); |
581 EXPECT_EQ(dep1_public_config_label, computed[4].label); | 583 EXPECT_EQ(dep1_public_config_label, computed[4].label); |
582 EXPECT_EQ(dep2_public_config_label, computed[5].label); | 584 EXPECT_EQ(dep2_public_config_label, computed[5].label); |
583 } | 585 } |
584 | 586 |
585 // Tests that different link/depend outputs work for solink tools. | 587 // Tests that different link/depend outputs work for solink tools. |
586 TEST(Target, LinkAndDepOutputs) { | 588 TEST(Target, LinkAndDepOutputs) { |
587 TestWithScope setup; | 589 TestWithScope setup; |
588 Err err; | 590 Err err; |
589 | 591 |
590 Toolchain toolchain(setup.settings(), Label(SourceDir("//tc/"), "tc")); | 592 Toolchain toolchain(setup.settings(), Label(SourceDir("//tc/"), "tc"), {}); |
591 | 593 |
592 std::unique_ptr<Tool> solink_tool(new Tool()); | 594 std::unique_ptr<Tool> solink_tool(new Tool()); |
593 solink_tool->set_output_prefix("lib"); | 595 solink_tool->set_output_prefix("lib"); |
594 solink_tool->set_default_output_extension(".so"); | 596 solink_tool->set_default_output_extension(".so"); |
595 | 597 |
596 const char kLinkPattern[] = | 598 const char kLinkPattern[] = |
597 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"; | 599 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"; |
598 SubstitutionPattern link_output = SubstitutionPattern::MakeForTest( | 600 SubstitutionPattern link_output = SubstitutionPattern::MakeForTest( |
599 kLinkPattern); | 601 kLinkPattern); |
600 solink_tool->set_link_output(link_output); | 602 solink_tool->set_link_output(link_output); |
601 | 603 |
602 const char kDependPattern[] = | 604 const char kDependPattern[] = |
603 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.TOC"; | 605 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.TOC"; |
604 SubstitutionPattern depend_output = SubstitutionPattern::MakeForTest( | 606 SubstitutionPattern depend_output = SubstitutionPattern::MakeForTest( |
605 kDependPattern); | 607 kDependPattern); |
606 solink_tool->set_depend_output(depend_output); | 608 solink_tool->set_depend_output(depend_output); |
607 | 609 |
608 solink_tool->set_outputs(SubstitutionList::MakeForTest( | 610 solink_tool->set_outputs(SubstitutionList::MakeForTest( |
609 kLinkPattern, kDependPattern)); | 611 kLinkPattern, kDependPattern)); |
610 | 612 |
611 toolchain.SetTool(Toolchain::TYPE_SOLINK, std::move(solink_tool)); | 613 toolchain.SetTool(Toolchain::TYPE_SOLINK, std::move(solink_tool)); |
612 | 614 |
613 Target target(setup.settings(), Label(SourceDir("//a/"), "a")); | 615 Target target(setup.settings(), Label(SourceDir("//a/"), "a"), {}); |
614 target.set_output_type(Target::SHARED_LIBRARY); | 616 target.set_output_type(Target::SHARED_LIBRARY); |
615 target.SetToolchain(&toolchain); | 617 target.SetToolchain(&toolchain); |
616 ASSERT_TRUE(target.OnResolved(&err)); | 618 ASSERT_TRUE(target.OnResolved(&err)); |
617 | 619 |
618 EXPECT_EQ("./liba.so", target.link_output_file().value()); | 620 EXPECT_EQ("./liba.so", target.link_output_file().value()); |
619 EXPECT_EQ("./liba.so.TOC", target.dependency_output_file().value()); | 621 EXPECT_EQ("./liba.so.TOC", target.dependency_output_file().value()); |
620 | 622 |
621 ASSERT_EQ(1u, target.runtime_outputs().size()); | 623 ASSERT_EQ(1u, target.runtime_outputs().size()); |
622 EXPECT_EQ("./liba.so", target.runtime_outputs()[0].value()); | 624 EXPECT_EQ("./liba.so", target.runtime_outputs()[0].value()); |
623 } | 625 } |
624 | 626 |
625 // Tests that runtime_outputs works without an explicit link_output for | 627 // Tests that runtime_outputs works without an explicit link_output for |
626 // solink tools. | 628 // solink tools. |
627 TEST(Target, RuntimeOuputs) { | 629 TEST(Target, RuntimeOuputs) { |
628 TestWithScope setup; | 630 TestWithScope setup; |
629 Err err; | 631 Err err; |
630 | 632 |
631 Toolchain toolchain(setup.settings(), Label(SourceDir("//tc/"), "tc")); | 633 Toolchain toolchain(setup.settings(), Label(SourceDir("//tc/"), "tc"), {}); |
632 | 634 |
633 std::unique_ptr<Tool> solink_tool(new Tool()); | 635 std::unique_ptr<Tool> solink_tool(new Tool()); |
634 solink_tool->set_output_prefix(""); | 636 solink_tool->set_output_prefix(""); |
635 solink_tool->set_default_output_extension(".dll"); | 637 solink_tool->set_default_output_extension(".dll"); |
636 | 638 |
637 // Say the linker makes a DLL< an import library, and a symbol file we want | 639 // Say the linker makes a DLL< an import library, and a symbol file we want |
638 // to treat as a runtime output. | 640 // to treat as a runtime output. |
639 const char kLibPattern[] = | 641 const char kLibPattern[] = |
640 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.lib"; | 642 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.lib"; |
641 const char kDllPattern[] = | 643 const char kDllPattern[] = |
642 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"; | 644 "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"; |
643 const char kPdbPattern[] = | 645 const char kPdbPattern[] = |
644 "{{root_out_dir}}/{{target_output_name}}.pdb"; | 646 "{{root_out_dir}}/{{target_output_name}}.pdb"; |
645 SubstitutionPattern pdb_pattern = | 647 SubstitutionPattern pdb_pattern = |
646 SubstitutionPattern::MakeForTest(kPdbPattern); | 648 SubstitutionPattern::MakeForTest(kPdbPattern); |
647 | 649 |
648 solink_tool->set_outputs( | 650 solink_tool->set_outputs( |
649 SubstitutionList::MakeForTest(kLibPattern, kDllPattern, kPdbPattern)); | 651 SubstitutionList::MakeForTest(kLibPattern, kDllPattern, kPdbPattern)); |
650 | 652 |
651 // Say we only want the DLL and symbol file treaded as runtime outputs. | 653 // Say we only want the DLL and symbol file treaded as runtime outputs. |
652 solink_tool->set_runtime_outputs(SubstitutionList::MakeForTest( | 654 solink_tool->set_runtime_outputs(SubstitutionList::MakeForTest( |
653 kDllPattern, kPdbPattern)); | 655 kDllPattern, kPdbPattern)); |
654 | 656 |
655 toolchain.SetTool(Toolchain::TYPE_SOLINK, std::move(solink_tool)); | 657 toolchain.SetTool(Toolchain::TYPE_SOLINK, std::move(solink_tool)); |
656 | 658 |
657 Target target(setup.settings(), Label(SourceDir("//a/"), "a")); | 659 Target target(setup.settings(), Label(SourceDir("//a/"), "a"), {}); |
658 target.set_output_type(Target::SHARED_LIBRARY); | 660 target.set_output_type(Target::SHARED_LIBRARY); |
659 target.SetToolchain(&toolchain); | 661 target.SetToolchain(&toolchain); |
660 ASSERT_TRUE(target.OnResolved(&err)); | 662 ASSERT_TRUE(target.OnResolved(&err)); |
661 | 663 |
662 EXPECT_EQ("./a.dll.lib", target.link_output_file().value()); | 664 EXPECT_EQ("./a.dll.lib", target.link_output_file().value()); |
663 EXPECT_EQ("./a.dll.lib", target.dependency_output_file().value()); | 665 EXPECT_EQ("./a.dll.lib", target.dependency_output_file().value()); |
664 | 666 |
665 ASSERT_EQ(2u, target.runtime_outputs().size()); | 667 ASSERT_EQ(2u, target.runtime_outputs().size()); |
666 EXPECT_EQ("./a.dll", target.runtime_outputs()[0].value()); | 668 EXPECT_EQ("./a.dll", target.runtime_outputs()[0].value()); |
667 EXPECT_EQ("./a.pdb", target.runtime_outputs()[1].value()); | 669 EXPECT_EQ("./a.pdb", target.runtime_outputs()[1].value()); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 final_target.inputs().push_back(object_file); | 866 final_target.inputs().push_back(object_file); |
865 EXPECT_TRUE(final_target.OnResolved(&err)); | 867 EXPECT_TRUE(final_target.OnResolved(&err)); |
866 | 868 |
867 AssertSchedulerHasOneUnknownFileMatching(&final_target, object_file); | 869 AssertSchedulerHasOneUnknownFileMatching(&final_target, object_file); |
868 } | 870 } |
869 | 871 |
870 TEST(Target, ResolvePrecompiledHeaders) { | 872 TEST(Target, ResolvePrecompiledHeaders) { |
871 TestWithScope setup; | 873 TestWithScope setup; |
872 Err err; | 874 Err err; |
873 | 875 |
874 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 876 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {}); |
875 | 877 |
876 // Target with no settings, no configs, should be a no-op. | 878 // Target with no settings, no configs, should be a no-op. |
877 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); | 879 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); |
878 | 880 |
879 // Config with PCH values. | 881 // Config with PCH values. |
880 Config config_1(setup.settings(), Label(SourceDir("//foo/"), "c1")); | 882 Config config_1(setup.settings(), Label(SourceDir("//foo/"), "c1"), {}); |
881 std::string pch_1("pch.h"); | 883 std::string pch_1("pch.h"); |
882 SourceFile pcs_1("//pcs.cc"); | 884 SourceFile pcs_1("//pcs.cc"); |
883 config_1.own_values().set_precompiled_header(pch_1); | 885 config_1.own_values().set_precompiled_header(pch_1); |
884 config_1.own_values().set_precompiled_source(pcs_1); | 886 config_1.own_values().set_precompiled_source(pcs_1); |
885 ASSERT_TRUE(config_1.OnResolved(&err)); | 887 ASSERT_TRUE(config_1.OnResolved(&err)); |
886 target.configs().push_back(LabelConfigPair(&config_1)); | 888 target.configs().push_back(LabelConfigPair(&config_1)); |
887 | 889 |
888 // No PCH info specified on target, but the config specifies one, the | 890 // No PCH info specified on target, but the config specifies one, the |
889 // values should get copied to the target. | 891 // values should get copied to the target. |
890 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); | 892 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); |
891 EXPECT_EQ(pch_1, target.config_values().precompiled_header()); | 893 EXPECT_EQ(pch_1, target.config_values().precompiled_header()); |
892 EXPECT_TRUE(target.config_values().precompiled_source() == pcs_1); | 894 EXPECT_TRUE(target.config_values().precompiled_source() == pcs_1); |
893 | 895 |
894 // Now both target and config have matching PCH values. Resolving again | 896 // Now both target and config have matching PCH values. Resolving again |
895 // should be a no-op since they all match. | 897 // should be a no-op since they all match. |
896 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); | 898 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); |
897 EXPECT_TRUE(target.config_values().precompiled_header() == pch_1); | 899 EXPECT_TRUE(target.config_values().precompiled_header() == pch_1); |
898 EXPECT_TRUE(target.config_values().precompiled_source() == pcs_1); | 900 EXPECT_TRUE(target.config_values().precompiled_source() == pcs_1); |
899 | 901 |
900 // Second config with different PCH values. | 902 // Second config with different PCH values. |
901 Config config_2(setup.settings(), Label(SourceDir("//foo/"), "c2")); | 903 Config config_2(setup.settings(), Label(SourceDir("//foo/"), "c2"), {}); |
902 std::string pch_2("pch2.h"); | 904 std::string pch_2("pch2.h"); |
903 SourceFile pcs_2("//pcs2.cc"); | 905 SourceFile pcs_2("//pcs2.cc"); |
904 config_2.own_values().set_precompiled_header(pch_2); | 906 config_2.own_values().set_precompiled_header(pch_2); |
905 config_2.own_values().set_precompiled_source(pcs_2); | 907 config_2.own_values().set_precompiled_source(pcs_2); |
906 ASSERT_TRUE(config_2.OnResolved(&err)); | 908 ASSERT_TRUE(config_2.OnResolved(&err)); |
907 target.configs().push_back(LabelConfigPair(&config_2)); | 909 target.configs().push_back(LabelConfigPair(&config_2)); |
908 | 910 |
909 // This should be an error since they don't match. | 911 // This should be an error since they don't match. |
910 EXPECT_FALSE(target.ResolvePrecompiledHeaders(&err)); | 912 EXPECT_FALSE(target.ResolvePrecompiledHeaders(&err)); |
911 | 913 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 ASSERT_EQ(c.bundle_data().file_rules().size(), 1u); | 1044 ASSERT_EQ(c.bundle_data().file_rules().size(), 1u); |
1043 ASSERT_EQ(c.bundle_data().file_rules()[0].sources().size(), 1u); | 1045 ASSERT_EQ(c.bundle_data().file_rules()[0].sources().size(), 1u); |
1044 ASSERT_EQ(c.bundle_data().bundle_deps().size(), 1u); | 1046 ASSERT_EQ(c.bundle_data().bundle_deps().size(), 1u); |
1045 | 1047 |
1046 // E does not have any bundle_data information but gets a list of | 1048 // E does not have any bundle_data information but gets a list of |
1047 // bundle_deps to propagate them during target resolution. | 1049 // bundle_deps to propagate them during target resolution. |
1048 ASSERT_TRUE(e.bundle_data().file_rules().empty()); | 1050 ASSERT_TRUE(e.bundle_data().file_rules().empty()); |
1049 ASSERT_TRUE(e.bundle_data().assets_catalog_sources().empty()); | 1051 ASSERT_TRUE(e.bundle_data().assets_catalog_sources().empty()); |
1050 ASSERT_EQ(e.bundle_data().bundle_deps().size(), 2u); | 1052 ASSERT_EQ(e.bundle_data().bundle_deps().size(), 2u); |
1051 } | 1053 } |
OLD | NEW |